Why PWM?

Join Date
Apr 2002
Location
No income tax, no capital gains tax. Freedom!
Posts
8,389
I see PWM memtioned a lot when it comes to converting an analog output to a digital output. PWM takes timers and is resource hungry. Consider this:

Code:
AnalogOut = PID(error)     The PID calculates an analog control output value.

AnalogSum = AnalogSum + AnalogOut
if ( AnalogSum >= AnalogMax )
    AnalogSum = AnalogSum - AnalogMax
    DigitalOut = On
else
    DigitalOut = Off

AnalogMax is the maxiumum output plus one in output units which are usually counts. A 12 bit analog card would have a max value of 4096. This can be implented in just one rung on most PLCs and requires only one register for AnalogSum. Why not keep things simple?
 
I am not sure why you state PWM is resource hungry, please explain.

Its my understanding that many controllers have PWM embedded into the system which makes it easier to use. You also dont have to pay extra for analog/precision devices which could mean a major financial savings. Allowing for bandwidth any analog signal can be created with PWM.

Isnt it also true that analog can have noise issues? PWM should be immune to noise issues overall.

The way I understand it is, its available, its cheaper, saves space, noise immune and overall should be just as easy to use....depending on the controller and what you are doing.

When I was in TN I setup several brands of PLC for PWM to test Bergher Lahr stepper motors from a flexographic press. This thing had over 50 of them and they constantly gave problems so I needed a test bench. PWM allowed me to do this easily.
 
The output time base (measured rising edge to rising edge) varies in your algorithm (a shorter time base the closer the output is to 50%) whereas in standard PWM the time base remains constant and only the on duration changes.
 
?????

Ron, I was not debating the analog/digital issue, just the means by which the analog gets converted to digital on/off signals using a PLC.
On a PLC the PWM requires a special block or timers. On a servo motor there is a gate array or special timer/counters on the CPU itself that takes care of converting the analog value to on/off signals. I was thinking more about these threads where someone is controlling temperature and they think they need to convert the signal to PWM when a simpler method will do.

Bernie, yes the time for rising edge to rising edge does vary. Why does it matter? With both methods the percentage of the time the output is on is the same given the same input.
I dont understand what you meant here...
(a shorter time base the closer the output is to 50%)
 
I believe there are some devices on the receiving end which want the ON pulses spaced a consistent distance apart with only the ON time varying. It's been a while since I've worked with PWM based devices (mainly heaters) so I can't say which. If you can't think of any then I guess it's a moot point. It's interesting how, from 0 to 50% of full it looks like the output will be single ON pulses spaced closer and closer together. Then from there to 100% the ONs will get longer and longer with single OFF pulses seperating them. At least that's what it looks like in my mental running of a system.
 
I know how the output would work.

bernie_carlton said:
I believe there are some devices on the receiving end which want the ON pulses spaced a consistent distance apart with only the ON time varying.

I don't know of any. If there were then the Sliding Mode Control wouldn't work either.

bernie_carlton said:
It's been a while since I've worked with PWM based devices (mainly heaters) so I can't say which. If you can't think of any then I guess it's a moot point.

Certainly a heater doesn't care. A mechanical relay would not like to switch too often but who uses those in these applications?


bernie_carlton said:

It's interesting how, from 0 to 50% of full it looks like the output will be single ON pulses spaced closer and closer together. Then from there to 100% the ONs will get longer and longer with single OFF pulses seperating them. At least that's what it looks like in my mental running of a system.

Almost right. What the output would look like using an Excel simualtion.

I used the PID gains that one of the posts provided from last week.
 
Code for PWM - duty cycle variation

Peter, have classification PWM? Talk, more precision you code (first post) adequate for relay, to transitors other code modulate duty cycle and more level PWM modulate period wave. What the codes?
 
Re: Code for PWM - duty cycle variation

dandrade said:
Peter, have classification PWM?

Are asking if there is a name for this duty cycle varition method?
I don't know know of any name for this method. Duty cycle variation is good.

dandrade said:
Talk, more precision you code (first post) adequate for relay, to transitors other code modulate duty cycle and more level PWM modulate period wave.

Neither method is more precise than the other, BUT most people do not keep track of any remainders after converting the analog output to a digital number when using PWM. If I converted the spread sheet to use PWM then I would need 10 times more rows just to change the time period from .01 seconds to .001 seconds. This would only provide PWM output levels in increments of 10% which is still pretty coarse. If the output level is 85% the the output should be on 80% one cycle and 90% the next cycle.

dandrade said:
What the codes?

Eu não compreendo.
 
I wasnt debating, you asked why and I stated my understanding of why.

I can not relate to the spread sheet issue because I dont know or understand the relativity.

What I do understand is that many things are application specific. My stepper motor test bench being an example. I had Bergher-Lahr (now part of Scheider) stepper motors with a controller. The controller could use a PWM signal to allow me to control the motor, it wouldnt use an analog signal.

I "assume" that PWM is an economical method (when applicable) to develop a signal simialar to analog that is possibly more efficient in energy use.

I am not sure about the resource aspect, yes it uses timers which use registers but analog devices also require the use of register(s) and cpu time to process...doesnt it? If you could control using PWM and had no need to purchase extra analog devices or A/D converters wouldn't that make up for the possibility of added code or resource usage?

I know the MicroLogix 1200 and 1500 have a PWM instruction/function file. I have used it once and was simple enough to setup.

I didnt think about it till now but remember my L-sealer project? I used a flip flop timer arrangement to control pulsing the heat/cut wire to maintain the wire temp if idle for extended periods. I guess that could be considered PWM since I was controlling the duty cycle.I believe I used 2 timers and 3 lines of code.

I dont grasp alot about PID that maybe I should or maybe because I havent gotten to work with enough. PWM to me is simple to understand.b

Basically I have used PWM when analog wasnt available and PWM was. I still think it would be application specific which to use especially since you state either is as efficient as the other.
 
Missing the point.

rsdoran said:
I can not relate to the spread sheet issue because I dont know or understand the relativity.

It shows how varying the duty cycle is good enough. The extra effort of doing a PWM is seldon required.

Originally posted by rsdoran
I "assume" that PWM is an economical method (when applicable) to develop a signal simialar to analog that is possibly more efficient in energy use.

You "assume" correctly, but so is just varying the duty cycle.

Originally posted by rsdoran
I am not sure about the resource aspect, yes it uses timers which use registers but analog devices also require the use of register(s) and cpu time to process...doesnt it? If you could control using PWM and had no need to purchase extra analog devices or A/D converters wouldn't that make up for the possibility of added code or resource usage?

I think you are missing the point. Bernie correctly pointed out that the time between the rising edges is constant using PWM. What I proposed does not require a constant time between the rising edges, but it still converts analog value to a on/off signal and keeps the duty cycle the same.

Originally posted by rsdoran
I know the MicroLogix 1200 and 1500 have a PWM instruction/function file. I have used it once and was simple enough to setup.

Yes, but what if the PLC doesn't have that instruction. Also, that PWM still uses resources.

Originally posted by rsdoran
I dont grasp alot about PID that maybe I should or maybe because I havent gotten to work with enough. PWM to me is simple to understand.b

I know you have been busy, but you should look at all those spread sheets I have posted. Just search for PID. Each week a new spread sheet resprenting a different type of system has been posted. Read the comments and experiment with the spread sheets. Then you will be able to relate to the spread sheets.
 
What the codes?
Talk
Codes for PWM:
1) Code of Peter - First post.

2.a)For short Time (high frequency)
Ladder -Calculus value PWM Out
Subroutine Timmer constant /*interrupt timmer*/
IF(PWM Out > counter) {
Output=ON
else
Output=OFF
}
counter=counter+1 /*Counter acumulative time*/
IF(counter==Max) /*Max=value representtive 100% time*/
counter=0
return subroutine

2.a) For low frequency - Timmers in ladder

3) Knows this here!? (Image bottom)
Frequency = cycles of the systems (the real oscillation)
SP = Setpoint
Streak of output=0%-50%

The author writed, applied in the control of temperature of close pack(packing) of products sizes varied.It affirmed, method operated stabilized in Open Loop.

PWM with senoidal modulate - The name went, inserted in a monograph. Already it researches, a lot but did not find official literature. He knows the real name of this technique? He knows as he obtain the model simplified?

pwm.gif
 
Dandrade, I still don't understand you.

The switching frequency must be faster than the system response. In the case of the spreadsheet the switching calculation is done every .01 seconds and the fastest time constant is .1 seconds.
Download the spread sheet whose link can be found in my third post and see.

I looked around and this technique is called a "time proportional" output.
 
Last edited:
Very good is simple name. No have EXCEL, no possible view you files.Ok, understand is frequency samples and frequency output.Tranks
 
originally posted by Peter Nachtway
I looked around and this technique is called a "time proportional" output.

Not to add confusion to this, but I looked up some of the 'time proportional output' references I have see in the past and all of them talk about a timebase value. Basically it seems to say that 'time proportional output' is a slow, software version of PWM. The PWM references I come across seem to infer a hardware implementation.

That being said, I like Peter's alternative. It's simple and compact compared to 'software PWM'. It also seems to automatically trade response for resolution without any extra effort. Like Peter said, I think standard 'software PWM' would do this too, as long as you save the time overrun from cycle to cycle.

Keith
 

Similar Topics

Good morning! I'm trying to find a DIN rail-mountable 4-0channel PWM amplifier that is capable of accepting a 5VDC PWM with a maximum frequency...
Replies
2
Views
108
I have a project to control the speed of motor DC using PWM Output on PLC and when im on working i have a several trouble and of of them is the...
Replies
6
Views
213
Hi All, I came up with this for ramping the PWM pin on the micro 820. I'm new to ladder logic so I am not sure if this will even work? Once...
Replies
6
Views
349
Hi, I am trying to have my PLC start a heating fan in a linear manner. A certain percentage at a certain received setpoint. To do this, I use a...
Replies
8
Views
1,583
Hi guys, i have never had to do a PWM Output or input before i have a Device that to dimm the lamp output from the ballast, the ballast has a 24V...
Replies
6
Views
1,048
Back
Top Bottom