simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
1.94k stars 510 forks source link

[BUGFIX] Injected channel #371

Closed askuric closed 5 months ago

askuric commented 5 months ago

There seems to be a bug in the code ( one pretty hard to find, believe me :D )

Basically when in the for loop the injected channels are read the current code does a completely reasonable assumption that ADC_INJECTED_RANK_1=1, ADC_INJECTED_RANK_2=2, and ADC_INJECTED_RANK_3=3, However, at least in case of stm32g474 this is not the case :D So here is the fix to avoid this assumption.

Candas1 commented 5 months ago

Hi,

I added this code for using injected adc registers and not using the interrupt anymore. For the channel I use i+1, it wasn't OK ?

askuric commented 5 months ago

Your addition works great it's just that for some architectures the i+1 did not correspond to the ADC_INJECTED_RANK_x. In particular my nucleo stm32f474re, in the case fo G4 architecture it is defined using LL flags

#define ADC_INJECTED_RANK_1                (LL_ADC_INJ_RANK_1) /*!< ADC group injected sequencer rank 1 */

here is the link

For some architectures it is just from 1 to 3 but for others its done using these LL flags. stm32duino repo search. I am not even sure that these LL flags are consecutive. So it's safer to enforce using the ADC_INJECTED_RANK_x.

Candas1 commented 5 months ago

My bad, first bug.

Candas1 commented 5 months ago

What driver are you using with your nucleo board that has 3 shunts ? I need a proper 3 shunt setup for my tests.

runger1101001 commented 5 months ago

Here's a higher power one with 3 shunt sensing: https://www.aliexpress.com/item/4000126430773.html It also has 2 shunt sensing for some reason (as someone recently pointed out on the forum) so this is even a board where we could run 2x current sensing at the same time :-D

This one: https://www.st.com/resource/en/data_brief/x-nucleo-ihm07m1.pdf Will plug directly into a Nucleo64, and has 3-shunt sensing. Not so high power, but might be convenient...

I also have a DRV8316 based board which has current sensing (3 shunt low side), I could send you one if you want :-) but it is in the shape of a Arduino MKR Shield so you'd need jumper wires to connect it to STM32s.

Candas1 commented 5 months ago

Actually I already have: X-NUCLEO-IHM07M1 X-NUCLEO-IHM16M1

And even managed to order this one when it was finally in stock: X-NUCLEO-IHM16M1

I need to go through the docs and see if I can use all shunts on same ADC with the nucleo boards I have.

askuric commented 5 months ago

Merging into the dev branch.