2
\$\begingroup\$

I want to measure current using sensor MLX91220 which gives output in analog. I have battery that I charge and discharge via switching MOSFET and want to measure current on this grid.

Problem is that it gives stable output when MOSFET's gate PWM is either at 0% duty cycle or 100% but fluctuate a lot in middle range.

I found similar problem related to this. Suggestions were to use low pass filter and cutoff frequency depends on the PWM frequency and microcontroller's ADC's sample rate but I have no idea how to select from that. Also my duty cycle is changing during this period, so does that affect choosing frequency ?

I have seen current readings from in built BMS, those are very stable, what (or which method) is used in that ?

\$\endgroup\$
1
  • \$\begingroup\$ Usually that would imply of the use of LC filter, ceramic caps and low dcr inductor. But in your case the switching frequency s such low that it would be to big, too expensive. \$\endgroup\$ Aug 25, 2021 at 13:19

2 Answers 2

1
\$\begingroup\$

If you have enough oversampling you may can just average the measurements to get a rather stable and accurate result. The problem with measuring alternating signals like pwm is that if your sample rate doesn't match the frequency of the signal you tend to get unstable results depending on where the samples actually are taken.

Another option would be to sync the ADC to the generation of the pwm, assuming that it's the same controller which controlls both - if not you might can feed the pwm signal to the uC.

\$\endgroup\$
1
  • \$\begingroup\$ For testing I am using separate Arduino but later on I have to implement the same on BeagleBone. Even if I can oversample I don't think I can assign that much processing power to this task, it already has good computing tasks. I have to look in details for syncing ADC and PWM, I'll try that too. \$\endgroup\$
    – dharmikP
    Aug 25, 2021 at 13:21
1
\$\begingroup\$

We really need a schematic of your charging circuit to be sure, but the likely problem is that you're undersampling the output. Your sensor is measuring the instantaneous current, but the current is being switched on and off by your PWM controller.

If this is the case, the easiest solution would be to put a large capacitor across the sensor. The sensor has an impedance of <1milliohm, so if your PWM frequency is 1.60MHz, a 1000uF cap would give you about 20dB (10X voltage) attenuation of the AC portion of the PWM signal. It may be more practical to put a passive or active lowpass filter between the sensor and the ADC.

If that's not practical, you could sample the ADC at 20-100X the PWM frequency and average (LPF) in your processor. Not knowing your PWM or ADC specs, I can't guess whether that's practical or not.

My guess is the LPF between the sensor and ADC is your best bet.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I am using Arduino Nano , default ADC frequency is 9.6kHz and my PWM frequency is 1khz. The number of cap value you mentioned, I want to know how to calculate that. \$\endgroup\$
    – dharmikP
    Aug 25, 2021 at 13:14
  • \$\begingroup\$ I used f=1/2piRC, which gives you the filter corner frequency 160 KHz for a 1000uF cap, then multiplied it by 10 to get 160MHz (because I dropped the decimal, corrected above). For 1KHz PWM, it would be over 1F, so that's not too practical (maxcaps would be too slow, I think). Hardware LPF between sensor and ADC looks much better, but if you can jack up the ADC sampling rate, a software filter would probably work too. (In rough terms, sampling a PWM signal for average value gives you an accuracy of about PWM rate/sample rate, which in your current configuration is just over 10%.) \$\endgroup\$ Aug 25, 2021 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.