> I notice that the Basic Stamp 2 has a BASIC command (DTMFOUT) to > generate DTMF via a single digital output (aka 1 bit DAC), which > it says can be turned into proper waveforms with filtering. (It > also has a command to output one or two arbitrary tones). > > My question is: How is this done? > > I can see that a single tone can be done via a square wave (and > attenuating the 3, 5'th etc harmonics would approximate a sine wave). > But directly summing two square waves of equal amplitude and > different frequency would take a 3 level output. I don't see how to > reduce it to 2 levels and keep the desired dual tones even > approximately. There are a number of methods for this. Probably the simplest to understand is something like the following: Loop: bcf PORTB,0 btfsc Phase1,7 bsf PORTB,0 movf Freq1,w addwf Phase1 nop movf Freq2,w addwf Phase2 bsf PORTB,0 btfss Phase2,7 bcf PORTB,0 decfsz OverallTime goto Loop When both waves are high, the output is [almost] constantly high; when both are low, the output is [almost] constantly low. When the two waves are opposite each other, the output is a 50%-duty-cycle very rapid square wave.