PWM to "true" analog

I need to send an analog signal from a Nano to a device that will not support a (PWM) based analog input (confirmed with manufacturer) it requires a “true” 0-5v signal.

The manufacturer has recommended this converter. I bet you can guess why I am not keen on it.

I have found this converter.

Does anyone have experience with something similar?

1 Like

Hi Adam,

Would it be possible to get some specifics around your project?
What module are you integrating this with, what range and response speed do you need for the analog Singal, resolution ect

Hi Adam
Technical information here

or Google "PWM to analog converter circuit for much more.
Cheers Bob

1 Like

Hi Adam
Just re read your post. You must have a DC voltage to produce that PWM signal in the first place. Why not just use that DC signal instead of going to the trouble of converting an analog signal to PWM and back again.
Cheers Bob

1 Like

Thanks @Robert93820 & @Liam120347
Range is 0-5vdc response time does not need to be fast at all to an extent the slower the better to be honest as the sensor is very sensitive (0-1psi differential).
The function I am trying to achieve and have except for the Analog output is-
I am reading a differential pressure sensor (0-5vdc analog) with an Arduino Nano, the Nano outputs the sensor value to a 4 digit 7seg display and also outputs the sensor value via the PWM output to the device that requires the signal (this part is not important except that it requires the DC analog signal). I also have the ability in the Nano to override the PWM output and displayed value using a potentiometer. This override function is required for calibration purposes.

I think Roberts article may be what Im after.

Hi Adam
I don’t see why you could not connect the sensor output to your Nano, which as you say is used to drive a display, AND the other device. The analog input to the Nano should be very high, the other device is unknown. If loading is a concern you could isolate by using 2 OP amps connected as a voltage follower, that is connect your source to the non inverting input of both OP amps and connect the output directly back to the inverting input. This will give you 2 low impedance sources to drive your Nano and the other device. The OP amps will have to be “rail to rail” types. OP amps connected in this manner have a very high input impedance.

A good choice here would be a LMC6482AIN which is a dual unit (8 pins) and pretty versatile with a VCC of 2 to 16V. The down side to this is even though the device is “rail to rail” this is never the case. They will still only go to about 0.1V of the rails. This means a swing between 0.1V and 4.9V (for a 5V VCC). The output will accurately track the input between these 2 values. Using this method if 0V and 5V are absolutely essential you have to have the OP amps powered between slight negative voltage (say -2V) and slightly more than 5V (6V?).

This could be a bit simpler than trying to filter the PWM as using a simple RC filter you are going to have ripple, how much depends on the actual values of R and C chosen. If you need a “clean” DC voltage you will have to be a bit more exotic. I am not familiar with the Nano but if the PWM is the same as other Arduino the PWM is in 255 steps anyway, it is not a continuous variation.

Cheers Bob
PS: Due to high impedances involved you should use very short wire lengths. The OP amp approach if used could have the OP amps close to the sensor and because the output impedance is low the wire lengths can be dramatically increased to your other devices.

3 Likes

Thanks mate but you are going to have to dumb this down for me a bit.
here is the simulation of what I have mocked up on the bench - DP calibrator Copy - Wokwi Arduino and ESP32 Simulator

Everything is working well, I just need to get that PWM analog out (pin3) converted to a nice smooth 0-5v analog signal.

It just so happened I was in Jaycar when I got your message so I picked up one of those LMC6482AIN but after reading the data sheet I have no idea how to connect it in. And full disclosure I have a very limited understanding of electronics and is Dr google that has got me this far.

Hey Adam,

We all had to start somewhere with this hobby, glad to see you are getting some pretty top notch advice for this project!

For converting your PWM signal to an analog signal, I would suggest looking into a Low Pass Filter to get it smoothed out, here’s a great guide as to how they function and a few calculators to get you on your way with making one.

Cheers,
Blayden

Hi Adam
You seem to now have 2 sensors. If that had been known in the first place I would not have wasted my time and your money considering OP amps. Thought you said you had 1 sensor measuring pressure difference. Not 2 sensors and measuring the difference between them.

Your sketch. You have 2 “inPin”, I believe these should be labelled A0 and A1 or they would be mistaken as digital 0 and 1. Your declaration of “outPin” as 3 would be the digital 3 you have labelled as VCC. This is a PWM pin and I assume this is what you need to convert to DC. Why label it VCC, that is normally the label attached to the supply for ICs etc. You should not use an Arduino pin for that. You later declare A3 as an output, that is OK and helped separate this pin from “outPin” (you use 2 pin3s).

Filtering PWM. That article linked explains this in fairly easy terms but he failed to mention one very important thing regarding the formulae. He did not tell you that ALL bits of the formula are expressed in their native values, like:
Frequency is Hz
Resistance is Ohm (Ω) Circuit reference usually R
Capacitance is Farad (F) Circuit reference usually C
Inductance is Henry (H) Circuit reference usually L

so 1kHz is 1000 Hz
10kOhm (10k) is 10000 Ohm
10 microFarad (µF) is 0.000,010 Farad
10 nanofarad (nF) is 0.000,000,010 Farad
and 1milliHenry (mH) is 0.001 Henry
and so on. If you change 1 multiplier you have to change ALL to the same multiplier that is Hz (single unit), kilo (K = X 1000), milli(m = divide by 1,000), micro (µ = divide by 1,000,000), nano ( n = divide by 1,000,000,000).
Failing to be aware of this would result in an error of several zeros either way.

Read and absorb that linked article. If you need ripple free result you will probably need the RC filter followed by a LR. But filtering PWM will not be smooth. 0 to 5V would be in 255 steps of 19.6mV or 0.0196V. If you can tolerate this fine, otherwise plan B.
Cheers Bob

There’s not 2 sensors. There’s the pressure sensor and there’s the potentiometer for calibration that was described above. The ‘differential’ referred to in the original clarification is the difference between the pot setting and the sensor reading, calculated by the MCU. That’s why the value to be sent to that external device is only ever available as a PWM signal. The low pass filter should work well, because it appears that the slow settling time isn’t going to matter.

Hi Jeff
If you open Adam’s link you will see he has pictured 2 sensors connected to 2 different Arduino inputs. A0 and A1. Plus another fixed 5V via a 1k resistor on A5 which I presume is this overriding switch.
It would be nice to get an accurate diagram of how everything works, like where does “VCC” go.
Cheers Bob

VCC is the PWM output to the external device. It’s not connected to anything because that’s where OP needs to add whatever device is going to create the “true” 0-5v signal.

1 Like

Hi Jeff
That is somewhat obvious But I am used to working in black and white, not in a situation where almost everything has to be guessed. I was just pointing out that I think “VCC” might have been a strange terminology for that function.

If you got that far I think you would agree that Adam has depicted 2 sensors in that diagram but his initial statement indicated 1 differential device

Tell me that does not indicate 1 device. I have worked on equipment which used such sensors to detect cooling fan failure in a transmitter by measuring the pressure differential (or in this case the lack of) across the final PA valve. 1 sensor.
Cheers Bob

It does. And " I also have the ability in the Nano to override the PWM output and displayed value using a potentiometer." indicates the other.

@Jeff105671 @Robert93820
OK I am to blame for some of this confusion.

  1. I have limited options in that simulator so the POT to the right of the board represents this DP sensor The second pot and switch at the bottom is the override control.
  2. For the VCC label, again I am limited by the simulator, I cannot add a wire without attaching it to something I thought VCC best represented the analog out.

there are also a couple of items that I have on the bench set up that are not in the simulator including some resistors for the segment display and 2 capacitors for the DP sensor (as per its data sheet)
And just so we are clear I am happy the function of everything except the analog output.

Blayden thanks for that link still working on getting my head around it. For reference according to the spec sheet the Audrino board PWM output is 490Hz on pin 3.
What cutoff frequency am i looking for?? Am i going for a How do I know if I want an RC or RL filter??

Hi Jeff
Adam has either got 2 sensors or 2 potentiometers in that diagram. Not one of each. They both look the same to me. You could well be correct. If you analysed that sketch it might yield some more answers but I am not going to do that.

Possible he is simulating the sensor with a potentiometer so why not label the sketch to indicate 2 pots instead of some picture which could be pots but equally could be sensors

Like I said. Get a bit tired of guessing. Have put in my 2 bobs worth.
Cheers Bob

@Robert93820 & @Jeff105671

Sorry for the confusion guys.

I am somewhat limited in the simulator.

  1. I cannot add label is it that I am aware of.
  2. There is no pressure sensor available so the pot to the right of the board represents this DP Sensor
  3. The pot and switch to the bottom represent the override function.
  4. pin3 - VCC represents the analog output, I could not put a wire in without attaching it to something from all the options I had I thought the VCC represented this the best.

As I said earlier I am pretty happy with the function of everything except the Analog output.

I have read both articles on bypass filtering that have been posted but am still at a bit of a loss to what I need.

The device I am connecting to is designed to interface with any 0-5vdc analog signal directly from a sensor. I have no other information on it that is why I reach out to the manufacture who told me
“Adam,
We have to have a 0 to 5 volt analog signal, nothing frequency based will work without some type of converter like this one.”

Hi Guys not sure what going on but when I post anything more than a short sentence its getting flagged as spam and needs review by an admin??

Hi Adam
Might be why I can see “A Replying” flashing up but nothing happens. You might have to contact Core direct. I can’t see why that would happen.
Cheers Bob

3rd time lucky?

I am limited by the options in the simulator.

  1. I cannot add labels that I am aware of (I did try)
  2. No suitable sensor was available to represent the DP sensor I am using. The pot to the right of the board represents the DP sensor. The Pot and switch to the bottom represent the override functions.
  3. Pin3 analog out - I cannot add a wire without connecting it to something, I thought VCC represented this the best.

As I said earlier, I am fairly happy with the function of everything except the PWM Analog out.

There is very limited information on the device I am connecting the analog to that is why I reach out to the manufacture who’s exact words were “We have to have a 0 to 5 volt analog signal, nothing frequency based will work without some type of converter like this one.” I can tell you that it is designed to connect directly to 0-5vdc analog output sensors.