Everything2
Near Matches
Ignore Exact
Full Text
Everything2

pulse width modulation

created by JeffMagnus

(idea) by bonnet (5.2 y) (print)   ?   (I like it!) Thu Apr 06 2000 at 18:48:21

Pulse Width Modulation
Technique used in motor speed control, lighting, sound generation, and servo positioning.

Since getting analog voltages out of a binary device requires extra hardware, sometimes just sending out a stream of pulses with the percentage of on-time correct will work.
For example, to get an output voltage of 3 volts from a pin that can be either at 0 or 5 volts, having the pin at 5 volts 60% of the time (plus a filter capacitor) gets you close to 3V.

For all the elegance and thrift of this approach, there is a lot of processor overhead in deciding exactly when to switch while doing other tasks. Some microcontrollers have special hardware to do PWM in the background.


(idea) by bitter_engineer (6.5 y) (print)   ?   (I like it!) Sat May 27 2000 at 1:22:22

A simple way to do pulse width modulation at about 1kHz on a 10MHz chip: It requires one Output compare interrupt for each output, and one timer interrupt to act as the sync pulse. It is used like so:
  1. For each output, keep an integer static variable to reflect the duty cycle. It should be equal to (100-%output)*100.
  2. Set your sync interrupt to activate every 10,000 cycles.
  3. Every time your sync interrupt activates, set all outputs low, unless an input's static varialble is equal to zero.
  4. For each output, set its timer for its static variable, unless the value is equal to 10,000, in which case don't set it.
  5. The result should be a square wave for each output with a base frequency of 1kHz.
There are a few problems with this system. First of all, interrupts may be at a premium on your microcontroller, and you may want to use some more math to try to schedule all your outputs and sync off of one interrupt. Second of all, in this case, all outputs are turned off at the same time. If several outputs control electric motors, you should be prepared for a nasty voltage spike. YMMV.

If you are designing a system that will be used around humans, then the frequency of your pulse should also be taken into consideration. Pulse width modulation at 1kHz will cause an annoying 1kHz whine when it is used to drive an electric motor, even with the filter capacitor. This is why I have my doubts about bonnet's assertion that it can be used in sound generation. Even driving a system above 20 kHz is bound to produce some overtones in the audible spectrum. If minimizing annoyance is an issue, you may want to scrap the PWM scheme and just shell out the extra bucks for a D/A converter.


printable version
chaos

PWM bang-bang control Digital to Analog Converter PCM
Roland SH-09 electromagnetic pulse gun Korg Mono/Poly Sequential Circuits Multi-Trak
Roland Juno-6 Moog Source Game Boy Player Roland Jupiter-8
Korg Trident mk II Moog MiniMoog ARP Solus servomotor
sawtooth Modulation music concrete phase offset modulation
Akai AX80 Oberheim OB-8 Oberheim Synthesizer Expander Module Oberheim OB-1
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Just another sprinkling of indeterminacy
In his autumn before the winter comes man's last mad surge of youth
Sunset Boulevard
The threat of freedom
I signed up for the carpool for all the wrong reasons and now I'm bitter as Hell
The Truth Behind Doritos Flavors
Japanese education
learning to juggle
Gone in Sixty Seconds 2006 - Theatre Quest Entries
If we could build things out of concepts, I'd have pants made of lust
Les Fleurs du Mal
Stormy Weather
Active Denial System
Pioneer 10
New Writeups
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
calgon
Buffalo Bill by the pool(poetry)
gate
Anarchy is Order(idea)
ushdfgakjasgh
Scribeling(thing)
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
antigravpussy
your warm whispers(personal)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Everything 2 is brought to you by the letter C and The Everything Development Company