I've been looking around the forum for some time and this is my first post, so hello everybody!
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:
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):
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?