How to read a PWM value on an analog input ?

Hi,

I have an application that needs to read a PWM value from another PLC. In fact, as far as I understand, analag input are 8 bits analog that goes on a AD converter and PWM is somehow digital signals.

Can anyone help me with a way to smooth this PWM signal into a true analog signal. The PWM signal I should receive range from 0 to 3.2 V DC, I don’t need any opamp, just a filter to get a true analog signal I can use on a analog input on my Arduino.

Many thanks

Francois X.

A PWM signal is a digital signal that goes up and down rapidly. The ratio of up to down is set by the software and so it looks like a Pulse Width Modulated signal, hence the name. To turn this into an anlogue signal simply connect the output through a resistor (say 1K) to a capacitor (say 0.1uF) who’s other end is at earth. Playing about with these values will alter the amount of smoothing you have and hence how repeatable the reading will be from sample to sample with a constant PWM value.
On the Arduino the analogue input measures 10 bits of resolution so you will get a reading from 0 to 1023.
However, the Arduino reference is +5V so you wont get the full range feeding a 3v3 PWM signal into it.
Hope that helps

However, the Arduino reference is +5V so you wont get the full range feeding a 3v3 PWM signal into it.

You can, of course, connect the AREF pin to a 3.3v reference (ideally from the PLC, but Diecimila and similar boards provide a local one) and set the Arduino to use the external analog reference.

Or you could measure the PWM pulse width digitally. There are a number of sensors that provide their output using PWM and I expect you can find some suitable Arduino code using google. I would think pulseIn would be the most common method used but you could also do it using the input capture interrupt capability of Timer1.

If the signal is 3.2 volt switched PWM, it should be directly readable by an arduino digital port.

Note that if you do try to read it digitally, you might have to do something clever to detect the cases of 0% and 100% duty cycle, where there are no digital transitions at all. If you know the PWM frequency you can set a timeout that’s slightly longer than the period and if you haven’t detected any pulses you can use the state of the line to determine if it’s 0% (line is low) or 100% (line is high).

  • Ben

Hi,

As I understood, I need a resistor and a capacitor to smooth the PWM signal into a “quiet” full analog signal. Can anyone provide me with a schematic on how to do it. Do I need to set all in serial on the PWM signal wire ?

Many thanks

Francois X.