Stuart Meier wrote... >After a spell on other things, I am back to a PIC project, and need to >generate a 'Dong' sound (as in "ding-dong", without the ding..) > >On cost grounds I can't go the ISD route, so I want to store and output >a waveform from a 12C PIC. Question is, how can I easily create the >table of tones/durations required? As I am tone deaf, trial and error >could take a lifetime... If all you need to do is create a good semblance of a chime or bell, here's an ultra-cheap circuit that'll generate a nice tone with very realistic exponential decay. Depending on the component values you choose, it can go "dong", "ding", "clink" or even "tunk". All it takes is four resistors, three capacitors, and two PIC I/O pins, one of which has to be the PIC's open-drain output pin, RA4. You'll also need to amplify the circuit's output, as it can't drive a speaker by itself. RA4------------------+ | RA3----R1---+---R2---+---R3---C2---+----+---> TO AMPLIFIER | | | | | | C1 C3 R4 | | | | | | GND GND GND Some component values, for the sake of an example: R1 =3D 470 ohms C1 =3D 10uF R2 =3D R3 =3D R4 =3D 10K ohms C2 =3D C3 =3D 10nF In this circuit, R1 acts as a current limiter to keep from overloading PIC port pin RA3, and it also controls waveform attack time together with C1; C1 and R2 control the decay rate of the tone; and R3/C2/R4/C3 form a bandpass filter that shapes the output waveform. R3 and C2 determine the low-frequency rolloff and kill most of the DC "pop" that would otherwise be superimposed on the output; and R4 and C3 determine the high-frequency rolloff and thus control the timbre (the harmonic content) of the output waveform. To operate the circuit: 1. Before initiating a "dong" procedure, RA3 and RA4 are both configured as outputs and both have been outputting a LOW. 2. To start the "dong", output a HIGH on both RA3 and RA4, and wait a period of time at least 5 * R1 * C1 to give C1 time to charge up (in this example, that would be about 25 milliseconds). 3. At the end of this period, change RA3 from an output to an input. 4. Then start outputting alternating 1's and 0's on RA4 at whatever frequency you want the tone to be, with roughly a 50% duty cycle. This generates the tone by "chopping" the DC voltage that's on the top end of C1, and it also causes C1 to start discharging through R2 during the half-cycles when port pin RA4 is low. Since the voltage on C1 decays exponentially, and since it's being chopped, you end up with a tone that decays in amplitude very realistically. 5. Once C1 is discharged, which takes about 10 * R2 * C1 seconds (about a second, in this example), stop toggling RA4 and leave it LOW; also make RA3 an output again and bring it LOW, too, until you want to emit another "dong". The rest of the work of creating a good sound with the right harmonics is the job of the output filter. Experiment with component values to get a good sound. Voila... Dave -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics