# Arduino Forum

## Topics => Science and Measurement => Topic started by: tuxstef on Jul 18, 2012, 05:52 am

Title: PWM shunt current measurement
Post by: tuxstef on Jul 18, 2012, 05:52 am
Hello,

How do you get the right time if pwm is used for measuring a shunt voltage? I won't use some electronic circuits except the voltage gain amplifier to scale from e.g. 0-20 mV to 0-4V.
Is there a function to call to get the pwm pin is just now high?

Please help!

Yours, Stefan
Title: Re: PWM shunt current measurement
Post by: winner10920 on Jul 18, 2012, 07:14 pm
You could add a capacitor to smooth out the voltage on the shunt, although it may also affect the voltage reading,
Or take many reading fast and find the ones that count, mind you may also want adjust in software that the duty cycle varies so the avg current is different than at the instant its on
or add a capacitor and or inductor to the output to smooth the voltage and keep the current constant
Title: Re: PWM shunt current measurement
Post by: tuxstef on Jul 18, 2012, 08:13 pm
Thanks to winner10920 !

But this question is unanswered.

Quote
Is there a function to call to get the pwm pin is just now high?

Please help
Title: Re: PWM shunt current measurement
Post by: CarlosAlbertoEstrada on Jul 22, 2012, 06:24 am

Hello there,

1. Remember V=IR
2. If you have a signal 4-20mA coming, add a 250Ohms in parallel to have an equivalent of 1-5VDC (perrrrfect for arduino analog input)
3. If you 0-20mA, you have to use (1) to find the shunt to have a proportional Voltage acceptable for Arduino analog inputs
4. Forget any capacitor or any amplifier...

Hope this helps
Title: Re: PWM shunt current measurement
Post by: tuxstef on Jul 22, 2012, 07:01 am
Hello,

I want to ask new, because the main question could be confusing.

The situation:

There's a pwm driven Motor. On the high side current is measured with a shunt and the corresponding voltage is amplified with an opamp circuit to 0,2 - 4V. This voltage goes to the ain input of the arduino.

So, you know that pwm current isn't smooth so the simplest measurement method is to measure at the right time -> if the digital port of the pwm driver is high.

Now my question again:

Is there a function (or any way) to call to find out that the digital port (pwm driven) is just now high?

Also I could take some true rms ics like the AD636. I won't need it because I don't need any absolute measurements here.

The 3rd method would be to measure like the ad636:

Vrms = (Avg * ( Vin^2) )^(1/2)

Any code suggestions?

Thanks!