Author Topic: H-bridge current measurment  (Read 1488 times)

0 Members and 1 Guest are viewing this topic.

Offline RARvoltTopic starter

  • Newbie
  • Posts: 4
  • Country: pl
H-bridge current measurment
« on: November 01, 2020, 11:53:22 pm »
I've been looking around the forum for some time and this is my first post, so hello everybody!  ;D

For my engineering thesis, I am building a two axis inverted pendulum stabilised with reaction wheels (something similiar to this).
I am using there STM32F411 (aka. BlackPill) microcontroller. It controls two 12V DC motors (Pololu #4757) using two H-bridge modules - Cytron MD13S. So I can control two motors with PWM and DIR each.
I also wanted to measure the current draw from each motor and since the hall effect current sensors I had on hand had to wide range I decided to build my own current sensing circuit with shunt resistors.
I want to measure current (max 5A) in both directions and have it converted into voltage 0-3.3V (for µC's ADC), so when there is no current flowing the ADC will read Vcc/2. I found this application note from ST and used schematic from section 2.1:
1101434-0
I worked out resistors values as follows:
$$I_{max}=5A\\
V_{DD}=3.3V\\
R_{s}=50m\Omega\\
V_{s}=0.25V\\
P_{Rs}=1.25W\\
G_{max}=\frac{V_{DD}}{2I_{max}R_{s}}=6.6\\
G=6\\
\frac{R_2}{R_1}=G-0.5=5.5\\
R_1=2k\Omega\\
R_2=11k\Omega\\
2R_2=22k\Omega\\
f_{LP,o}=\frac{1}{2{\pi}R_{LP}C_{LP}}\\
R_{LP}=2k\Omega\\
C_{LP}=100nF\\
f_{LP,o}\approx800Hz$$


I then created following schematic (x2 for two motors):
1101438-1
I got the PCBs from JLCPCB, soldered them, tested voltages in various places, inserted programmed microprocessor and found out that when the motor is spinning in one direction everything is fine, I'm getting reasonable readings, but when motor is spinning in other direction readings are just maxed out to the end of the scale.
Example:
  • Motor spinning left - ~1.7V - OK
  • Motor not spinning - 1.65V - OK
  • Motor spinning right - 0V - BAD
If I reverse the polarity of the connections I am getting the same result just reversed.
Shunt resistor is connected in series with the motor between A and B connectors on the MD13S module.
I am attaching full schematic below.

What am I missing here?  |O
« Last Edit: November 01, 2020, 11:58:36 pm by RARvolt »
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 17194
  • Country: us
  • DavidH
Re: H-bridge current measurment
« Reply #1 on: November 02, 2020, 04:09:13 am »
I do not think this is your problem but the original circuit has a flaw.  The feedback capacitor across R2 needs to be balanced with the same time constant on the non-inverting side so half value capacitors across the 2xR2 resistors.  Without this, the AC common mode rejection will be compromised.  It may be better to just leave the feedback capacitor out or use the least possible capacitance and rely on CLP to limit bandwidth.

Where is the difference amplifier connected?  If the source side of the transistors, then it will only see current in one direction.
 

Offline S. Petrukhin

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: ru
Re: H-bridge current measurment
« Reply #2 on: November 02, 2020, 06:33:42 am »
I got the PCBs from JLCPCB, soldered them, tested voltages in various places, inserted programmed microprocessor and found out that when the motor is spinning in one direction everything is fine, I'm getting reasonable readings, but when motor is spinning in other direction readings are just maxed out to the end of the scale.
Example:
  • Motor spinning left - ~1.7V - OK
  • Motor not spinning - 1.65V - OK
  • Motor spinning right - 0V - BAD

Why is it bad? This is how it should be. Vcc/2 is the midpoint, the starting point. An increase in the voltage from it means an increase in the current in direct rotation. The voltage drop from it is an increase in the current in the reverse rotation.

You need to make the value obtained from the ADC signed and subtract Vcc/2 from it. Then positive values will indicate the forward value current, negative values will indicate the reverse rotation current, 0-stop.

If this is inconvenient, you can enter a flag for the direction of rotation.
Code: [Select]
var
   ReversDirect : boolean;
   Current : integer;
begin
   ReversDirect:=false;
   Current:=ADC-Vcc/2;
   if Current<0 the begin
      ReversDirect:=true;
      Currenr:=-Current;
   end;
end;


Also, both lower arms of the bridge must be connected to the current sensor resistor, not one of them.
« Last Edit: November 02, 2020, 06:38:01 am by S. Petrukhin »
And sorry for my English.
 

Offline RARvoltTopic starter

  • Newbie
  • Posts: 4
  • Country: pl
Re: H-bridge current measurment
« Reply #3 on: November 02, 2020, 11:18:06 am »
Why is it bad? This is how it should be. Vcc/2 is the midpoint, the starting point. An increase in the voltage from it means an increase in the current in direct rotation. The voltage drop from it is an increase in the current in the reverse rotation.

I have radings from ADC reversed, so 0 means Vcc and 4096 means 0V
Any rotation in reverse direction results in reading going straight to zero.
The motor is powered from separate 12V PSU. I have grounds connected in single point.
I tried powering the load from 3.3V and I had good readings in both directions.
When I powered the load from 5V, I measured around 0.5V on non-inverting input of the TLV2316 (pin 5).
When I reversed the polarity of the supply (swapped VPP and GND on schematic below), I got 4V.

Where is the difference amplifier connected?  If the source side of the transistors, then it will only see current in one direction.
Below is rough schematic of how shunt resistor is connected. Currently I am not powering motor with PWM, just straight DC from PSU.
« Last Edit: November 02, 2020, 11:22:35 am by RARvolt »
 

Offline S. Petrukhin

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: ru
Re: H-bridge current measurment
« Reply #4 on: November 02, 2020, 12:06:30 pm »
Why is it bad? This is how it should be. Vcc/2 is the midpoint, the starting point. An increase in the voltage from it means an increase in the current in direct rotation. The voltage drop from it is an increase in the current in the reverse rotation.

I have radings from ADC reversed, so 0 means Vcc and 4096 means 0V
Any rotation in reverse direction results in reading going straight to zero.
The motor is powered from separate 12V PSU. I have grounds connected in single point.
I tried powering the load from 3.3V and I had good readings in both directions.
When I powered the load from 5V, I measured around 0.5V on non-inverting input of the TLV2316 (pin 5).
When I reversed the polarity of the supply (swapped VPP and GND on schematic below), I got 4V.

Where is the difference amplifier connected?  If the source side of the transistors, then it will only see current in one direction.
Below is rough schematic of how shunt resistor is connected. Currently I am not powering motor with PWM, just straight DC from PSU.

Wait, I didn't understand your problem right away. I thought you were taking a measurement on the shunt to the engine. To measure the DC motor current in any direction, you can measure it up to the H-bridge, then you will not have negative values, you will not need to make the zero point with an offset of half Vcc. Whichever way the H-bridge turns on the motor, it will always draw current from the power supply in one direction. And the lack of signal in your experiment when changing Gnd and Vpp, I think, is due to the fact that the OP and shunt lands were connected.Note the division of land in figure 8.
And sorry for my English.
 

Offline RARvoltTopic starter

  • Newbie
  • Posts: 4
  • Country: pl
Re: H-bridge current measurment
« Reply #5 on: November 02, 2020, 12:48:24 pm »
I kinda want to read negative values, because I am going to implement a regulator that takes into account actual current of the motor to calculate the force applied to the reaction wheel.
Actually - when I know the direction of the motor from the encoder I can just invert the reading - right? In that case, I need to connect GND of the driver through the sense resistor and I could get full 12 bit reading in both directions.
There will be some offset caused by the current draw from electronics inside the driver, but I can zero it out.

I need to remove R10, R11, R15, and R18 from the circuit. Then I will add a second 2k resistor on top of R16 to get 1k (Gain=12). Do I need the 2k R12 then? Should I short it or leave it?
 

Online voltsandjolts

  • Supporter
  • ****
  • Posts: 2451
  • Country: gb
Re: H-bridge current measurment
« Reply #6 on: November 02, 2020, 01:48:06 pm »
You could put your sense resistor at the bottom end of the H-bridge to sense current in both directions.
Sense voltage is always positive but you know which way the bridge is going.
Edit: Ahh, I see, maybe that is what you are doing in the above post.
« Last Edit: November 02, 2020, 01:50:05 pm by voltsandjolts »
 

Offline RARvoltTopic starter

  • Newbie
  • Posts: 4
  • Country: pl
Re: H-bridge current measurment
« Reply #7 on: November 02, 2020, 02:07:33 pm »
Edit: Ahh, I see, maybe that is what you are doing in the above post.

I originally connected sense resistor like below, but now it is in the configuration you showed above.
I am still wondering how I should wire the circuit to get bidirectional current measurement such that
$$I_{max}=Vcc\\I_0=Vcc/2\\-I_{max}=0V\\Vcc=3.3V$$
« Last Edit: November 02, 2020, 02:09:09 pm by RARvolt »
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4195
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: H-bridge current measurment
« Reply #8 on: November 02, 2020, 02:51:23 pm »
If you are going with the approach in series with the motor, save yourself the trouble and use a high side current amplifier capable of the 12V common mode. Eg: INA240.
Make sure you don't have (negative) transients during the transition between fet and diode. (diodes are not infinitely fast and the motor is an inductor)

For motor current control in series with the motor is the best place, since it can also measure the braking current. But it is the most complicated shunt placement due to common mode change and transients. Since the voltage at the shunt changes from Gnd to +12V each PWM cycle.
« Last Edit: November 02, 2020, 02:53:30 pm by Jeroen3 »
 

Offline S. Petrukhin

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: ru
Re: H-bridge current measurment
« Reply #9 on: November 02, 2020, 04:08:39 pm »
Edit: Ahh, I see, maybe that is what you are doing in the above post.

I originally connected sense resistor like below, but now it is in the configuration you showed above.
I am still wondering how I should wire the circuit to get bidirectional current measurement such that
$$I_{max}=Vcc\\I_0=Vcc/2\\-I_{max}=0V\\Vcc=3.3V$$
Why do you need to measure a negative current value? You know the direction, you just need to measure the current-the voltage drop on the h-bridge shunt to gnd. So you will have the full ADC range of 4096 steps to measure the current, not half of it.
And sorry for my English.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 17194
  • Country: us
  • DavidH
Re: H-bridge current measurment
« Reply #10 on: November 03, 2020, 01:43:07 am »
Why do you need to measure a negative current value? You know the direction, you just need to measure the current-the voltage drop on the h-bridge shunt to gnd.

Bipolar measurement of the current allows knowing the braking direction.  That cannot happen in this case but other circuit configurations would allow it.

« Last Edit: November 03, 2020, 01:46:26 am by David Hess »
 

Online mawyatt

  • Super Contributor
  • ***
  • Posts: 3907
  • Country: us
Re: H-bridge current measurment
« Reply #11 on: November 03, 2020, 01:50:24 am »
Here's a link to a Hall Effect current sensor developed for measuring Stepper Motor Sine and Cosine coil currents, might be useful.

https://www.photomacrography.net/forum/viewtopic.php?f=25&t=39689&hilit=Motor+Current+Sensor

Best,
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf