Current sensing problem - Page 1
Forum section: electronics / beginners

author: bonzer35
author_rank: Contributor
timestamp: December 14, 2023, 10:09:25 pm
content: I am building a pump controller with a current sense circuit. The pump motor is PWM controlled via an Atmega 328. The MCU also measures the current across a shunt resistor R1 via the MCU ADC and a current sense amplifier (U1). The problem I have is that if the motor is under load to the point where it stops, the current measured drops to zero. If I connect an ammeter inline with the power supply, I can see that the current increases when the motor stops but the measured current through the shunt is zero. In addition, when the motor is stopped, it seems that the current that is being measure by my ammeter is likely going through the diode D2 as this heats up rapidly.How can I modify this circuit to ensure that the current can be measured even if the motor is stalled? I wondered if putting it inline with the supply would be better.Thanks in advance for any help.

author: Whales
author_rank: Super Contributor
timestamp: December 15, 2023, 03:45:46 am
content: D2 getting hot is interesting. Is the motor being run with 100% PWM when stalled or is it still partial duty cycle?Is the 12V power supply (which powers both the motor AND the ZXC current mon chip) going bad when the motor is stalled? That might make the current mon chip misbehave.I assume the IRLZ44N mosfet stays cold throughout this? Could the heat possibly be coming from this instead (it's also in a TO-220 package)? It looks like it has a low gate threshold voltage so it should work with a 5V gate voltage from an Arduino fine.

author: jwet
author_rank: Frequent Contributor
timestamp: December 15, 2023, 04:21:51 am
content: I agree with last poster. What you've posted looks pretty good. You're sensing motor current correctly. My biggest question is - what kind of stall current are you getting on your DMM? Your .05 ohm resistor should give 100 mV at 2 Amp current (edited this- is this high enough?). The ZXCT shouldn't fold back or anything at high current unless the supply is collapsing and you're pulling down the supply below 2.5v. Also the data sheet doesn't show the 4.7K resistor in the Vs- leg but the bias currents are low enough that it should be ok. The fact that D2 is getting hot is really strange, it should just be keeping current flowing during your PWM off cycles. Is the software driving the hell out of PWM when it sees high currents?Challenging problem, willing to do some back and forth if you'd like.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 15, 2023, 05:06:59 am
content: Not that this is the issue, but by connecting D2 cathode to +12V the motor BEMF will keep flowing current through the shunt when PWM is off, providing a smoother reading (Inductor-filtered triangular shape, instead noisy square PWM).Are you properly measuring the current? I mean the ADC reading should be synced so it reads when the pwm output is on.

author: Whales
author_rank: Super Contributor
timestamp: December 15, 2023, 07:13:03 am
content: > Are you properly measuring the current? I mean the ADC reading should be synced so it reads when the pwm output is on.That's a good point. This probably isn't what is causing your main issues, but it's still important. PWM will cause lots of noise in your current readings if you just make those measurements whenever you want.You can either:(1) Fix it in software: Synchronise your ADC readings with the PWM output.(2) Fix it in hardware: Add a low pass filter to the board to smooth out the current reading into an average. ie add a capacitor between the + and - sampling pins of the ZXC.

author: bonzer35
author_rank: Contributor
timestamp: December 15, 2023, 02:02:40 pm
content: Thanks for the comments - a lot of good replies there. I'll try to address each of the raised questions/comments:Quote from: Whales on December 15, 2023, 03:45:46 amThe motor is not being run at 100% PWM when stalled. The torque of the motor makes it hard to stall at 100%.The symptoms occur at all duty cycles where the torque is not too high to stall. Regarding the power supply, I am using a decent desktop computer SMPS and stalling the motor doesn't seem to cause the PSU to cut out. I get the same problem whether on a PSU or an 85Ah leisure battery.The MosFET stays cool and the diode is very toasty when stalled.Quote from: jwet on December 15, 2023, 04:21:51 amStall current measured across whole circuit can go up to 7A depending on PWM setting. The 0.05 ohm resistor should give me 0.5v across the resistor with a 10A load. The resistor R7 on the ZXC sense amplifier means at FSD it should output nearly 5v into the MCU.... unless my calcs are wrongThe datasheet for the ZXC shows a 4K7 to protect the sense amplifier from inductive loads. As mentioned above, the issue is not caused by driving the motor flat out.Quote from: Whales on December 15, 2023, 07:13:03 amThere is a lot of noise in the readings, even though I added a LPF (R2, C2) to filter the 7.8Khz PWM. I do already sample the rising edge of the PWM before capturing the current reading. I should really ensure the reading is valid by checking for a high on the PWM after sampling as well, but the speed of the PWM means the code doesn't execute fast enough to check reliably. Thanks for the tip on capacitor between sense pins of the ZXC.

author: bonzer35
author_rank: Contributor
timestamp: December 15, 2023, 03:07:40 pm
content: Quote from: DavidAlfa on December 15, 2023, 05:06:59 amI followed your advice and actually, I think this was the issue! I now get the kind of readings I'd expect, even when the motor is stalled. I'll keep testing but initially this looks to have solved the problem - thank you!

author: Whales
author_rank: Super Contributor
timestamp: December 15, 2023, 03:11:03 pm
content: > There is a lot of noise in the readings, even though I added a LPF (R2, C2) to filter the 7.8Khz PWMI recommend moving the LPF before the current sense IC. The current sense IC could be doing weird nonlinear things when there are transient excursions outside its range, but an R and a C will be fine as long as it's within their voltage ratings.> I followed your advice and actually, I think this was the issue! I now get the kind of readings I'd expect, even when the motor is stalled. I'll keep testing but initially this looks to have solved the problem - thank you!There is no way this could have solved the problem of D2 getting hot too.Surely?On that note: you mention having a battery to be able to run this off. This might let you run it isolated (assuming the Arduino also runs of the bat), allowing you to use your scope probe directly across D2 to see what it's doing.

author: bonzer35
author_rank: Contributor
timestamp: December 15, 2023, 03:15:49 pm
content: Quote from: Whales on December 15, 2023, 03:11:03 pmNo, not the heating issue but the zero current readings.Thanks for the advice re putting the scope across D2 when powered by battery - I'll try that.

author: Whales
author_rank: Super Contributor
timestamp: December 15, 2023, 09:37:20 pm
content: Just make sure not to have any of the equipment hooked up to your computer via a USB cable during this test. That then ties the circuit ground to your house wiring ground, ruining the isolation.I solemnly swear I have never made this mistake before.

author: bonzer35
author_rank: Contributor
timestamp: December 16, 2023, 01:18:07 pm
content: I've been trying to work out what had been going on with the issue I had, both with zero current sensing and the heating of the diode. Here's my theory ...When the motor is stalled, the PWM causes a high current to flow through the motor windings but due to PWM this current turns on and off rapidly. This pulsing results in collapsing magnetic fields to induce back EMF that causes current to flow through the diode. The back EMF means that the voltage drop across the sense resistor disappears or reduces significantly which is why it measures zero current. Moving the diode leg to the positive rail means that the potential difference is maintained at the junction with the resistor and motor.Does this sound like a reasonable explanation or is it littered with newbie misunderstanding?

author: jwet
author_rank: Frequent Contributor
timestamp: December 17, 2023, 02:39:41 pm
content: >>>Does this sound like a reasonable explanation or is it littered with newbie misunderstanding?Yes I think it does. In the normal case, you pulse the motor with some voltage and current and most of the energy leaves as mechanical energy to do its job and the rest gets snubbed by the diode. In the case of a locked rotor, you're asking the diode to get rid of all the energy that you've pumped in. Good thinking on your part.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 17, 2023, 03:00:25 pm
content: Completely normal. D2 gets hot with large motor current and low duty cycle. Use synchronous switch if poor efficiency at low RPM, high torque is a problem.Supply current sensing senses supply current, which is low at low duty cycles (low RPM), but motor current can still be pretty high. Best place to sense current is low side, i.e. between the MOSFET source and GND. That way, you are sensing motor current and can actually regulate the torque.

author: Siwastaja
author_rank: Super Contributor
timestamp: December 17, 2023, 03:02:04 pm
content: Quote from: jwet on December 15, 2023, 04:21:51 amNo, there is no motor current sensing in this schematic at all. You can calculate it from input current, knowing duty cycle, but it's better to sense it directly to begin with.

author: bonzer35
author_rank: Contributor
timestamp: December 17, 2023, 03:57:32 pm
content: So are you saying that high-side current sensing is only sensing supply current but low-side is better for sensing actual motor current?

author: Siwastaja
author_rank: Super Contributor
timestamp: December 17, 2023, 05:55:15 pm
content: During off-time, current only flows in the freewheeling diode. You'd need to place the sense resistor within that loop - in series with the motor - to sense motor current. Currently you are only sensing the motor current when the MOSFET is conducting. You can calculate average motor current by assuming the current is the same during on-time and off-time.In any case, I think your problem might be that current measurement is not synchronized to PWM, am I correct? With low duty cycle, the on-time is so short that if you read the current outside of that tiny window, you just read zero. You have to read at correct timing, when the MOSFET is on; optimally in the middle of the conduction period. Then you still won't know the exact motor current without measuring it (you are missing the off-time measurement), but probably good enough given your current schematic.Or, you can take a lot of samples during the whole switching cycle (say, dozens) for average input current. Then you can estimate average motor current by multiplying by 1/D. Example: D = 10%. Actual motor current = 10A. Current through the shunt = 10A for 10% of the time, 0A for 90% the time, average 1A. Calculate 1A * 1/0.1 = 10A.

author: bonzer35
author_rank: Contributor
timestamp: December 17, 2023, 09:14:14 pm
content: Great info - I understand.The current measurement is synchronized with the PWM but because I'm running PWM at 7.8Khz, I don't think the code is running fast enough to capture all the samples reliably at the lower duty cycles where the pulse width is much smaller. I may try to do this by using interrupts rather than polling. I already obtain the average of about 50 samples.It's not crucial for me to get super accurate current measurement so I don't feel I need to move the resistor to the low side on this particular circuit but it's really useful to know how this should be done if I need good measurements. Thanks

author: trilerian
author_rank: Regular Contributor
timestamp: December 18, 2023, 04:38:06 am
content: I have made a couple of circuits now that measure current for my projects. One measured the current of a bldc motor. I use the Allegro ACS hall sensors though and not a shunt, but really it should still be fine with a shunt. The drive frequency of the bldc motor was 12khz. The trick is to take the average that the sensor outputs. The bldc circuit is a high side circuit and in series with the power source. My current project is a battery discharger and I am using a feedback loop to control the pwm duty cycle to keep my discharge at a constant rate. This is a low side current sensor, but still the ACS hall sensor. I will say getting a good low pass filter on the output helps too.