Some time ago there was a thread about DTMF decoders and one gentleman stated that he had developed a fully functional DTMF decoder that used an incredibly small amount of PIC processor resources. He could not share the details with us because he had done the work for his employer. I'm sure I know how he did it. I stumbled on the trick quite by accident while testing software I wrote for my employer. Since this knowledge is too important to many PICLIST'ers to keep under my hat, and my employer is not into telephone products, I'm going to share it with you. I did a quick experiment to verify the concept works, and writing the code would be easy, I just don't have the time right now to work out the numbers related to the DTMF frequencies. The trick can simultaneously detect any number of frequencies in almost any amount of noise and interference with an amazingly small amount of code. The secret is synchronous detection. For those that don't know, let me first explain and give an example of synchronous detection. A synchronous detector is a device (hardware or software) that can detect a signal with a high degree of noise immunity because it is synchronized to the source of the signal allowing it to average out noise. Lets say you had a photoelectric eye as a safety device that stopped a machine if someone got too close to it. On one side of the six foot access way to the machine is an LED emitting a beam of infra-red light in a square wave (very important) to the receiver 6 ft away. On the other side of the access way is a receiver which contains a photodiode and a very high gain amplifier that picked up the square wave from the emitter, but also electrical and optical interference from the motor drives of all the machines in the area and the mercury vapor lights overhead. This interference would cause the machine to shut down for no apparent reason. The synchronous detector solves the problem because the square wave driving the emitting LED also synchronizes the detector, finding the signal and averaging out the (random) noise. A synchronous detector works as follows: If a received signal is in phase with the reference signal, a capacitor is charged or a counter is incremented. If a signal is received which is out of phase with the reference signal, a capacitor is dis- charged or a counter is decremented by an equal amount. The noise, being random, or just not in step with the reference, will produce no average charge on the capacitor or count in the counter, while the real signal will. The amount of noise immunity is determined by the time constant of the capacitor or the number of counts in a counter. A synchronous detector can also be used as a frequency detector if the number of counts or the time constant is not too long. In my test, my software synchronous detector running a sample rate of 7KHz @ 20 samples per test, with a trigger threshold of 10 counts, would produce an output if an unsynchronized input signal came within about 50Hz of 7KHz or a multiple thereof. In a DTMF decoder, you will probably need a low pass filter to keep out harmonics. In a frequency detector, you won't be turning on and off an LED, so you would just test the input and increment a counter (once or a number of times, depending on required noise immunity and processor speed) for a period of time each time a high is seen. You would repeat the process for the same amount of time and counts, only decrementing the counter each time a high is seen. The cycle rate of incrementing and decrementing would be the target trequency. The number of samples and the trigger threshold (count) would set the bandwidth. Noise would be present both during the incrementing and decrementing and would be cancelled (averaged) out. To similtaneously detect multiple frequencies, you would have one register for each frequency to be detected, initialized at the middle of their range. You would run the CPU like a state machine, looking at the input and incrementing and decrementing the appropriate registers according the CPU clock rate and the periods of the various frequencies. After an appropriate number of counts for the required bandwidth, you would look at each of the registers and any register that was over the threshold count would indicate that that particular frequency had been detected. At this point, you know the rest. The input to the PIC would be a comparator (no schmitt trigger) or high gain amplifier like in TV/VCR remote receivers, which would change state at the zero crossings, saturating with the signal and clipping off noise. The summing of the two DTMF frequencies would produce a stream of pulses in which square waves of the two DTMF frequencies could be seen. I would like to use this technique in a home project, but I don't have the time right now to sit down and work out the numbers related to the DTMF frequencies, although I have verified that the trick will work. I would be grateful if someone who does have the time and the need to work out the details would return the favor and share his/her code with me. I won't be using it in a commercial project since my employer is not into telephone products. TTFN :-)