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
420 virtual bool Move(int32_t dist,
421 MoveTarget moveTarget = MOVE_TARGET_REL_END_POSN)
override;
545 return m_enableRequestedState;
631 bool blockUntilDone =
false);
654 return m_enableTriggerActive;
710 if (m_hlfbMode == newMode) {
713 m_hlfbMode = newMode;
714 m_hlfbCarrierLost =
true;
775 case HLFB_CARRIER_45_HZ:
776 m_hlfbCarrierLossStateChange_ms =
777 HLFB_CARRIER_LOSS_STATE_CHANGE_MS_45_HZ;
779 case HLFB_CARRIER_482_HZ:
780 m_hlfbCarrierLossStateChange_ms =
781 HLFB_CARRIER_LOSS_STATE_CHANGE_MS_482_HZ;
786 m_hlfbCarrierFrequency = freq;
809 return m_hlfbCarrierFrequency;
824 return (
volatile bool &)m_inFault;
836 return m_statusRegMotor;
875 return m_alertRegMotor;
888 atomic_and_fetch(&m_alertRegMotor.
reg, ~mask);
1001 return m_brakeOutputPin;
1070 return m_limitSwitchPos;
1139 return m_limitSwitchNeg;
1191 return m_enableConnector;
1232 return m_inputAConnector;
1273 return m_inputBConnector;
1328 return m_eStopConnector;
1380#ifndef HIDE_FROM_DOXYGEN
1382 virtual void OutputDirection()
override {
1392 void ClearFaults(uint32_t disableTime_ms, uint32_t waitForHlfbTime_ms = 0) {
1394 m_clearFaultHlfbTimer = waitForHlfbTime_ms;
1395 m_clearFaultState = CLEAR_FAULT_PULSE_ENABLE;
1398 bool ClearFaultsActive() {
1399 return m_clearFaultState != CLEAR_FAULT_IDLE;
1430 bool MotorInACount(uint16_t count);
1440 bool MotorInBCount(uint16_t count);
1450 ShiftRegister::Masks m_enableMask;
1453 const PeripheralRoute *m_aInfo;
1454 const PeripheralRoute *m_bInfo;
1455 const PeripheralRoute *m_hlfbInfo;
1458 uint32_t m_aDataMask;
1459 volatile uint32_t *m_aTccBuffer;
1460 uint32_t m_bDataMask;
1461 volatile uint32_t *m_bTccBuffer;
1462 uint32_t m_aTccSyncMask;
1463 volatile uint32_t *m_aTccSyncReg;
1464 uint32_t m_bTccSyncMask;
1465 volatile uint32_t *m_bTccSyncReg;
1476 uint8_t m_hlfbTcNum;
1485 uint16_t m_hlfbNoPwmSampleCount;
1487 uint32_t m_hlfbCarrierLossStateChange_ms;
1489 uint32_t m_hlfbLastCarrierDetectTime;
1494 bool m_lastHlfbInputValue;
1495 bool m_hlfbPwmReadingPending;
1496 uint16_t m_hlfbStateChangeCounter;
1499 PolarityInversionsSD m_polarityInversions;
1501 bool m_enableRequestedState;
1502 bool m_enableTriggerActive;
1503 uint32_t m_enableTriggerPulseStartMs;
1504 uint32_t m_enableTriggerPulseCount;
1505 uint32_t m_enableTriggerPulseLenMs;
1507 uint16_t m_aDutyCnt;
1508 uint16_t m_bDutyCnt;
1512 StatusRegMotor m_statusRegMotor;
1513 StatusRegMotor m_statusRegMotorRisen;
1514 StatusRegMotor m_statusRegMotorFallen;
1515 StatusRegMotor m_statusRegMotorLast;
1517 AlertRegMotor m_alertRegMotor;
1529 void ToggleEnable();
1533 enum ClearFaultState {
1535 CLEAR_FAULT_PULSE_ENABLE,
1536 CLEAR_FAULT_WAIT_FOR_HLFB
1544 bool m_hlfbCarrierLost;
1545 int32_t m_enableCounter;
1556 bool m_motionCancellingEStop;
1558 bool m_shiftRegEnableReq;
1559 ClearFaultState m_clearFaultState;
1560 uint32_t m_clearFaultHlfbTimer;
1565 MotorDriver(
enum ShiftRegister::Masks enableMask,
1566 const PeripheralRoute *aInfo,
1567 const PeripheralRoute *bInfo,
1568 const PeripheralRoute *hlfbInfo,
1581 void Refresh()
override;
1592 void FaultState(
bool isFaulted);
1629 bool CheckEStopSensor();
Base class for all connector classes.
ClearCore Digital Input Connector class.
#define CPM_HLFB_CAP_HISTORY
Definition MotorDriver.h:49
#define DEFAULT_TRIGGER_PULSE_WIDTH_MS
Definition MotorDriver.h:57
Defines the Peripheral Route structure, used in HardwareMapping.
LED shift register access class.
ClearCorePins
ClearCore PIN definitions.
Definition SysConnectors.h:54
ClearCore common utility functions.
#define DATA_OUTPUT_STATE(GPIO_PORT, DATA_MASK, STATE)
Definition SysUtils.h:86
virtual ConnectorModes Mode()
Get the connector's operational mode.
Definition Connector.h:309
ConnectorModes
All possible operational modes for a connector.
Definition Connector.h:74
@ CPM_MODE_STEP_AND_DIR
Definition Connector.h:126
ConnectorTypes
The different types of ClearCore connectors.
Definition Connector.h:172
@ CPM_TYPE
Definition Connector.h:264
ClearCore digital input connector class.
Definition DigitalIn.h:70
uint16_t FilterLength()
Get the connector's digital filter length in samples. The default is 3 samples.
Definition DigitalIn.h:146
bool InputRisen()
Clear on read accessor for this connector's rising input state.
bool InputFallen()
Clear on read accessor for this connector's falling input state.
ClearCore motor connector class.
Definition MotorDriver.h:79
HlfbModes
Setup the HLFB query to match the ClearPathâ„¢ Motor's HLFB signaling format.
Definition MotorDriver.h:168
@ HLFB_MODE_STATIC
Definition MotorDriver.h:178
@ HLFB_MODE_HAS_PWM
Definition MotorDriver.h:190
@ HLFB_MODE_HAS_BIPOLAR_PWM
Definition MotorDriver.h:204
volatile const float & HlfbPercent()
Returns the percent of Peak Torque/Max Speed based on the current HLFB PWM duty cycle.
Definition MotorDriver.h:694
bool MotorInADuty(uint8_t duty)
Function to set the duty cycle of a PWM signal being sent to the motor's Input A.
volatile const AlertRegMotor & AlertReg()
Accessor for the current Motor Alert Register.
Definition MotorDriver.h:874
Connector::ConnectorTypes Type() override
Get connector type.
Definition MotorDriver.h:457
ClearCorePins EnableConnector()
Definition MotorDriver.h:1190
void HlfbMode(HlfbModes newMode)
Sets operational mode of the HLFB to match up with the HLFB configuration of a ClearPathâ„¢ motor.
Definition MotorDriver.h:709
ClearCorePins InputAConnector()
Definition MotorDriver.h:1231
ClearCorePins InputBConnector()
Definition MotorDriver.h:1272
bool BrakeOutput(ClearCorePins pin)
Set the associated brake output connector.
StatusRegMotor StatusRegRisen()
Clear on read accessor for Motor Status Register rising edge detection.
bool LimitSwitchNeg(ClearCorePins pin)
Set the associated negative limit switch connector.
HlfbStates
Return state when HLFB state is requested.
Definition MotorDriver.h:144
@ HLFB_HAS_MEASUREMENT
Definition MotorDriver.h:157
@ HLFB_UNKNOWN
Definition MotorDriver.h:161
@ HLFB_DEASSERTED
Definition MotorDriver.h:148
@ HLFB_ASSERTED
Definition MotorDriver.h:152
bool EnableRequest()
Accessor for the enable request state of the motor.
Definition MotorDriver.h:544
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 ...
ClearCorePins EStopConnector()
Definition MotorDriver.h:1327
bool EnableActiveLevel()
Definition MotorDriver.h:1357
void EnableRequest(bool value)
Function to request the motor to enable or disable.
void HlfbActiveLevel(bool activeLevel)
Definition MotorDriver.h:1366
static const int16_t HLFB_DUTY_UNKNOWN
Definition MotorDriver.h:136
bool PolarityInvertSDEnable(bool invert)
Function to invert the default polarity of the enable signal of this motor.
HlfbModes HlfbMode()
Accessor for current HLFB operational mode.
Definition MotorDriver.h:729
StatusRegMotor StatusRegFallen()
Clear on read accessor for Motor Status Register falling edge detection.
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition MotorDriver.h:1153
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:887
bool EnableConnector(ClearCorePins pin)
virtual bool MoveVelocity(int32_t velocity) override
Issues a velocity move at the specified velocity.
bool EStopConnector(ClearCorePins pin)
volatile const HlfbStates & HlfbState()
Return the latest HLFB state information.
Definition MotorDriver.h:672
ClearCorePins LimitSwitchPos()
Get the associated positive limit switch output connector.
Definition MotorDriver.h:1069
bool HlfbCarrier(HlfbCarrierFrequency freq)
Set the HLFB carrier frequency signal.
Definition MotorDriver.h:773
bool PolarityInvertSDDirection(bool invert)
Function to invert the default polarity of the direction signal of this motor.
bool IsWritable() override
Get R/W status of the connector.
Definition MotorDriver.h:472
ClearCorePins BrakeOutput()
Get the associated brake output connector.
Definition MotorDriver.h:1000
bool PolarityInvertSDHlfb(bool invert)
Function to invert the default polarity of the HLFB signal of this motor.
void HlfbFilterLength(uint16_t samples)
Sets the filter length in samples. The default is 3 samples.
Definition MotorDriver.h:442
bool ValidateMove(bool negDirection)
bool HlfbHasRisen()
Clear on read accessor for HLFB rising edge detection.
Definition MotorDriver.h:744
bool HlfbHasFallen()
Clear on read accessor for HLFB falling edge detection.
Definition MotorDriver.h:759
bool MotorInBState(bool value)
Function to set the value of the motor's Input B.
bool IsInHwFault() override
Check whether the connector is in a hardware fault state.
Definition MotorDriver.h:823
ClearCorePins LimitSwitchNeg()
Get the associated negative limit switch output connector.
Definition MotorDriver.h:1138
bool MotorInAState()
Accessor for the state of the motor's Input A.
void EnableActiveLevel(bool activeLevel)
Definition MotorDriver.h:1347
bool LimitSwitchPos(ClearCorePins pin)
Set the associated positive limit switch connector.
volatile const bool & EnableTriggerPulseActive()
Check to see if enable trigger pulses are actively being sent.
Definition MotorDriver.h:653
bool InputBConnector(ClearCorePins pin)
HlfbCarrierFrequency HlfbCarrier()
This motor's HLFB carrier frequency.
Definition MotorDriver.h:808
bool MotorInAState(bool value)
Function to set the state of the motor's Input A.
bool MotorInBDuty(uint8_t duty)
Function to set the duty cycle of a PWM signal being sent to the motor's Input B.
bool HlfbInputStatus()
Definition MotorDriver.h:1337
bool HlfbActiveLevel()
Definition MotorDriver.h:1376
bool InputAConnector(ClearCorePins pin)
MotorReadyStates
Motor readiness states.
Definition MotorDriver.h:222
@ MOTOR_ENABLING
Definition MotorDriver.h:230
@ MOTOR_DISABLED
Definition MotorDriver.h:226
@ MOTOR_FAULTED
Definition MotorDriver.h:234
@ MOTOR_READY
Definition MotorDriver.h:238
@ MOTOR_MOVING
Definition MotorDriver.h:242
bool MotorInBState()
Accessor for the state of the motor's Input B.
volatile const StatusRegMotor & StatusReg()
Accessor for the current Motor Status Register.
Definition MotorDriver.h:835
HlfbCarrierFrequency
High-Level Feedback (HLFB) carrier frequency: 45 Hz or 482 Hz.
Definition MotorDriver.h:210
virtual bool Move(int32_t dist, MoveTarget moveTarget=MOVE_TARGET_REL_END_POSN) override
Issues a positional move for the specified distance.
ClearCore motor-connector manager.
Definition MotorManager.h:46
ClearCore Status Register Manager class.
Definition StatusManager.h:37
ClearCore Step and Direction generator class.
Definition StepGenerator.h:58
ClearCore Board Supervisory System Manager.
Definition SysManager.h:58
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36
SysManager SysMgr
System manager.
Definition MotorDriver.h:59
Accumulating register of alerts that have occurred on this motor. Intended for use in Step and Direct...
Definition MotorDriver.h:345
uint16_t MotionCanceledNegativeLimit
Definition MotorDriver.h:371
uint16_t MotionCanceledPositiveLimit
Definition MotorDriver.h:365
AlertRegMotor(uint32_t val)
Definition MotorDriver.h:401
uint16_t MotionCanceledInAlert
Definition MotorDriver.h:359
uint16_t MotorFaulted
Definition MotorDriver.h:388
AlertRegMotor()
Definition MotorDriver.h:394
uint16_t MotionCanceledSensorEStop
Definition MotorDriver.h:377
uint16_t MotionCanceledMotorDisabled
Definition MotorDriver.h:383
struct ClearCore::MotorDriver::AlertRegMotor::@3 bit
uint32_t reg
Definition MotorDriver.h:349
A small register with bit and field views. This allows easy configuration for steppers that use an in...
Definition MotorDriver.h:94
PolarityInversionsSD()
Definition MotorDriver.h:121
struct ClearCore::MotorDriver::PolarityInversionsSD::@1 bit
PolarityInversionsSD(int16_t val)
Definition MotorDriver.h:128
int16_t reg
Definition MotorDriver.h:98
uint32_t enableInverted
Definition MotorDriver.h:107
uint32_t hlfbInverted
Definition MotorDriver.h:115
uint32_t directionInverted
Definition MotorDriver.h:111
Register access for information about the motor's operating status. Intended for use in Step and Dire...
Definition MotorDriver.h:251
uint32_t Triggering
Definition MotorDriver.h:309
uint32_t reg
Definition MotorDriver.h:255
uint32_t InEStopSensor
Definition MotorDriver.h:321
uint32_t AtTargetVelocity
Definition MotorDriver.h:273
MotorReadyStates ReadyState
Definition MotorDriver.h:305
uint32_t InNegativeLimit
Definition MotorDriver.h:317
uint32_t PositionalMove
Definition MotorDriver.h:293
uint32_t AtTargetPosition
Definition MotorDriver.h:265
StatusRegMotor()
Definition MotorDriver.h:327
StatusRegMotor(uint32_t val)
Definition MotorDriver.h:334
uint32_t InPositiveLimit
Definition MotorDriver.h:313
uint32_t Enabled
Definition MotorDriver.h:289
uint32_t HlfbState
Definition MotorDriver.h:297
struct ClearCore::MotorDriver::StatusRegMotor::@2 bit
uint32_t MotorInFault
Definition MotorDriver.h:284
uint32_t AlertsPresent
Definition MotorDriver.h:301
uint32_t MoveDirection
Definition MotorDriver.h:279
uint32_t StepsActive
Definition MotorDriver.h:269