Page 1 of 1

Bluepill i2c and BLDC commutation misses

Posted: Mon Nov 23, 2020 2:34 pm
by martin321
Hi,

I am using a Bluepill board to drive a BLDC motor trough 3 PWM pins and hall sensors. Hall sensors are connected to interrupt and commutation is using hardware timer.
The motor runs smooth without sending data through i2c, but when I send 20 bytes every 50ms the motor stutters and are missing commutation steps.

The receiver is a 1284P running at 8MHz.

Is the Bluepill waiting for an ACK from there receiver, so it halts the program from continuing?

Martin

Re: Bluepill i2c and BLDC commutation misses

Posted: Mon Nov 23, 2020 5:30 pm
by stevestrong
martin321 wrote: Mon Nov 23, 2020 2:34 pm Is the Bluepill waiting for an ACK from there receiver, so it halts the program from continuing?
In the Libmaple core it will affect the main loop. But the interrupts should not be affected.
Which core do you use? Any schematic available?

Re: Bluepill i2c and BLDC commutation misses

Posted: Wed Nov 25, 2020 8:23 am
by martin321
I’m using a DRV8323 with 3xPWM signal.
There is a SIN table that analogWrite uses to create sin waves for commutation.

No sure what core I’m running. Installed STM32Duino into the Arduino IDE.
I’ve attached the IDE setup

Re: Bluepill i2c and BLDC commutation misses

Posted: Wed Nov 25, 2020 8:30 am
by stevestrong
That seems to be the official STM core.
@fpiSTM will take care of this.

Re: Bluepill i2c and BLDC commutation misses

Posted: Wed Nov 25, 2020 12:46 pm
by fpiSTM
This fairly depends on your code.
I2C works with IT and I guess priority is higher than the one you used for the HALL sensor, that's probably explain why you have this issue.

Re: Bluepill i2c and BLDC commutation misses

Posted: Fri Jan 22, 2021 7:56 pm
by martin321
fpiSTM wrote: Wed Nov 25, 2020 12:46 pm This fairly depends on your code.
I2C works with IT and I guess priority is higher than the one you used for the HALL sensor, that's probably explain why you have this issue.
Hi fpiSTM,

I have tried to find a way to set the hallsensor update to a higher priority than i2c.
What I have found and tried hasa not worked. Probalby because I have not implemented it correcty.
https://github.com/stm32duino/Arduino_C ... issues/472

The stutters happened only at higher speeds. I guess this is when i2c uses more time that the commutation period.

HardwareTimer* motorTimer = new HardwareTimer(TIM1);
This is where hallsensors position is gathered and a sin lookup table is used to set analogWrite

HardwareTimer* i2cData = new HardwareTimer(TIM2);
i2cData is the function where a single i2c request is made and a single i2c transmission.

Can the problem be that I am doing a i2c send/receive inside a HW timer?

I will try tomorrow to move it to the loop and use a "blink without delay" function.

Martin

Re: Bluepill i2c and BLDC commutation misses

Posted: Sat Jan 23, 2021 3:06 pm
by martin321
It worked when removing i2c from TIM2 and use it directly in the loop.
I see now why there would be a problem with i2c inside TIM2.

Had to read the code again yesterday to see it.

Martin

Re: Bluepill i2c and BLDC commutation misses

Posted: Sat Jan 23, 2021 3:10 pm
by fpiSTM
If you use the I2C inside the Timer handler IRQ then I guess you are in a deadlock.