Hello all i want to make a alarm which is pretty simple for me but i would love to be able to drive a small speaker for the alarm sound instead of a buzzer...
Can anyone point me to how to control a speaker. How to get different tones and stuff from a MCU pin...
Can be AVR, PIC, ARM i dont care really. Its all the same to me heh...
Do not just connect a speaker voice coil from a PIC pin to ground. The DC resistance of the speaker is so low that it will overload the port pin. Put a 100uF or so electrolytic capacitor (6V, properly polarized) in series with the speaker. This breaks the DC path so no DC current is drawn from the PIC port pin.
I would also try to find a 2" speaker with a 30 to 45 Ohm voice coil (they exist), rather than using one with a 4Ohm coil. It will make more sound and load the pin less.
Myke Predko did a little bit about sound from microcontrollers (PICs) in his book Programming and Customizing PICmicro Microcontrollers. Here's a link to the pertinent chapter at Google Books.
Heh You got a calculator between your ears that will do that one easily.
Lucio Di Jasio has some good audio info in the last chapter of his "Programming 16-bit Microcontrollers in C" and the 32-bit book as well. I know you have a copy of the 16-bit book at least.
I have both heh... didnt even notice these books ... i forgot i bought the "Programming 32-bit Microcontrollers in C Exploring the PIC32" when i first wanted to get into PIC32 but went to arm heh...
I have a question about the inductive spike from the speaker coil. Given the high dv/dt of the PIC PWM signal, can anyone explain how the inductive spike from the coil is handled without a flywheel diode? Or is it assumed that the built in diode in the PIC handles the spike?