Using PWM on AVR micro to generate DTMF

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

formatting link
and some source code here
formatting link

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

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

TIA

Reply to
gamma
Loading thread data ...

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.

No, but its an interesting topic...

Reply to
Stefan Brröring

of course it should be like:

Stefan

Reply to
Stefan Brröring

formatting link

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

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

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
Reply to
Tim Wescott

PWM is not bullet proof; it has many subtleties.

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

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

formatting link

Reply to
Vladimir Vassilevsky

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

Reply to
rickman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.