-----Original Message----- From: Tracy Smith To: PICLIST@MITVMA.MIT.EDU Date: Thursday, November 11, 1999 5:55 AM Subject: Re: DTMF Tones? Can somebody explain how I make sound with a PIC? >--- Dave VanHorn wrote: >> > I would like to write some code to make DTMF >> tones. However I can't >> figure >> > out even how to produce noise. I have to hook up >> a capaciter or >> > something... I can't find any sample circuits and >> then even if I did. >> What >> > do I send? A pulse of some sort? >> >> >> This is one that might be better done in an external >> chip. > >I disagree. It might be easier if you have no idea how >to do it, but that's why people ask questions... > >I can think of several ways. Probably the easiest >would be to generate two sinusoidally modulated PWM >wave forms on two I/O pins, add them together through >a resistor network and low-pass filter them. Eric >Smith has a fast algorithm for generating sine waves, >while Scott Dattalo has one that based on phase >accumulators (and consequently easier to control the >frequency). Either of these may be used to generate >the two sine waves corresponding to the two tones. >Generating two pwm wave forms in software is more >challenging, but it CAN be done. I believe Lawrence >and again Scott have posted software pwm algorithms. > >I suspect (but don't have the time to show) that one >could combine the sinusoids digitally (as opposed to >an analog based summer). For example, the pwm duty >cycle could be formed by adding the sine waves >together. In other words, for every PWM cycle the duty >cycle is the proportional to the sum of the amplitudes >of the two sinusoids comprising the DTMF tone. > >You'll want to use phase accumulators to minimize >frequency errors and you'll need low-pass filters to >filter the PWM signal to remove the carrier. IIRC, a >single cycle resolution, 256 level PWM waveform on a >20MHZ pic has a carrier frequeny just under 20khz. >This would give you about 12 samples for the highest >DTMF frequency. > >.lo > >===== > >__________________________________________________ >Do You Yahoo!? >Bid and sell for free at http://auctions.yahoo.com > > I may be inventing the wheel... Anyway, there was an interesting idea in Scenix application notes on how to generate sine waveform not using table or multiply, just addition. Basically, they generate triangle waveform, then integrate it and, vou la, something very similar to sine is produced. Triangle waveform is easy to implement - its just addition and substraction. So, the frequency of sine waveform is equal to the primary triangle frequency. BUT, a problem appears when triangle frequency doesn't exactly match sampling frequency divided by an integer. Typical way to make triangle is something like: add to the current value fixed step untill the wave reaches maximum, then substract the step untill the wave reaches minimum, and again. What if the triangle reaches its maximums and minimums BETWEEN sampling points? In this case, an error will appear, and frequency is corrupted. A simple solution is: when triangle waveform goes over maximum, substract the number it went over from the maximum (see appendix); and same for minimum. As a result, the frequency is jitter free. The drawback is that the resulting sine amplitude is varying slightly depending on the step chosen. For DTMF it must be okay. 16bit resolution for step, accumulators of triangle and sine will be enough. For output, only 8 most significant bits can be taken. Is this the same as phase accumulators? _ Nikolai Golovchenko, Electrical Engineering Student National Mining University of Ukraine www.nmuu.dp.ua Dnepropetrovsk, Ukraine E-mail: golovchenko@mail.ru P.S. Tracy, may I ask you what "dot lo" means? :-) Attachment converted: wonderland:solution.gif (GIFf/JVWR) (0000F660)