From: Vladimir Vassilevsky on


Tim Wescott wrote:


> I haven't _done_ it, but I see no reason that it shouldn't be bullet
> proof.

PWM is not bullet proof; it has many subtleties.

> If you can get unwrapped from all the details of the PWM generation
> process you'll find that a PWM output followed by a low pass filter acts
> pretty much like a DAC followed by a low pass filter. Get that firmly in
> your head, and then you can think of the PWM/filter combo as a simple 8-
> bit DAC.

This is big oversimplification full of incorrect assumptions. PWM is
nonlinear process, PCM is linear.

> Eight bits aren't at all enough for decent audio quality, but it should
> be sufficient for solid DTMF signaling.

Combining two square waves into 3-level signal is good enough for
signaling; however it won't fit into regulatory template.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
From: rickman on
On Feb 19, 3:25 am, gamma <darkknight...(a)gmail.com> wrote:
> Hi
>
> I'm wanting to generate DTMF tone dialling (to dial a phone number)
> using an AVR micro with the timer in PWM mode.
> There's a description of how it supposedly works herehttp://www.atmel.com/dyn/resources/prod_documents/doc1982.pdf
> and some source code herehttp://www.avrfreaks.net/index.php?func=viewItem&item_id=168&module=F...
>
> From looking at the code in the example, the CPU runs at 8 MHz and
> timer 1 interrupts every 510 cycles (256 + 254) i.e. a counter counts
> from zero up to 255 and back to zero and an interrupt occurs every
> time the counter reaches zero.  The output that generates the waveform
> changes when the counter matches an output compare register.  The
> value in the output compare register changes on each interrupt, to
> generate a varying duty cycle.  At 8 MHz and with a prescalar of one,
> an interrupt occurs every 64 microseconds or so.
>
> What I'm not sure I understand is what the idea of PWM mode with the
> AVR timer is.  In non PWM mode, using output compare, you can also
> generate high/low pulses - the only problem is that for the short
> pulses, you have to be able to re-interrupt very quickly  - too
> quickly  - so PWM mode handles these short pulses.  Is that right?
>
> Wikipedia has a picture of the waveform for the dial-tone of a "1"
> herehttp://en.wikipedia.org/wiki/File:MultiTone1.png
> Does anyone have any experience of using the AVR micro to generate
> dial tones and does it work?
>
> TIA

I haven't looked at your references, but I did the exact thing of
using PWM to generate audio on a PC many years ago. I'm not sure what
prompted me, but I wrote some code to steal the timer interrupt of the
8253 clock interrupt timer along with the timer that drove the PC
speaker. I used the interrupt to mark the sample rate and programmed
the PC speaker timer for the PWM output. It actually worked
acceptably when playing audio files. The audio wasn't great, but
voice could be understood. A coworker was walking by and heard the PC
talking and wanted to know how I did that. The end result was that
they added code to their signal processing software to let the user
"hear" what the tool was doing to the signal. Remember, this was in
the days before every PC had attached speakers. One of the sounds
produced were DTMF tones in addition to other signaling sounds. I
think it was used as a teaching tool as much as anything.

Rick