Convert PWM to Analog out

A PWM output CAN be used to generate a 0-10VDC output suitable for controlling many devices, have done it many times for speed reference to AC Drives. You need to figure out the impedance of the device you are trying to control and then calculate the time constant [RC] of the circuit that is compatible with the PWM frequency. In most cases 2 resistors and a capacitor [$1 of components] is all that is needed.
Thanks for your help. I will get the impedence of the valve driver Monday. Has this been very reliable for you?
 
Ok

First, a RC filter can be simulated in software using the equation
vout=exp(-T/(R*C))*vout+(1-exp(-T/(R*C)))*vin
Were T is the period or update time.
I will choose a period of 10 milliseconds so T = 0.010 second
This means there will be 100 duty cycles per second. It looks like the T could be chosed to be one millisecond but I doubt the PLC part can update the counter that fast. Every 10 milliseconds looks like a good place to start.

To provide 10 bit resolution the PWM output must be able to change the duty cycles from 0/1024 to 1024/1024. In some cases the hardware my only allow 0/1024 to 1023/1024. So there are 100 cycles per second and each one is divided into 1024 parts so the frequency input to the counter is counter is 100*1024=102400

The counter can be programmed to provide pulse outputs. I have seen this done a couple of ways and it depends on the microcontroller used. In all ways I have seen there are two registers. The most common way I have seen the PWM implemented there is 1 register that controlled the on time and another that controllers the off time. The sum of the two registers must be equal to 1024. Hopefully the PLC software deal with this.

Ripple. How much does the volatage output change worse case?
If you look at the equation above and assume vout=0 and apply and apply a 10 volt input over 10 milliseconds then

vout(T)=vout(0)*(1-exp(-T/(R*C))*10volts
since
vout(0)=0 and vin=10
vout(T)=(1-exp(-T/(R*C))*vin
This can be approximated by
vout(T)=(T/RC*T)*vin(T)
If RC=0.1 seconds an T=0.01 the ripple will be approximately
vout(T)=(1-exp(-T/(R*C))*vin
or about 0.9 volts. That is a lot of ripple even if it is worse case. The ripple can be reduced by about a factor of 10 by making the PWM cyclee rate faster by a factor of 10 or making the RC time constant longer by a factor 10. Both solutions aren't very good. First, I doubt the PLC microcontroller can update the PWM registers every millisecond. You could be satified with just updating the counters whenever you can after a one millisecond period expired. Note, this also means you need to program the counter to have an input 10 time higher or about 1024000 counts per second. Second, increasing the time constant by a factor of 10 makes the RC time constant 1 second which is very long. It will take 5 time constants for the signal to reach within 1% of the 10 volt input signal. I asked this before, how quickly must the valve be able to respond? Since the 1 millisecond sample time is doubtful the only other practical option is to lengthen the time constant or just use the ripple as a dither.

About time constants. Calculating the time constant is easy. Just multiply the resistor valve by the capacitor value. For example, a 100K ohm resistor used with a 1 microfarad capacitor will provide a 0.1 second time constant. Another option is a 10K ohm resistor and a 10 microfard will do. The practical aspect of this is that capactitors in the microfard range are relatively large.
 
vout(T)=vout(0)*(1-exp(-T/(R*C))*10volts
since
vout(0)=0 and vin=10
vout(T)=(1-exp(-T/(R*C))*vin
This can be approximated by
vout(T)=(T/RC*T)*vin(T)
If RC=0.1 seconds an T=0.01 the ripple will be approximately
vout(T)=(1-exp(-T/(R*C))*vin
What the heck did you just say?
 
Thank you Peter for the detailed post.

If I choose the platform with PWM output (not for cost reasons) what information is necessary to build the R/C device? I am assuming the specifications of the valve driver as the analog output is the input for the valve driver. The reaction time of 10 milliseconds that you chose will be plenty fast. I will have this information Monday evening, will you then be able to help me with the math that was in your previous post?

Thanks for your time.
 
This comment is right on the mark!!!!

jlcann0n said:
I pity the people who have to maintain and trouble shoot this system.

That is just jlcann0n way of agreeing with my earlier comment...
From an engineering stand point I think it is a crime to try to save $100 and waste $2000 woking on a kludge solution unless this solution is going to be used many times so there is a pay back.
... that filtering a PWM is a kludge and that you should use a real analog output.

Kyle Grathwol, it would be unwise to implement a method that you don't fully understand. If you buy an Entertron PLC with real analog outputs then you will be using a PRODUCT that is off the shelf with DOCUMENTATION.
Another advantage would be tech support. Is Cubloc going to support your kludge? I doubt it. I think your changes are much better with Entertron support their analog output. The product doesn't necessarily need to be a Entertron but it does need to be a PRODUCT with DOCUMENTATION.

Does anybody disagree?
Anybody?
Kyle, if no one disagrees that should be significant.
I don't mind explaining the math but conclusion will always be the same.

One more thing. I am glad you think my comment was funny. You provided the opportunity that I couldn't pass up. Harsh, blunt, you bet. Sometimes you have to yell at some body to warn them about an impending disaster.
 
COTS (commercial off the shelf) is the way to go to minimize total cost of ownership: engineering, implementation, support, & maintenance.

I'd recommend the commercial approach that provides an analog output.

Dan
 
Thank you for your input everyone.
Sometimes you have to yell at some body to warn them about an impending disaster.
Thanks Peter for your concern for this project and that you don't want to see it fail.

I will post the details of the valve driver Monday evening. Hopefully Peter will help me with the math and Mr. Bits & Bytes can contribute his experience with using this device and I will then be able to decide if it is indeed "kludge" or a viable option for this application.
 

Similar Topics

Hello there, We're trying to build a prototype for a 3D food printer. The main control board for the printer sends out PWM signals. For...
Replies
19
Views
4,709
Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
112
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
374
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,534
Hello, could someone kindly convert the attached RSP files that are currently used for SLC 5 PLC into PDF please
Replies
6
Views
563
Back
Top Bottom