Return to SDK Examples for Microchip Studio
42#define motor ConnectorM0
48#define SerialPort ConnectorUsb
53 motor.HlfbMode(MotorDriver::HLFB_MODE_HAS_PWM);
55 motor.HlfbCarrier(MotorDriver::HLFB_CARRIER_482_HZ);
59 SerialPort.Mode(Connector::USB_CDC);
60 SerialPort.Speed(baudRate);
61 uint32_t timeout = 5000;
63 SerialPort.PortOpen();
64 while (!SerialPort &&
Milliseconds() - startTime < timeout) {
73 MotorDriver::HlfbStates hlfbState = motor.HlfbState();
76 if (hlfbState == MotorDriver::HLFB_HAS_MEASUREMENT) {
78 float hlfbPercent = motor.HlfbPercent();
80 SerialPort.Send(
"Speed output: ");
82 if (hlfbPercent == MotorDriver::HLFB_DUTY_UNKNOWN) {
83 SerialPort.SendLine(
"UNKNOWN");
86 char hlfbPercentStr[10];
88 snprintf(hlfbPercentStr,
sizeof(hlfbPercentStr),
"%.0f%%", hlfbPercent);
89 SerialPort.Send(hlfbPercentStr);
90 SerialPort.SendLine(
" of maximum speed");
93 else if (hlfbState == MotorDriver::HLFB_DEASSERTED) {
94 SerialPort.SendLine(
"Disabled or Shutdown");
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.