# How to average output of current sensor to get smooth output?

I am using INA138 current sensor with 100Hz, PWM duty 5%, 8-bit resolution signal load is a resistor,

I getting zero readings while actual current readings also appear,

edited -

zero current sense output - this means when the current sensor detects OFF DUTY of duty cycle it gives zero volts on the output., the load is an LED, controlling led brightness with a feedback loop,

I need to remove this zero by adding a low pass filter to the output of the current sensor

my sampling rate 255, cycles per second,

I need continuous measurement without going to zero, to make fast feedback control loop, I get actual current reading 5-10 times per second while other readings are zero.

I have doubt,

What if I add an RC low pass filter on the output of current sensor?

I made small stimulation 100Hz 3.3V square applied to 50Hz low filter, (not 5% duty) I see output voltage has averaged to 1.8V

how to avoid reducing voltage while low pass filtering?

• Try reading the data only when the PWM is in the ON condition. If the current sensor is being read by the same micro controller that generates the PWM, synchronising the current sensor read to the PWM ON should be possible. – AJN Jul 8 '20 at 5:26
• "I need continuous measurement without going to zero, to make fast feed back control loop". Once your readings are synchronised to read only when PWM is ON, It might not make sense to have a control loop operating at the same periodicity as the PWM. The control loop should run 5 or 10 times slower than the PWM frequency. – AJN Jul 8 '20 at 5:27
• Can you give more information about your PWM+load setup and what parameter exactly the control system is controlling. – AJN Jul 8 '20 at 5:30
• "how to avoid reducing of voltage?" What do you mean by that? The figure has a wave form which looks to be 3.5V peak and roughly 50% duty cycle. The output is expected to be around 1.7V. – AJN Jul 8 '20 at 5:31
• @AJN i am using esp32 to generate pwm 100Hz and uses inbuilt adc at 255 adc sampling cycles, how to synchronize these two? – kobi89 Jul 8 '20 at 5:42