Advice on Current Sensing for new board design

To be precise this is my schematic for the board i build :slight_smile:

With a 12 bit ADC you will get a current resolution of 4.6 mA, the full scale current is -5A to +5A. And the price is about 5 euros.

I can send you my altium library with this component if you are interested in :slight_smile:

Best regards

Hey @robin2906 :smiley:

I would like to be able to order everything from JLCPCB (the easiest for me and anyone other who wants to fabricate the board), and unfortunately they do not have TSC2010. I am thinking of using the 50V/V gain INA213AIDCKR + 10mOhm shunt.
At the end I would gain a bit of resolution and loose a bit of range. But I suppose that currents higher than 4Ams will be really rare with this board.

What do you think about this combination?

Unfortunately the INA213AIDCKR is a HIGH SIDE current sensor not an in-line current amplifier. It can’t be used as an in-line current sensor because it accept only common mode voltage from 0 to 26V and is rejection is too bad for in-line current sensing:

image

Comparison with TSC2010 from st :

It recover in less than a 1 us for a common mode step of 12V and it is tolerant to up to 70V of common mode step.

Without any affiliation. I have had good experiences with PCBWay - they’ll order TSC2010s for you if your design needs them.

But - the INA*** chips are smaller and cheaper anyway. I’m looking at those as well for the designs I’m doing. There’s some fairly awesome application notes from TI about choosing them, specifically for low side sensing applications. I will try to attach them here…

Hmmm… seems I can’t attach PDFs?
Let me see if I can find the links:

Hi Robin,

I’m wondering why you say this? It seems to me the current must pass through the low side shunt resistor, since Sense1 is Phase 1 & 2, and Sense2 is Phase 3. Where else would the current go? It’s a genuine question on my part - I’m just a humble IT guy trying to learn about this complex world of BLDC control…

I’ve seen other chips (e.g. STSPIN830 but also others) which have this kind of low side sensing setup combined with extra inputs for limiting the current based on those, so at least in some designs it should work? Is it something different about the L6234?

Regards from Vienna,

Richard

Hi Richard,

No problems I will try to explain :slight_smile:

An inverter is basically 6 switches, each can be ON (a current can flow through it) or OFF (no current can flow). I you put a shunt resistor connected between the ground and the low side of the tree branch of the inverter you will get an image of the current flowing through the inverter.

But keep in mind that in each branch of the inverter the lower transistor is always in the opposite state from the upper transistor of the branch. Are you alright with this principle?

Our low side current sensing circuit have a huge drawback: it can get an image of the current only when a low transistor is ON !

When a low side transistor is ON then the current in the coil of the motor pass through the shunt resistor. If we measure the voltage across the shunt we will know the current passing through it.

But what if the low side transistor is OFF? If the low side transistor of the branch is OFF then no current will flow through the resistor because one side of the resistor is connected to the ground and the other side connected to nothing. So if we sample the voltage across the resistor we will know nothing.

If you are confident with this you can deduce the table in my previous message :

For most states of the inverter you will find that the current flowing through the shunt is always the current of one inverter branch at time.

For two state of the inverter (T1 = 0, T2 =0, T3 = 0) or (T1 = 1 T2 = 1 and T3 = 1) you will find that the current flowing through the shunt will be Ia + ib + ic. But if you know Kirchhoff law you already know that in a closed circuit the current entering the circuit is equal to current leaving, so in our BLDC case: i1+i2+i3 = 0 … magic … a lot of current is drawn by the motor but the voltage drop across the resistor is 0… so that why you cannot sample easily the total current with a single low side shunt resistor :frowning:

But as you point it, STSPIN830 use a low side shunt, and it work well! Next is an overview of how the ST engineer handle it:

If you know that your inverter is in the state for example T1=0, T2 =1 and T3 =1 then according to the table the current flowing through you shunt resistor is ia. If you are rapid enough you can start your MCU ADC and get the value of Ia.

Then you wait some time until your inverter reach the state T1=1, T2=1 and T3 = 0 and you firing again you’re ADC, you can sample ic.

But be careful … sometime if the state duration is too low, for example 20 us, and your ADC need at least 30 us to sample the voltage drop across the shunt you cannot use this state for sampling ic… That why you need a complicated algorithm to select which inverter state will have a duration compatible with you sampling time depending of the motor operating point …

After when you have the 2 currents properly sampled you can deduce i3 because as always i1 + i2 + i3 = 0 BUT be careful, your pain is not about to end … Here you have to use an algorithm for compensate the lagging in your acquisition because you haven’ sampled ia and ic at the same time (you waited for your inverter to be in the appropriate state for sampling the second current…).

When you have the tree current corrected from the lagging and the rotor position you can compute your torque controller, torque limiter, power limiter or whatever you want “easily”

So to conclude, single low side shunt work, but the price to pay is complex algorithm and a MCU with appropriates peripherals adapted to this kind of operation. STSPIN830 is perfect for this, Arduino is definitely not :wink:

Don’t hesitat to ask if it’s not clear

Best regards

3 Likes

Hi Robin,

tank you very much for your detailed explanation. I really appreciate it if people use their spare time to help other people gaining knowledge to overcome their problems.

We now know, that lowside current sensing is rather not a good way to implement torque control.
But how about current monitoring?
If my adc is way slower than my PWM or if i filter the sensing signal with a lowpass filter it should be possible to detekt overcurrent events such as collision, shouldn´t it? In this case the measured current will allways be a averaged current through the motor.

Best regards
Anderson

1 Like

Hello,
I agree with Robin, it is enough complex, but not impossible :).

It can be possible with an arduino, but I don’t know if it is enough quick (with stm32 I am sure).

We have to trigger the position of the ADC in the middle point of the PWMs duties

In the first time : (Time of PWMB + Time of PWMC)/4+deadtime

The SVM sector 1&3 match with -Ic
The SVM sector 2&6 match with -Ib
The SVM sector 4&5 match with -Ia

In the second time : (Time of PWMA + Time of PWMB)/4+deadtime

The SVM sector 1&5 match with Ib
The SVM sector 3&2 match with Ia
The SVM sector 6&4 match with Ic

Then, we have to compute in the SVM sector:

1&6: Ia = -Ic - Ib
3&4: Ib = -Ia - Ic
2&5: Ic = -Ia - Ib

If I didn’t mistake in the phases, it should be working :slight_smile:

Best regards.

I’d like to throw in my vote here to keep it more general. The way I see it there are 2 main reasons to do current sensing in BLDC control:

  1. to recover the phase angles via measurement of the current, to be able to drive the FOC algorithm without the need for an encoder, or to improve on encoder only setups in some way

  2. to limit the motor current to some value, usually to prevent something burning up (e.g. MOSFETs, Motor Windings, PCB traces and batteries).

or combination of both reasons…

Reason 1 is a nice feature for SimpleFOC because many setups will be greatly simplified in terms of physical setup and cost if you can get acceptable FOC performance without the encoder.

Reason 2 is a nice feature for SimpleFOC because many new kinds of motor windings can be used, and higher voltage/current setups become possible. With FOC control and the possibility of “holding” a position, current limiting is required to ensure the MOSFETs are operated with a “pulsed” current.

As I understand it, a solution for current sensing for driving FOC requires either 3 shunts, or 2 shunts and some extra calculations, or just one shunt and lots of complex calculations correlated to the algorithm timings.

As I understand it, a solution for current sensing for limiting current is considerably simpler in terms of the software, requires only one shunt, either high or low side, but needs to be implemented “fast”, i.e. in a way that guarantees the current gets limited before the burning starts.

In any case, in my opinion, SimpleFOC should try to do all of these things - current sensing for limiting, current sensing for FOC control, and 3 shunt/2 shunt/1 shunt, and high-side, low-side and inline.

Why? For the same reasons Robin states: SimpleFOC is trying to be a general library, not tied to specific hardware. So its hard to predict which type of current sensing the user will need in their application. In the same way you support multiple angle-sensors, you could support multiple current-sensors :slight_smile:

That said, it is obviously best to start with one kind of sensing and build from there.

Perhaps I can be of help, but unfortunately this stuff is a hobby for me, and judging the speed with which my hobby progresses I guess you will be long finished before I can be of any use…

1 Like

Hey @runger!
I appreciate the enthusiasm :smiley:

We are aiming to support as many motor+sensor+mcu+driver combinations out there and this will continue for sure.
Current sensing is a new topic for me and for simplefoc and I am eager to dig into it.

At the moment with help of @robin2906 I designed a new SimpleFOCShiled with double shunts in-phase which is going to be a great test-bed for this.
Once when I have a good version of it I will make the files available.
I am uising INA240 current sense amps (vrsion 50V/V) and 10mOhm shunts for starters. But this could be changed to 20mOmh and 20V/V version.

Till then, I have the DRV8302 board that I found some time ago and it has low side current sensors for all 3 phases. I am going to concentrate on it for the first implementation. But as robin already very very well explained the low-side implementation tends to be very hardware specific and might result in dividing the simplefoc library to stm/esp/arduino/teensy separate libraries.

Hi, and thank you for that excellent and detailed explanation. I think I understand most of it but I’d like to take you up on your offer to clarify, if you don’t mind!

The STSPIN830 is a pretty cool driver, but it’s just a driver. It doesn’t have a MCU, so it can’t do FOC by itself, and it uses the current sense input only to limit the motor current (for things like low resistance windings or stall situations I assume). But it can be configured for either 3-PWM or 6-PWM driving, and has some other cool features. It’s very small though, and the PCB layout is (for me) challenging.

I understand fully the argument that sensing the individual phase currents for the purposes of FOC control with just one low side shunt is very difficult, as you describe and illustrate with the table.

But for the purpose of current limiting, when you’re only trying to understand the total current flowing through the system and don’t care about individual phase currents, why would the 1-shunt setup not work?
When T1,T2,T3==0 then the current flowing through the system is also 0, or am I wrong? I guess this state is not a normal state in terms of motor commutation, but can occur due to the PWM?
I would assume that – for the purposes of current limiting --, a single high-side or a single low-side shunt should read the same value?

Isn’t the reason single shunt sensing is ok for current limiting purposes, because the whole system current is flowing through the shunt, regardless of which path it takes through the windings?

Regards from Vienna,

Richard

Hi Mr Anderson,

Yes absolutely, you can detect collision with low side single shunt. If the motor stall then a huge spike of current will flow through the resistor. In my opinion the best way to do that is to synchronize you ADC with a state of your inverter. With this method you limiting current threshold is set regarding to the maximum current for a phase of your motor.

A low pass filter can also do the tricks but be careful to not set your current limiting threshold too high because state 0 and 7 of the inverter will always lowered your “averaged” current value.

Let a free running ADC sampling at low frequency is not a good option in my opinion because if you have no luck you will always sample state 7 or 0 of the inverter :wink:

Best regards

Hi Richard,

You’re welcome, it’s cool if it was helpful :wink:

Sorry I was thinking about the STSPIN32F0 :slight_smile: Yep exactly the shunt resistor is used only for current limiting.

With a low side current sensor you can’t know “the total current flowing through the system” you can only know one phase current at time :wink:

But you are completely right, in a current limiting application a low side shunt can be enough because you don’t mind to know exactly which phase overconsume. You just have to observer the shunt voltage, if it rise above a threshold you have to cut power down as fast as you can before it’s too late :slight_smile: This feature is present in the STSPIN830.

But again with a low side current sensing it’s difficult to know all the current flowing through the 3 coils of the motor you need a complex algorithm for this purpose.

Yep the sum of the 3 current will be 0. It can happen when you do FOC with your motor.

Yes high or low side will sense the same value.

The high side sensor is more difficult to build but you can protect your design against a short to ground.

With a low side resistor it’s easy to build but you cannot detect if a branch of your inverter is shorted to GND because each side of your shunt resistor will be connected to GND.

Again not the whole current flowing through the motor, just the current flowing through one phase at time.

Best regards

Is it important to know the precise value and progression of current values? Or would it be more useful to know the exact moment current passes a few specific (pot adjustable) thresholds? In that case, a flash ADC with comparators triggering interrupts might be used. No more concerns about sampling duration.

Hey,

I re-found the application note I’d read a while back on all this current sensing stuff. I think it explains it rather well:

https://www.ti.com/lit/ug/tiducy7/tiducy7.pdf

I guess you all know it?

Regards,
Richard

1 Like

@runger I’ve just scanned this and it looks really good! I’ll have a proper look at it this weekend.
Thanks for sharing

Nice!

Is torque ripple same as transient spikes ?

Chers,
Søren

Tourque ripple is “jitter” or anisotropy in the motors torque. I.e. the force the motor can provide is not “smooth”.

I think it typically refers to constant load situations, I.e. while holding or driving with constant speed?

I’d really like to understand it better myself, so if anyone has insights I’d be pleased to hear them.

But I think, if I understand correctly, that basically torque ripple is undesirable as motion will be less smooth, and it can be audible.

Also, the problem exists to different degrees depending on different parameters - things like load, rotation speed, PWM freq., etc…
So you want to avoid setups which work well for some parameters, but develop high torque ripple for others…

Regards from Vienna,

Richard

Hi folks,

once again i`m struggling with low side current sensing. In AN5306 ST proposed a lowside current sensing with the STM32G4 series. Here is a screenshot.
Screenshot 2020-12-09 130924

Furthermore the range of the opamp input voltage ist from 0V to VDDA, as can be seen here

Source

How can this be done without damaging the the chip? As far as i understand the switching process of the three halfbridges, there is a freewheling current inbetween every positive pulse of the top side pwm cycle. This current flows “backward” through the shunt and through the freewheling diode of the lowside mosfets. So this current causes a negative voltage drop at the shunt resistor.
Screenshot 2020-12-09 132440

I am missing something? Why is ST recommanding this allthough it can harm my chip?

Best regards
Anderson

You ask excellent questions! I have been wondering about these things myself as I wrestle with the design of a current sensing driver.

My take on this: when doing low side sensing, the common mode shifts are small, and the negative voltage seen across the shunt is usually only a small mV value. While the common mode of the op amps should be 0 - VCC, they can tolerate negative voltages in the small mV amounts, and it does not matter.

Some of the external current sense amp chips explicitly mention this in their datasheets.

So its just a guess from a relatively inexperienced person, but that’s my take on why they’re doing this.