At 09:45 PM 10/8/97 +0100, Floortje Hanneman & Wouter van Ooijen wrote: >Im working on a 16C84 based 'laser' (actually IR) gun/target. >When it either shoots or it is hit it should make some interesting noise. >I've connected a PIC pin to a 100uF elco and a small 8 ohm LSP, >but that doesn't make much noise. Adding a BD136/BD137 makes more noise, >but not enough for my taste. Also a simple square wave makes a rather dull >sound. > >Questions: >- what is an appropriate (simple) amplifier for a small speaker (or is > the 5 volt the limit, and should I use either a higher voltage or a > 4 transistor bridge)? >- would a piezo buzzer make more noise (when driven with the same voltage)? >- does anyone have experience in generating more interesting > sounds via 1 output bit (for instance using PWM)? If you can afford an additional pin, you can get twice the voltage amplitude by differential-driving your speaker. Simply output 01 or 10 to the two pins to either apply +V or -V across your speaker, giving a 2*V amplitude swing. Using one pin, you get only 0 to +V across the speaker. PICs have relatively high current sink & source capabilities (I think 25mA & 20mA, respectively, for the 16C84), but 5V into an 8 ohm load can draw up to 625mA, so a simple transistor amplifier could help if you need higher volume than is possible with differential drive. Small speakers have a rather limited frequency response. Most that I have seen are best used between about 400 - 4000 Hz. Piezo elements have higher impedance than speakers, and you should be able to get fairly high volume out of one with even single-ended drive off of one pin, but they have even worse frequency response than miniature speakers. Most have a resonant peak around 3-4 KHz. If you have access to a signal generator, try driving a piezo element like the one you plan to use with a 5Vp-p square wave, and tweak the frequency for maximum volume. Design your PIC circuit to use the same frequency. If you don't have a signal generator, many sources (such as DigiKey) list the resonant frequencies of the piezo elements they sell. If you want some more control over waveform, try using two pins, two resistors, and an op-amp voltage follower circuit to build a simple buffered D/A converter to drive your output device. +------------+ | | | |\ | | | \ | +--|- \ | | >-----+------O Vout +-----------+-----------|+ / | | | / > > |/ D1 | D0 | Vout < 10Kohms < 20Kohms -----+----+------- > > 0 | 0 | 0 | | 0 | 1 | V/3 | | 1 | 0 | 2V/3 --------------------------------- 1 | 1 | V D1 D0 PIC Output Port (where V is your supply voltage) This will allow you to have 4 distinct voltage levels on your output, and the op-amp will give you higher output drive capability, as well. By careful setting of the output levels, you can simulate triangle, sine, sawtooth, and other waveforms, albeit with only two bits of accuracy. However, depending on how many output pins you have free, you could go to 3 or 4 bits by extending this concept. Just make sure that each resistor is twice the value of the previous one. For example, use a 10K on D3, a 20K on D2, 40K on D1, and 80K on D0. Beyond 4 bits, go to a R/2R network or a dedicated D/A chip. Hopefully, my ASCII art circuit is sufficiently legible.... use a fixed-pitch font such as Courier to view it. - Rick "ASCII silly question, get a silly ANSI" Dickinson +---------------------------------+---------------------------+ | Enterprise ArchiTechs Company | | | Lotus Certified Notes | Never underestimate the | | Appl. Design & Administration | bandwidth of a station- | |(818)563-1061 rtd@notesguy.com | wagon full of tape reels. | | http://www.eArchiTechs.com | | +---------------------------------+---------------------------+