Sound output from small PIC Microchip

Status
Not open for further replies.

rnorman3

New Member
Hello all, I want to create a very simple and compact electronic keyboard (only 3 keys/switches) using just a small speaker, a 16F615, 3xAA batteries, and maybe a resistor or two. This is for my 10 year old's science project. It has to be as simple as possible.

I thought of just making it such that there would be one frequency for each key pressed (one key per digital pin and one output pin to the speaker. A couple of questions if you don't mind:

1. Will the pic be enough to directly drive a tiny 8ohm speaker, it doesn't need to be loud. Should I connect the speaker with a cap or inductor or something?

2. Is there some algorithm I can create in the firmware that would make the sound a little more interesting maybe to sound like a synthesizer? Or maybe by putting a cap or inductor at the speaker output?

Thanks!
RN
 
Audio is possible via the PWM module... You feed it's output through a small RC network... Its alright for headphones, but you will need a small amplifier to drive a speaker.
 
Hello there,


As Ian says, it's hard to get a lot of sound out of a PIC port when you are dealing with an 8 ohm speaker, but you should get something at least. Is it ok if they have to put their ear up to the speaker? Usually there's other noises in a science fair setting so you might want to think about this. And yes, you need a capacitor and resistor in series with the speaker. The port puts out 0 to 5v approximately and that's plus and minus 2.5 volts AC, and a 100 ohm resistor would allow 25ma peak which is a little high for a port pin so maybe 150 ohms would be safer.

But then there are usually other pins on a PIC too, not just one. You could use several pins and use them all to drive the same speaker. For example, using 4 ports and four 150 ohm resistors all going to the same port would give you 4 times the current which should be enough to hear although still not super loud. Four resistors and one capacitor, like an electrolytic cap of say 100uf with the positive terminal toward the port pins. That should give you something anyway. The programming for the four pins would all be the same unless you want to experiment with multi level signal creation which you probably dont.

When it comes to synth sound however, there's several factors that influence the sound quality. You should probably look this up because there are many aspects. For example, harmonic content and attack and decay to name a few. This is how we make a piano sound that is different from say a flute.

You should also work within a frequency range that is easy for humans to hear, like 1 kHz to 5 kHz i think is the best range (or close to that).
 
Last edited:
I have used these direct from an I/O pin. Not loud but enough to hear in a room with a TV on.

**broken link removed**

If you diode OR the two or more different outputs to the speaker, run each I/O pin on different timer interrupts (if you can on a PIC) and you can play around with multi-tone audio signals.

You certainly won't get the sound of a Steinway Piano out of a PIC.
 
You could modulate the frequency at a few Hz to make the sound more interesting.
 
Wow.... That is impressive... And he wants to excuse his "bad piano" skills...
 
Thanks so far, we're getting started on this, question though, pretty basic question, do I just come out of the pin, then to the speaker, then 150ohm to ground, and put a 100uF cap across the speaker?

Thanks!
 
The PicBasic Pro manual has the HPWN and SOUND commands that you can refer to.

Allen
 

Attachments

  • pbp_p96-96.pdf
    31.1 KB · Views: 631
  • PBP_p177.pdf
    23.7 KB · Views: 313
Wow.... That is impressive... And he wants to excuse his "bad piano" skills...

I know - it impressed me greatly

I wouldn't have believed it possibly to create a polyphonic piano using just a PIC - not to mention a capacitive keyboard as well.
 
Thanks so far, we're getting started on this, question though, pretty basic question, do I just come out of the pin, then to the speaker, then 150ohm to ground, and put a 100uF cap across the speaker?
Why put a capacitor across the speaker when it is supposed to be in series with the speaker and the current-limiting resistor?
Read post #3 again.
 
One timer to generate the main tone using a timer overflow with pre-load. A second timer running at a few hertz ramping up and down the timer preload value for the first timer.
Sorry if this cannot be done on a PIC as I haven't used them in years, but an 8051 from SILABs certainly can as I did this on a piece of kit I designed at work to make it more "interesting" to the end user.
 
thanks Allen, that's very interesting for me, but could I use PicBasic Pro with a JuneBug/PicKit2 programmer?
Thanks!
 
Shouldn't have any problem. The PBP produces a HEX file like the the assembler and C compiler. I normally use MicroCode Studio when working with PBP and program the PIC using PicKit2 v2.61 programming program.

I never used a JuneBug so cannot comment.

Allen
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…