27 #ifndef __MOTORDRIVER_H__ 28 #define __MOTORDRIVER_H__ 35 #include "StatusManager.h" 40 #define HLFB_CARRIER_LOSS_ERROR_LIMIT (0) 41 #define HLFB_CARRIER_LOSS_STATE_CHANGE_MS_45_HZ (25) 42 #define HLFB_CARRIER_LOSS_STATE_CHANGE_MS_482_HZ (4) 49 #define CPM_HLFB_CAP_HISTORY 2 54 #define CPM_ENABLE_DELAY 1250 57 #define DEFAULT_TRIGGER_PULSE_WIDTH_MS 25 265 uint32_t AtTargetPosition : 1;
269 uint32_t StepsActive : 1;
273 uint32_t AtTargetVelocity : 1;
279 uint32_t MoveDirection : 1;
284 uint32_t MotorInFault : 1;
289 uint32_t Enabled : 1;
293 uint32_t PositionalMove : 1;
301 uint32_t AlertsPresent : 1;
305 MotorReadyStates ReadyState : 3;
309 uint32_t Triggering : 1;
313 uint32_t InPositiveLimit : 1;
317 uint32_t InNegativeLimit : 1;
321 uint32_t InEStopSensor : 1;
359 uint16_t MotionCanceledInAlert : 1;
365 uint16_t MotionCanceledPositiveLimit : 1;
371 uint16_t MotionCanceledNegativeLimit : 1;
377 uint16_t MotionCanceledSensorEStop : 1;
383 uint16_t MotionCanceledMotorDisabled : 1;
388 uint16_t MotorFaulted : 1;
424 virtual bool Move(int32_t dist,
425 MoveTarget moveTarget = MOVE_TARGET_REL_END_POSN)
override;
549 return m_enableRequestedState;
635 bool blockUntilDone =
false);
658 return m_enableTriggerActive;
714 if (m_hlfbMode == newMode) {
717 m_hlfbMode = newMode;
718 m_hlfbCarrierLost =
true;
783 case HLFB_CARRIER_45_HZ:
784 m_hlfbCarrierLossStateChange_ms =
785 HLFB_CARRIER_LOSS_STATE_CHANGE_MS_45_HZ;
787 case HLFB_CARRIER_482_HZ:
788 m_hlfbCarrierLossStateChange_ms =
789 HLFB_CARRIER_LOSS_STATE_CHANGE_MS_482_HZ;
794 m_hlfbCarrierFrequency = freq;
821 return m_hlfbCarrierFrequency;
836 return (
volatile bool &)m_inFault;
848 return m_statusRegMotor;
887 return m_alertRegMotor;
900 atomic_and_fetch(&m_alertRegMotor.reg, ~mask);
1016 return m_brakeOutputPin;
1085 return m_limitSwitchPos;
1154 return m_limitSwitchNeg;
1214 return m_enableConnector;
1263 return m_inputAConnector;
1312 return m_inputBConnector;
1360 return m_eStopConnector;
1380 m_polarityInversions.bit.enableInverted = activeLevel;
1390 return m_polarityInversions.bit.enableInverted;
1399 m_polarityInversions.bit.hlfbInverted = !activeLevel;
1409 return !m_polarityInversions.bit.hlfbInverted;
1412 #ifndef HIDE_FROM_DOXYGEN 1414 virtual void OutputDirection()
override {
1416 m_polarityInversions.bit.directionInverted) {
1424 void ClearFaults(uint32_t disableTime_ms, uint32_t waitForHlfbTime_ms = 0) {
1426 m_clearFaultHlfbTimer = waitForHlfbTime_ms;
1427 m_clearFaultState = CLEAR_FAULT_PULSE_ENABLE;
1430 bool ClearFaultsActive() {
1431 return m_clearFaultState != CLEAR_FAULT_IDLE;
1462 bool MotorInACount(uint16_t count);
1472 bool MotorInBCount(uint16_t count);
1482 ShiftRegister::Masks m_enableMask;
1485 const PeripheralRoute *m_aInfo;
1486 const PeripheralRoute *m_bInfo;
1487 const PeripheralRoute *m_hlfbInfo;
1490 uint32_t m_aDataMask;
1491 volatile uint32_t *m_aTccBuffer;
1492 uint32_t m_bDataMask;
1493 volatile uint32_t *m_bTccBuffer;
1494 uint32_t m_aTccSyncMask;
1495 volatile uint32_t *m_aTccSyncReg;
1496 uint32_t m_bTccSyncMask;
1497 volatile uint32_t *m_bTccSyncReg;
1508 uint8_t m_hlfbTcNum;
1512 HlfbModes m_hlfbMode;
1517 uint16_t m_hlfbNoPwmSampleCount;
1518 HlfbCarrierFrequency m_hlfbCarrierFrequency;
1519 uint32_t m_hlfbCarrierLossStateChange_ms;
1521 uint32_t m_hlfbLastCarrierDetectTime;
1525 HlfbStates m_hlfbState;
1526 bool m_lastHlfbInputValue;
1527 bool m_hlfbPwmReadingPending;
1528 uint16_t m_hlfbStateChangeCounter;
1533 bool m_enableRequestedState;
1534 bool m_enableTriggerActive;
1535 uint32_t m_enableTriggerPulseStartMs;
1536 uint32_t m_enableTriggerPulseCount;
1537 uint32_t m_enableTriggerPulseLenMs;
1539 uint16_t m_aDutyCnt;
1540 uint16_t m_bDutyCnt;
1561 void ToggleEnable();
1565 enum ClearFaultState {
1567 CLEAR_FAULT_PULSE_ENABLE,
1568 CLEAR_FAULT_WAIT_FOR_HLFB
1576 bool m_hlfbCarrierLost;
1577 int32_t m_enableCounter;
1588 bool m_motionCancellingEStop;
1590 bool m_shiftRegEnableReq;
1591 ClearFaultState m_clearFaultState;
1592 uint32_t m_clearFaultHlfbTimer;
1598 const PeripheralRoute *aInfo,
1599 const PeripheralRoute *bInfo,
1600 const PeripheralRoute *hlfbInfo,
1613 void Refresh()
override;
1624 void FaultState(
bool isFaulted);
1661 bool CheckEStopSensor();
1667 #endif // __MOTORDRIVER_H__ Definition: MotorDriver.h:238
volatile const float & HlfbPercent()
Returns the percent of Peak Torque/Max Speed based on the current HLFB PWM duty cycle.
Definition: MotorDriver.h:698
uint32_t enableInverted
Definition: MotorDriver.h:107
ClearCorePins EnableConnector()
Definition: MotorDriver.h:1213
void HlfbActiveLevel(bool activeLevel)
Definition: MotorDriver.h:1398
Definition: MotorDriver.h:148
PolarityInversionsSD(int16_t val)
Definition: MotorDriver.h:128
Definition: MotorDriver.h:234
static const int16_t HLFB_DUTY_UNKNOWN
Definition: MotorDriver.h:136
Defines the Peripheral Route structure, used in HardwareMapping.
bool HlfbHasFallen()
Clear on read accessor for HLFB falling edge detection.
Definition: MotorDriver.h:763
bool MotorInBState()
Accessor for the state of the motor's Input B.
Definition: MotorDriver.h:157
volatile const StatusRegMotor & StatusReg()
Accessor for the current Motor Status Register.
Definition: MotorDriver.h:847
MotorReadyStates
Motor readiness states.
Definition: MotorDriver.h:222
ClearCore digital input connector class.
Definition: DigitalIn.h:70
StatusRegMotor(uint32_t val)
Definition: MotorDriver.h:334
void HlfbMode(HlfbModes newMode)
Sets operational mode of the HLFB to match up with the HLFB configuration of a ClearPathâ„¢ motor...
Definition: MotorDriver.h:713
#define DATA_OUTPUT_STATE(GPIO_PORT, DATA_MASK, STATE)
Definition: SysUtils.h:86
bool HlfbHasRisen()
Clear on read accessor for HLFB rising edge detection.
Definition: MotorDriver.h:748
uint32_t hlfbInverted
Definition: MotorDriver.h:115
bool MotorInADuty(uint8_t duty)
Function to set the duty cycle of a PWM signal being sent to the motor's Input A. ...
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition: MotorDriver.h:1168
AlertRegMotor()
Definition: MotorDriver.h:394
bool EnableActiveLevel()
Definition: MotorDriver.h:1389
uint16_t FilterLength()
Get the connector's digital filter length in samples. The default is 3 samples.
Definition: DigitalIn.h:146
bool IsInHwFault() override
Check whether the connector is in a hardware fault state.
Definition: MotorDriver.h:835
bool PolarityInvertSDDirection(bool invert)
Function to invert the default polarity of the direction signal of this motor.
volatile const AlertRegMotor & AlertReg()
Accessor for the current Motor Alert Register.
Definition: MotorDriver.h:886
Definition: Connector.h:126
StatusRegMotor StatusRegFallen()
Clear on read accessor for Motor Status Register falling edge detection.
Definition: MotorDriver.h:230
uint32_t reg
Definition: MotorDriver.h:255
ClearCorePins InputAConnector()
Definition: MotorDriver.h:1262
HlfbModes
Setup the HLFB query to match the ClearPathâ„¢ Motor's HLFB signaling format.
Definition: MotorDriver.h:168
ClearCorePins InputBConnector()
Definition: MotorDriver.h:1311
ClearCorePins LimitSwitchPos()
Get the associated positive limit switch output connector.
Definition: MotorDriver.h:1084
ClearCore motor connector class.
Definition: MotorDriver.h:79
#define DEFAULT_TRIGGER_PULSE_WIDTH_MS
Definition: MotorDriver.h:57
ClearCorePins EStopConnector()
Definition: MotorDriver.h:1359
Connector::ConnectorTypes Type() override
Get connector type.
Definition: MotorDriver.h:461
bool HlfbActiveLevel()
Definition: MotorDriver.h:1408
AlertRegMotor(uint32_t val)
Definition: MotorDriver.h:401
Definition: MotorDriver.h:204
virtual bool Move(int32_t dist, MoveTarget moveTarget=MOVE_TARGET_REL_END_POSN) override
Issues a positional move for the specified distance.
StatusRegMotor StatusRegRisen()
Clear on read accessor for Motor Status Register rising edge detection.
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36
HlfbModes HlfbMode()
Accessor for current HLFB operational mode.
Definition: MotorDriver.h:733
LED shift register access class.
bool HlfbCarrier(HlfbCarrierFrequency freq)
Set the HLFB carrier frequency signal.
Definition: MotorDriver.h:781
bool PolarityInvertSDEnable(bool invert)
Function to invert the default polarity of the enable signal of this motor.
Base class for all connector classes.
void EnableActiveLevel(bool activeLevel)
Definition: MotorDriver.h:1379
ClearCore Status Register Manager class.
Definition: StatusManager.h:37
Definition: MotorDriver.h:178
ConnectorModes
All possible operational modes for a connector.
Definition: Connector.h:74
ClearCorePins BrakeOutput()
Get the associated brake output connector.
Definition: MotorDriver.h:1015
PolarityInversionsSD()
Definition: MotorDriver.h:121
bool PolarityInvertSDHlfb(bool invert)
Function to invert the default polarity of the HLFB signal of this motor.
SysManager SysMgr
System manager.
Definition: MotorDriver.h:59
ClearCore Digital Input Connector class.
bool MotorInBDuty(uint8_t duty)
Function to set the duty cycle of a PWM signal being sent to the motor's Input B. ...
Definition: MotorDriver.h:152
int16_t reg
Definition: MotorDriver.h:98
HlfbCarrierFrequency
High-Level Feedback (HLFB) carrier frequency: 45 Hz or 482 Hz.
Definition: MotorDriver.h:210
bool InputFallen()
Clear on read accessor for this connector's falling input state.
Definition: MotorDriver.h:226
Definition: MotorDriver.h:190
Definition: MotorDriver.h:242
HlfbCarrierFrequency HlfbCarrier()
This motor's HLFB carrier frequency.
Definition: MotorDriver.h:820
uint32_t directionInverted
Definition: MotorDriver.h:111
Definition: MotorDriver.h:161
volatile const bool & EnableTriggerPulseActive()
Check to see if enable trigger pulses are actively being sent.
Definition: MotorDriver.h:657
struct ClearCore::MotorDriver::PolarityInversionsSD::@1 bit
ClearCorePins LimitSwitchNeg()
Get the associated negative limit switch output connector.
Definition: MotorDriver.h:1153
#define CPM_HLFB_CAP_HISTORY
Definition: MotorDriver.h:49
bool MotorInAState()
Accessor for the state of the motor's Input A.
Definition: Connector.h:264
Register access for information about the motor's operating status. Intended for use in Step and Dire...
Definition: MotorDriver.h:251
void EnableTriggerPulse(uint16_t pulseCount=1, uint32_t time_ms=DEFAULT_TRIGGER_PULSE_WIDTH_MS, bool blockUntilDone=false)
Sends trigger pulse(s) to a connected ClearPathâ„¢ motor by de-asserting the enable signal for time_ms...
void HlfbFilterLength(uint16_t samples)
Sets the filter length in samples. The default is 3 samples.
Definition: MotorDriver.h:446
ClearCore Step and Direction generator class.
Definition: StepGenerator.h:56
ClearCore Board Supervisory System Manager.
Definition: SysManager.h:58
ClearCore motor-connector manager.
Definition: MotorManager.h:46
bool EnableRequest()
Accessor for the enable request state of the motor.
Definition: MotorDriver.h:548
Accumulating register of alerts that have occurred on this motor. Intended for use in Step and Direct...
Definition: MotorDriver.h:345
bool ValidateMove(bool negDirection)
ClearCorePins
ClearCore PIN definitions.
Definition: SysConnectors.h:54
ClearCore common utility functions.
HlfbStates
Return state when HLFB state is requested.
Definition: MotorDriver.h:144
A small register with bit and field views. This allows easy configuration for steppers that use an in...
Definition: MotorDriver.h:94
virtual bool MoveVelocity(int32_t velocity) override
Issues a velocity move at the specified velocity.
bool HlfbInputStatus()
Definition: MotorDriver.h:1369
uint32_t reg
Definition: MotorDriver.h:349
StatusRegMotor()
Definition: MotorDriver.h:327
bool IsWritable() override
Get R/W status of the connector.
Definition: MotorDriver.h:476
volatile const HlfbStates & HlfbState()
Return the latest HLFB state information.
Definition: MotorDriver.h:676
virtual ConnectorModes Mode()
Get the connector's operational mode.
Definition: Connector.h:309
void ClearAlerts(uint32_t mask=UINT32_MAX)
Clear the Motor Alert Register. Motion will be prevented if any Alert Register bits are set...
Definition: MotorDriver.h:899
ConnectorTypes
The different types of ClearCore connectors.
Definition: Connector.h:172
bool InputRisen()
Clear on read accessor for this connector's rising input state.