2022-03-17 12:13 PM
Hello, I'm working on Electronic Speed Controller For Sensorless BLDC Motor.
I changed the ESC circuit a bit on this blog (https://simple-circuit.com/arduino-sensorless-brushless-motor-bldc/) by replacing the Arduino with a STM32F103 (I'm using an LQF48 adapter) and the Mosfet (and including the mosfet driver) using the BTN7970.
I've tried the circuit that I made without BackEMF as well as testing whether my circuit can rotate 360 ° and the results rotate but the rotation is very slow (approximately 30-40 RPM).
Next I tried to use BackEMF detection by using an external comparator (LM339). The result is that the motor only vibrates (the motor only moves slightly to the left and then to the right and then repeats).
I don't understand what's wrong.
1. Is my interrupt program correct?
2.Is the program for starting the motor incorrect?
Here's the circuit I made in Eagle and the STM32F103 program.
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
startMotor();
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == BEMF_Pin) {
if(modeMotor == 2) {
//Check for debounce signal
for(uint8_t i = 0; i < 40; i++)
{
if(bldcStep & 1){ //If bldcStep Odd ( 1, 3, 5), When Odd => BEMF Signal Rising
if(HAL_GPIO_ReadPin(GPIOB, BEMF_Pin)) i -= 1;
}
else {
if(!(HAL_GPIO_ReadPin(GPIOB, BEMF_Pin))) i -= 1;
}
}
BLDC_MOVE();
bldcStep++;
bldcStep %= 6;
}
}
}
void startMotor() {
if(modeMotor == 1) { //If modeMotor == 1, Motor Starting (Without BEMF)
AHBL();
HAL_Delay(50);
AHCL();
HAL_Delay(50);
BHCL();
HAL_Delay(50);
BHAL();
HAL_Delay(50);
CHAL();
HAL_Delay(50);
CHBL();
HAL_Delay(50);
bldcStep = 0;
int i = 3000;
while (i > 100) {
HAL_Delay(i);
BLDC_MOVE();
bldcStep++;
bldcStep %= 6;
i = i - 20;
}
modeMotor = 2; //If modeMotor == 2, Motor Running (With BEMF)
}
}
void BLDC_MOVE()
{
switch(bldcStep)
{
case 0:
AHBL();
BEMFC_Falling();
break;
case 1:
AHCL();
BEMFB_Rising();
break;
case 2:
BHCL();
BEMFA_Falling();
break;
case 3:
BHAL();
BEMFC_Rising();
break;
case 4:
CHAL();
BEMFB_Falling();
break;
case 5:
CHBL();
BEMFA_Rising();
}
}
//C-B, A FLOATING
void CHBL() {
HAL_GPIO_WritePin(GPIOA, INC_Pin|INHB_Pin|INHC_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHA_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_RESET);
}
//A-B, C FLOATING
void AHBL() {
HAL_GPIO_WritePin(GPIOA, INHA_Pin|INHB_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHC_Pin|INC_Pin, GPIO_PIN_RESET);
}
//A-C, B FLOATING
void AHCL() {
HAL_GPIO_WritePin(GPIOA, INHA_Pin|INHC_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHB_Pin|INC_Pin, GPIO_PIN_RESET);
}
//B-C, A FLOATING
void BHCL() {
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHB_Pin|INHC_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, INC_Pin|INHA_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_RESET);
}
//B-A, C FLOATING
void BHAL() {
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHA_Pin|INHB_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, INC_Pin|INHC_Pin, GPIO_PIN_RESET);
}
//C-A, B FLOATING
void CHAL() {
HAL_GPIO_WritePin(GPIOA, INC_Pin|INHA_Pin|INHC_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(INA_GPIO_Port, INA_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, INB_Pin|INHB_Pin, GPIO_PIN_RESET);
}
void BEMFA_Rising() {
pinState = 1;
BEMF_Pin = BEMFA_Pin;
CLEAR_BIT(EXTI->FTSR, BEMFA_Pin);
SET_BIT(EXTI->RTSR, BEMFA_Pin);
}
void BEMFA_Falling() {
pinState = 0;
BEMF_Pin = BEMFA_Pin;
CLEAR_BIT(EXTI->RTSR, BEMFA_Pin);
SET_BIT(EXTI->FTSR, BEMFA_Pin);
}
void BEMFB_Rising() {
pinState = 1;
BEMF_Pin = BEMFB_Pin;
CLEAR_BIT(EXTI->FTSR, BEMFA_Pin);
SET_BIT(EXTI->RTSR, BEMFA_Pin);
}
void BEMFB_Falling() {
pinState = 0;
BEMF_Pin = BEMFB_Pin;
CLEAR_BIT(EXTI->RTSR, BEMFB_Pin);
SET_BIT(EXTI->FTSR, BEMFB_Pin);
}
void BEMFC_Rising() {
pinState = 1;
BEMF_Pin = BEMFC_Pin;
CLEAR_BIT(EXTI->FTSR, BEMFC_Pin);
SET_BIT(EXTI->RTSR, BEMFC_Pin);
}
void BEMFC_Falling() {
pinState = 0;
BEMF_Pin = BEMFC_Pin;
CLEAR_BIT(EXTI->RTSR, BEMFC_Pin);
SET_BIT(EXTI->FTSR, BEMFC_Pin);
}
Please help.
2023-02-15 07:59 AM
I also have the same problem, I don't know if you have solved it, can you give me some advice?