---------- > From: Peter (Chee Foon Tiang) > To: PICLIST@MITVMA.MIT.EDU > Subject: Piezo speaker with PIC -> formula for musical notes frequencycalculation > Date: Sunday, May 31, 1998 10:15 PM > > Somebody mentioned on the PICLIST: > > http://www.dontronics.com/see.html#sound > > However, I don't think they produces the correct pitch on the > musical scale. > > So you might like to try my formula for musical tone > generation.... > > Theory of Operation > =================== > > i. The note "A" below "middle-C" is defined as 220 Hz. > > ii. An octave higher/lower corresponds to frequency > doubling/halving, i.e., > > "DO", "RE", "MI", "FA", "SO", "LA", "TI", "DO" > ^ ^ > | | > +-----------------------------------------+ > one octave / 2x frequency > > iii. You have 12 semitones (including flats and sharps) in an > octave. > > iv. The pitch(freq) increases exponentially going up the scale. > > Formula > ======= > Therefore, > ___ > k = 12 / (twelth root of 2) > \/ 2 > > where k = multiplier to the next semitone. > > if you natural log the above formula, it would be clearer, > > ln k = ln 2 / 12 > > Calculation > =========== > So, you have, > ___ > "DO" / middle-C = 12 / * 220 * 3 > \/ 2 > = 261.63 Hz > "DO" is 3 semitones above the reference note A. > > and, > ___ > "RE" / D = 12 / * 220 * 5 > \/ 2 > = 277.18 Hz > "RE" is 5 semitones above the reference note A. > > etc. > > So use a spreadsheet to calculate the frequency for the notes > in the octave that you want to cover and the corresponding periods > and reload values for your timers. > > I'm sorry that I do not have the PIC codes (haven't done one). > > I do have the assembly codes for Hitachi's 4-bit, C codes for > 8-bit and 16-bit uC. > > And by the way, although the PIC I/O ports can drive relatively > high current, it would be safer to use the circuit below (which > I think is relatively simple and cheap). > > Regards, > > > Peter Tiang > Design & Applications Lab > Hitachi Semiconductor(M) Sdn Bhd > > ==================================================================== > > >>> Mark Devin Newland 30/May/1998 11:49am >>> > I just build up my proto board for a similar project but used a 2N7000 > instead. However, I do not have the tone formulas and graciously ask > for a copy. Thanks in advance > > Peter (Chee Foon Tiang) wrote: > > > Drive the buzzer thru a pnp transistor as thus: > > > > +5V > > I/O 10k 100k | > > ---/\/\/\/\---+---/\/\/\/\---+ > > | E_____| > > | B |/ > > +-------|\__ > > C | > > | > > / > > / > > +-----+ > > | | BUZ > > +-----+ > > | > > GND > > > > Use a "frequency-controlled" type of > > buzzer (which works like conventional > > speakers), and you can generate > > various frequency to your liking. > > > > If you like I can mail you the formula > > for generating melodies, like > > "DO, RE, MI", etc. > > > > Regards, > > Peter Tiang > > ====================================== > > > > >>> NCS Products 29/May/1998 09:04am >>> > > I want to add sounds to a product--beeps and boops and the like. > > > > Can I just hook a piezo speaker to a PIC output pin? > > Or should I use a resistor and/or capacitor in series? Peter: Would it be better for the trnsistor to put the transducer in the emitter circuit?