From: gamma on
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 here
http://www.atmel.com/dyn/resources/prod_documents/doc1982.pdf
and some source code here
http://www.avrfreaks.net/index.php?func=viewItem&item_id=168&module=Freaks%20Tools

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"
here
http://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
From: Stefan Brröring on
> 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?

PWM is used instead of a D/A converter, so it runs with about 16 KHz,
thats about 10 times of the highest tone that you need for DTMF (about
1.6 KHz).

So, you can see the PWM output as an anlog output. You only need to add
a simple low-pass filter. The voltage at the output is nearly
proportional to the pulse-lenght of the PWM signal.

Then, with every int, you reload a value from a table which describes
the wave-form. This can be calculated like:

U = Umax (sin(f1*t) + sin/f2*t))

Because U has positive and negative values, you have to add an offset,
so that you will only get positive values for the reload value.

To eliminate the DC part, you need a high-pass filter.


> Does anyone have any experience of using the AVR micro to generate
> dial tones and does it work?

No, but its an interesting topic...
From: Stefan Brröring on
of course it should be like:

> U = Umax (sin(2*pi*f1*t) + sin(2*pi*f2*t))


Stefan
From: Vladimir Vassilevsky on


gamma 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.

> Does anyone have any experience of using the AVR micro to generate
> dial tones and does it work?

http://www.abvolt.com/products/telephone.htm

This uses AVR Tiny 26; it generates tones by PWM.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
From: Tim Wescott on
On Fri, 19 Feb 2010 00:25:22 -0800, gamma 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 here
> http://www.atmel.com/dyn/resources/prod_documents/doc1982.pdf and some
> source code here
> http://www.avrfreaks.net/index.php?
func=viewItem&item_id=168&module=Freaks%20Tools
>
> 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" here
> http://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 _done_ it, but I see no reason that it shouldn't be bullet
proof.

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.

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

--
www.wescottdesign.com