Return to SDK Examples for Microchip Studio
#include "ClearCore.h"
#define motor ConnectorM0
#define baudRate 9600
#define SerialPort ConnectorUsb
int main() {
motor.HlfbMode(MotorDriver::HLFB_MODE_HAS_BIPOLAR_PWM);
motor.HlfbCarrier(MotorDriver::HLFB_CARRIER_482_HZ);
SerialPort.Mode(Connector::USB_CDC);
SerialPort.Speed(baudRate);
uint32_t timeout = 5000;
SerialPort.PortOpen();
while (!SerialPort &&
Milliseconds() - startTime < timeout) {
continue;
}
while (true) {
SerialPort.Send("HLFB state: ");
MotorDriver::HlfbStates hlfbState = motor.HlfbState();
if (hlfbState == MotorDriver::HLFB_HAS_MEASUREMENT) {
SerialPort.Send(int8_t(round(motor.HlfbPercent())));
SerialPort.SendLine("% torque");
}
else if (hlfbState == MotorDriver::HLFB_ASSERTED) {
SerialPort.SendLine("ASSERTED");
}
else {
SerialPort.SendLine("DISABLED or SHUTDOWN");
}
}
}