2025-12-16 9:08 AM - edited 2025-12-16 9:09 AM
Hello,
In a seperate post I received help allowing my B-G431-ESC1 to accept PWM input from an ESP32 to vary the speed of a 24V hoverboard motor with hall sensors using FOC.
My goal now is to be able to vary the direction of the motor's rotation by varying the PWM.
Given that the acceptable range of values is 1060us to 1860us, I had hoped to be able to do this by having values 1060us to 1460us correspond to rotation in one direction, and the values from 1460us to 1860us correspond to rotation in the opposite direction.
I was unsure of any official documentation on bidirectional control, but i noticed that when using the motor pilot to manually set speeds, I was able to set the speed reference to be both positive and negative. I found a github with a guide on how to implement bidirectional control and after following the steps it mentioned, I found that when the motor driver was viewed on the motor pilot, the speed reference did indeed switch between positive and negative values with the appropriate PWM input.
However, when the speed reference was negative, the motor would attempt to rotate in the positive direction, crash, restart, attempt again, crash again, etc...
I have written this post to ask for help in resolving this issue of the speed reference showing up as negative, but the motor not actually being driven in the correct direction and then also crashing when it attempts to
Or if there were any easier ways to achieve the bidirectional control I described, I would also be very grateful to hear of how I should go about implementing this :)
the modifications I have made are as follows:
int16_t hDirection;__weak void MCI_SetDirection(MCI_Handle_t *pHandle, int16_t hDir)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
pHandle->hDirection = hDir;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
}__weak void MCI_ExecSpeedRamp(MCI_Handle_t *pHandle, int16_t hFinalSpeed, uint16_t hDurationms)
{
#ifdef NULL_PTR_CHECK_MC_INT
if (MC_NULL == pHandle)
{
/* Nothing to do */
}
else
{
#endif
if (pHandle->hDirection < 0)
{
hFinalSpeed = -hFinalSpeed;
}
else
{
hFinalSpeed = hFinalSpeed;
}
pHandle->hFinalSpeed = hFinalSpeed;
pHandle->lastCommand = MCI_CMD_EXECSPEEDRAMP;
pHandle->hDurationms = hDurationms;
pHandle->CommandState = MCI_COMMAND_NOT_ALREADY_EXECUTED;
pHandle->LastModalitySetByUser = MCM_SPEED_MODE;
#ifdef NULL_PTR_CHECK_MC_INT
}
#endif
} if(pHandle->Ton_value < (pESC_params->Ton_max + pESC_params->Ton_min)/2 ){
MCI_SetDirection(pMCI[pESC_params->motor], -1);
}
else{
MCI_SetDirection(pMCI[pESC_params->motor], 1);
}motor workbench: Version: 6.4.1 Build: 250722.154358
STM32 cubeIDE: Version 2.0.0
STM32 cubeMX: Version 6.16.0
Board: B-G431-ESC1
Motor:
I have been unable to find a spec sheet for this motor, I believe it comes from the zimx hb1 hoverboard. Below is the information I currently have about it.
24V, 5Apk, 15 pole pairs, max RPM 600,