I am working on an amplifier design, and I was thinking about using a
class D,G,or H design. Could someone please give me a hint on how to
implement the pulse width modulation that is necessary for these
topologies? I was thinking that I could just use a sample and hold
device off the output and compare that value with the current input at set
intervals. Is this how PWM works, or is it more complicated?
Just so I'm not chastised for asking this question...there is a PIC
|> From: Stuart Allman <HALCYON.COM> studio
> I am working on an amplifier design, and I was thinking about using a
> class D,G,or H design. Could someone please give me a hint on how to
> implement the pulse width modulation that is necessary for these
> topologies? I was thinking that I could just use a sample and hold
> device off the output and compare that value with the current input at set
> intervals. Is this how PWM works, or is it more complicated?
> Just so I'm not chastised for asking this question...there is a PIC
For the benefit of us all, perhaps you could give a brief exposition of
what classes D, G and H are (my education stopped at A, B, C). Anyhow,
PWM as applied to audio is a digital-to-analogue technique. If you
have an output which can only take one of 2 values (say 0 and +5V) then
you can create a low bandwidth DAC by switching between the 2 output
values at a frequency much greater than the audio frequency of
interest. The analogue output range is precisely 0-5V. To obtain a
value of, say, 1V then the digital output should be low 4/5 of the time
and high 1/5 of the time. The digital output should be switched at a
rate of, say, 44KHz and fed into a 20KHz low pass filter (the
brick-wall type used in CD players etc.)
There's no need for a SH or comparator if you are talking about PWM
pure and simple. However, since you want to convert an analogue input
into a PWM output yes you do need a comparator and a sawtooth
generator. The SH would be better replaced by an input bandwidth
limiter. A PWM output is obtained from the comparator by feeding the
sawtooth into the inverting input and the analogue signal into the
As a matter of interest, the PIC16C73/4 contains a 10-bit resolution
PWM output. Supposing you run it at top speed, 20MHz, then over 2**10
= 1024 clock cycles, you can adjust the output duty cycle over every
fraction (0..1024)/1024. The output frequency will be 20MHz/1024 =
19.53125KHz. You can trade off output precision vs output frequency
e.g. 8-bit precision at 78.125KHz.
Not exactly CD quality, but not too bad for telecom applications. I
have successfully made a PIC-powered tone generator by feeding the PIC
PWM output directly into a 1K:8ohm transformer with the 8ohm side
connected to a mini speaker. It's quite loud, and has the advantage of
zero power usage when off, unlike most amps which have a substantial
On Mon, 14 Jul 1997 08:59:25 -0400 Andy Kunz <FAST.NET> writes: montana
>Try using a PIC with PWM module(s).
Which reminds me... I've had good luck with the PWM modules
inside a 16c74a. It would be useful if I could find a single chip with a
bunch (maybe a dozen) of these in it with serial control (ideally with a
serial out so the data can be looped into more PWM controllers). I'd
like to be able to send a number into each of these PWM circuits and get
a pulse whose width is proportional to the number. Most PWM stuff I've
seen has been single channel and pretty much an analog circuit (PWM out
proportional to analog input). Any digital PWM peripherals out there?
At 02:23 PM 7/14/97 EDT, you wrote:
>bunch (maybe a dozen) of these in it with serial control (ideally with a
>serial out so the data can be looped into more PWM controllers). I'd
>like to be able to send a number into each of these PWM circuits and get
>a pulse whose width is proportional to the number. Most PWM stuff I've
>seen has been single channel and pretty much an analog circuit (PWM out
>proportional to analog input). Any digital PWM peripherals out there?
My generic robotic controller does this, sort of. It accepts commands via
RS-232 or 485 (or R/C PWM, depending upon software configuration). It
outputs R/C PWM to up to 16 channels, each channel gets a 2mS slot with
data up to 2mS wide, on a rotating basis. If you use a serial input, the
two PWMs through the 16 channels at the same time (one PWM module runs 8
channels, the other runs the other 8) for a complete refresh to each
channel every 16mS. If you go with a R/C PWM input, the signal cycles
Now if you're looking for real PWM like to generate an analog signal, I
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
Hardware & Software for Industry & R/C Hobbies
"Go fast, turn right, and keep the wet side down!"
|On Mon, 14 Jul 1997 14:23:44 EDT Harold Hallikainen
<JUNO.COM> writes: haroldhallikainen
>On Mon, 14 Jul 1997 08:59:25 -0400 Andy Kunz <FAST.NET> montana
>>Try using a PIC with PWM module(s).
> Which reminds me... I've had good luck with the PWM modules
>inside a 16c74a. It would be useful if I could find a single chip
>with a bunch (maybe a dozen) of these in it with serial control
>(ideally with a serial out so the data can be looped into more PWM
>controllers). I'd like to be able to send a number into each of these
>PWM circuits and get a pulse whose width is proportional to the
>number. Most PWM stuff I've seen has been single channel and pretty
>much an analog circuit (PWM out proportional to analog input). Any
>digital PWM peripherals out there?
There used to be chips with 4 or so channels of 6-bit PWM for TV remote
control application. Nowdays this function is done in a microcontroller
optimized for TV control, either with software or built in DAC hardware.
So these may not be available anymore.
Although not a single chip, one way to get several channels of
high-resolution digital PWM is with a bunch of plain old ripple counter
chips like 74HC4040. One counter is the master and is never reset. The
master could be one of the counters in the PIC. Each channel of PWM
output has a counter dedicated to it. All the counters are clocked from
the same source. Now for the trick. The MSB of each counter is
connected to an xor gate with the MSB of the master counter (the other
counter outputs aren't used). If the count in a channel counter is in
phase with the master count, the MSB is always the same, and the output
of the xor gate is always zero. If the counters are out of phase, two
pulses per counting cycle are output. The width of these pulses
increases until the counts are completely out of phase (one counter is at
10000000 when the other is at 00000000) at which point they merge. To
set the pulse width, the PIC needs to apply a reset pulse to the channel
counter at the proper time (based on the count in the master counter).
Once set up, the counters will operate in lockstep indefinitely so
attention of the processor is needed only when the pulse width is to be
changed. The output frequency of this setup is twice the overflow rate
of the counters and the resolution is half the maximum count. A
general-purpose counter timer chip like the old 82C54 could also be used
in a phasing scheme like this.
Another method would be to use a one channel on chip PWM then demultiplex
it into several outputs. As one of the RC experts already pointed out,
this works well for RC servos which only need a duty cycle of 5 to 10%
(since they were intended to work with multiplexed data over radio). If
you're using the PWMs for analog outputs, the gain could be increased to
compnesate for the limited duty cycle of the demultiplexed output. If
you need a pulse from 0 to 100% duty cycle this could be accomodated with
an analog pulse stretcher driven by the low duty cycle pulses. A pulse
stretcher has a capacitor that charges rapidly during the input pulse and
discharges slowly during the output pulse. The output pulse comes from a
latch which is set by the input pulse and reset when the capacitor
reaches zero again. The ratio of charging to discharging current sets
the stretching factor so it is not going to be absolutely precise, but
fine for things like motor control where it is inside another feedback
loop anyway. This is how RC servos control the motor internally.
|On Mon, 14 Jul 1997 16:28:54 -0400 Andy Kunz <FAST.NET> writes: montana
>At 02:23 PM 7/14/97 EDT, you wrote:
>>bunch (maybe a dozen) of these in it with serial control (ideally with
>>serial out so the data can be looped into more PWM controllers). I'd
>>like to be able to send a number into each of these PWM circuits and
>>a pulse whose width is proportional to the number. Most PWM stuff I've
>>seen has been single channel and pretty much an analog circuit (PWM out
>>proportional to analog input). Any digital PWM peripherals out there?
>My generic robotic controller does this, sort of. It accepts commands
>RS-232 or 485 (or R/C PWM, depending upon software configuration). It
>outputs R/C PWM to up to 16 channels, each channel gets a 2mS slot with
>data up to 2mS wide, on a rotating basis. If you use a serial input,
>two PWMs through the 16 channels at the same time (one PWM module runs 8
>channels, the other runs the other 8) for a complete refresh to each
>channel every 16mS. If you go with a R/C PWM input, the signal cycles
I did something like this to decode DMX512 (a lighting control
protocol) out to analog. Set up a single PWM channel in a 16c74a to
output 20 pulses of appropriate width (proportional to the analog out for
that channel) through a resistor through a 4051 demux to a capacitor to
ground. The single series resistor and all the capacitors to ground on
the 4051 outputs formed a conbination low pass filter and sample/hold.
When the demux was on another channel, the capacitor holds the last
voltage it was at due to the LPF of the PWM. This is followed by a
non-inverting amp to provide gain and a low output resistance.
So... did something like your controller already (it's been in
production for a few months now).
The PWM controller I'm looking for would ideally give me 12 to 16
channels of continuous PWM at 20 to 50 KHz. I want to do 12 to 16
channels of digitally controlled buck (as opposed to boost) voltage
control. Any digital peripheral chips like that out there?
|Harold Hallikainen wrote:
> On Mon, 14 Jul 1997 08:59:25 -0400 Andy Kunz <FAST.NET> writes: montana
> >Try using a PIC with PWM module(s).
> Which reminds me... I've had good luck with the PWM modules
> inside a 16c74a. It would be useful if I could find a single chip with a
> bunch (maybe a dozen) of these in it with serial control (ideally with a
> serial out so the data can be looped into more PWM controllers). I'd
> like to be able to send a number into each of these PWM circuits and get
> a pulse whose width is proportional to the number. Most PWM stuff I've
> seen has been single channel and pretty much an analog circuit (PWM out
> proportional to analog input). Any digital PWM peripherals out there?
The TDA8444 should work for you. Its an octuple DAC wit I2C control.
Tjaart van der Walt
| Another sun-deprived R&D Engineer slaving away in a dungeon |
| WASP International http://wasp.co.za |
| GSM and GPS value-added applications |
| Voice : +27-(0)11-622-8686 | Fax : +27-(0)11-622-8973 |
Is the PIC16F84 capible of producing Pulse Width Modulation? I'd like to
make a incandescent lamp dimmer utilizing this technique. (Although maybe
it would be better to utilize a zero crossing detector circuit and the
related triac dimming circuits.) If it is, how many PWM's can it output at
once? If not, what's a better PIC to use for this type of application?
Any PIC is great for this. If you're using DC it's simpler though that
probably won't serve your needs. I'll illustrate using an 8 bit counter.
Figure out a delay constant you can call 256 times that totals just a little
less that 1/120th of a second. Set your duty cycle output to on and start
counting to 256 every time there is a zero crossing detected. Each time you
increment the counter, compare it to your duty cycle constant. When the two
numbers are equal reset the duty cycle output. This has the effect of moving
one edge with respect to the stationary zero crossing edge as a function of
the duty cycle constant's magnitude. Use that output to trigger the triac.
There is a single chip solid state relay that could drive the lamp available
from Radio Shace for about $7.00. The zreo crossing detector I have built
from an op amp. Circuits for this application are numerous.
Shine Brightly..... or not
part 0 16 bytes
part 0 16 bytes
|(You asked twice, just so you know.) I'm too zonked to read assembler
at this late hour, if no-one else looks at it, I'll take a look in the
AM. I assume Watchdog Timer's disabled, and the PIC is not resetting
for any other reason like power brownouts, right?
Also, more code might be needed for some to figure out the problem, if
you have a web page you can drop it onto, you might do that & let people
who ask, know that it's available there. Being able to see ALL the
code, can be a real help to some people - like me <G>
Another suggestion is to use Equates & Defines & so on to make sure you
don't have problems with moving pins around later (i.e. you might
consider using defines like these: )
#define Pin100Percent PortD,4
#define Pin075Percent PortD,5
#define Pin050Percent PortD,6
#define Pin025Percent PortD,7
The advantage of these is that, if & when you move a wire to a different
port, you have just one *master* that you need to change, not 15
different places throughout the code where you need to make
modifications, so things are lots easier when you have a bug.
Your code would then look like:
BTFSC Pin100Percent ;SCAN STATUS OF ...
- which is pretty clear, and lots easier to maintain when you re-use the
code 4 months down the line, for another project <G>
Thomas C. Sefranek
part 0 5692 bytes
What part are you using?
I use PWM for my power supply designs using a 16C62A.
With that part PWM is very straight forward.
(Load the period register, load the pulse width register...)
everyone... Sorry got
a question to ask again... I
am now doing a SIMPLE project and I have encounter some small little problem
. So the project is
to just change the pulse width of the PWM that I have produce...lets
say there is three button and when I press the first one is 100% duty then
2nd 50% and 3rd 25% and so on...I
can not get the PWM to change instead i get constant 5Vbut
is I run the program to get a single duty cycle the program is perfect.
(no selection)I would like
to know how i can change the duty cycle, what are the step that i should
follow??current i am just
loading the new value of the duty cycle to the CCPR1L thats where the compare
value is store.here is a
small part of the program... Assuming
that the pwm wave is already running
BTFSC PORTD,4 &
;SCAN STATUS OF EACH PINS,GOTO change when a high is detected
of the CYCLEX CYCLEX &nb
MOVLW 0X1F &
;LOAD THE TIMER WITH THE REQUIRED
GOTO START So
if anyone have any idea of how to go about changing the duty cycles and
is it because that portD is use as PSP so special steps are needed to be
taken?? PLEASE HELP ME
Thomas C. Sefranek WA1RHP
ARRL Instructor, Technical Specialist, VE Contact.
When you moved the literal 0x1f to the W register, your next instruction
should be to move the W register to somewhere using the MOVWF command.
What you are doing is overwriting the 0xlf with the next command to move
the literal CYCLEVALUE to the W register.
> example of the CYCLEX
> MOVLW 0X1F
; MISSING MOVWF COMMAND???
> MOVLW CYCLEVALUE ;LOAD THE TIMER WITH
> THE REQUIRED
> MOVWF CCPR1L
> GOTO START
> So if anyone have any idea of how to go about changing the duty cycles
> and is it because that portD is use as PSP so special steps are needed
> to be taken?? PLEASE HELP ME
ICQ # : 12978762
/ ( ) \
\_/ : \_/
| | |
One thing to do to break this problem in to smaller pieces is
to make sure the PWM output is pulsing when the program is running
normally. Temporarily disconnect the low-pass filter network so that
there is access to the actual PWM output.
If one has an oscilloscope, it should be easy to see the wave
form which will be a progression of pulses such that the on time is
proportional to the off time which is how one figures the duty cycle,
anyway. Avoid duty cycles of 100% and 0% as they will just be the
output on all the time or off all the time. With a 50% duty cycle,
the positive half cycle should be as wide as the negative half.
If there is no scope handy, it may be necessary to use a logic
probe or some other means to determine that there is pulsation.
After that question has been answered, check the low-pass
filter. The simplest ones are just a resistor and capacitor in series
between the PWM output and ground. The idea is that the time constant
must be long enough that the capacitor can not fully charge nor fully
discharge. I hope some folks with a better grasp of the math can give
us actual numbers, but the game is to have a constant such that the
filtered output produces a steady voltage which is proportional to the
duty cycle. A 50% duty cycle should produce half the supply voltage.
If one is using an 8-bit PWM generator, then a 1 count will
produce a pulse that is on 1/256TH of the whole period and off the
rest of the time. This produces a very small voltage. If the number
254 was stuffed in to the generator, then the opposite is true and
there is a bit that is on most of the time and off for 1 count out of
If the filter does not have a long enough time constant, then
the PWM output will actually show the pulses and a count of 1 or so
will actually look like a series of spikes at 5 volts and 0 volts the
rest of the time. It definitely won't give the intended results.
Another consideration is that one wants the PWM output to have
a short enough constant so as to be responsive enough to reflect the
actual changes in level that one needs for the project.
One small example. Some of the nicest CD players today state
in their documentation that they use a 1-bit D/A converter. This is
just a PWM output that pulses at several megahertz. The filter on
that output gets rid of the megahertz pulse frequency just like a
filter in a power supply gets rid of the mains frequency. The filter
has to have a long enough time constant to smooth out the pulses, but
a short enough one to not cut off the 20-KHZ upper frequency limit of
In the real world, one needs several stages of filtering to
totally filter out the PWM frequency. My point in all of this is that
in order to trouble-shoot the PWM voltage problem, it will be necessary
to make sure that the PWM is actually delivering the pulses and that
the low-pass filter is actually suitable for the frequencies and time
A final example of a pwm situation is the 50% and 25% power
settings on a microwave oven. The power is actually 100% when it is
on, but the controller cycles it on and off at a 50% or 25% duty
cycle. The low-pass filter is the thermal constant of the food.
Martin McCormick WB5AGZ Stillwater, OK
OSU Center for Computing and Information Services Data Communications Group
part 0 16 bytes
Dear Sir / Madam,
I would like to thank you in advance for your precious time. I am trying to drive 3 servos through a PIC. I found the 4 servo controller in the site but I cannot follow it.
Since when using the CCP channels for PWM I am using the TIMER2 and therefore I can use only one frequency - is it possible to send different PWMs to the servos?
Would it be better to use interrupts instead of CCP channels?
Also I need an 18ms delay between the pulses how can I do that?
I have all the documentation from microchip but I still cannot understand how I can produce a 1900us PWM signal.
Would please someone help me?
ALL-NEW Yahoo! Messenger - all new features - even more fun!
More... (looser matching)
- Last day of these posts
- In 2005
, 2006 only
- New search...