ADC's current sense resolution


I’m still using the VESC 6 (STM32F401) hardware with SimpleFOC i’ve noted that for the current sense we have in the stm32_mcu.cpp this:

#define _ADC_RESOLUTION 1024.0f
float _readADCVoltageInline(const int pinA){
  uint32_t raw_adc = analogRead(pinA);
  return raw_adc * _ADC_CONV;

So the ADC is setup at 10 bit but in the case of the STM32F401 we can also use the 12 bit resolution.

Can I set the ADCs for current measurement to 12 bits, or is there a particular reason why it has to remain at 10 bits?

Yep, this is a mistake. It should be 4096 not 1024. :smiley:

We will do a quick release this week, with bugfixes that have appeared in the last few weeks so this one will be included as well.

EDIT: See blow!

1 Like

Ok I think I was too fast with my response here :smiley:

So stm32duino’s analogRead funciton will by default return value in between 0 and 1024 so that is why the default resolution is 1024. So it is not a mistake :smiley:

However you can modify this using the function analogReadResolution(12) and set it to 12 bit. If you do this make sure to change the _ADC_RESOLUTION as well.

Sorry for the confusion!

Yeh, i’ve undestand! thanks you!

i was referring to an old version of the library, since still i have to port all the stuff into the 2.2.2. In fact into the 2.2.2. there’s more configuration file and indeed the stm32f4 one, where it was fixed with 4096!

For me the 2.2.2 seems solve most of the instability problems that i have experienced with previous version (even if the voltage mode still cannot be usable at all with this setup).

a quick question! the iq current should be match more or less with the current supplied with my power supply?

right now i have

InlineCurrentSense(0.0005, 20, CURRENT_1, CURRENT_2, CURRENT_3);

where the gain and resistor match with the VESC firmware and datasheet of the AD8418 reported.

but seems not be the right gain, i get a similiar value respect to the power supply with 200.

what could be wrong?

Hey @luzz94,

No not really. The current of the BLDC phases should be higher than the power supply current.

Here is a nice blog post about this effect, not going too deep but it explains well the idea:

1 Like

Really useful and interesting! So I guess we can fall back to an H-bridge configuration because of the fact that in BLDC motors only two phases are fed at a time (instead of three in the case of PMSM). From there on we can see that we have a step down converter and so it becomes clear why the phasic current is higher than the driver input current.

So in the latest version of simplefoc where KV was introduced, should be possible to calculate the back EMF (or using the inductance value) and then from the a-b-c currents roughly estimate the driver input current?

however, I still don’t understand why by setting 20 gain for inline current sense like in the VESC firmware and listed on the datasheet, it gives me the wrong current value. It seems that both (VESC and SimpleFOC) have the same conversion factor and ADC resolution right now.

Is there any way to assign the gain value correctly?

Hi @luzz94 ,
This topic is probably too old for you. But just checking if you got this to work by chance? I happen to use the same current sense amplifier (AD8418) and struggling to get it running correctly. Lot of vibrations.