PDA

View Full Version : Two 16F84 pics using one piezo?



Rubicon
- 5th September 2005, 12:22
Hello,

How would one have two 16F84 pics share a single piezo speaker on their PORTA.1 pins?

At the moment I have a couple on a test breadboard their PORTA.1 pins connected to a single 10uF/16V electro cap and on to a (I hope) piezo speaker. I scavenged the speaker from an old UNIDEN cordless phone and it won't work without the capacitor. All the PORTB pins are connected to two banks of LEDS that light back and forth and beep when they reach either end. It's only point is to teach me how to do this.

If only one PIC is connected then everything works fine - startup beep and the beeps at either end but with two PICs there's only one startup beep then little clicks from the speaker.

Sorry but I don't have the current code to post - it's on an ancient computer in the garage with a faulty floppy, yes floppy drive. I must replace that sometime.

Any help greatly appreciated.

Rubicon.

sougata
- 5th September 2005, 12:28
Hi there,

You can try to amplify (buffer) the signal from the port pins through a single npn transistor and connect the the collectors of both to the buzzer if you are using thge sound function. If you are using a self oscillatory piezo buzzer then just and the ports using two diodes (4007 or such) and should get satisfactory result.

Regards

Sougata

Ingvar
- 5th September 2005, 18:00
Try making the pin INPUT right after each soundgenerating command.
You might also get away with connecting it PortA.1-capacitor-piezo-PortA.1(on other pic). This will only work if both pins are outputs and it has the potential to make very interesting sounds if both pics try to beep at the same time.

Ron Marcus
- 6th September 2005, 03:33
What would happen if you attached one pin to the center part of the piezo, and the other to the rim? When one is sending a tone, the other will be either at gnd potential, or b+. When the sending PIC changes, the same would be true of the other one. Even if there is a conflict where both were sending, the piezo would act as a mixer and create some wild effects. Just a thought...

Ron Marcus
- 6th September 2005, 03:37
Duh, Sorry Ingvar, I just duplicated part of your post.

Ingvar
- 6th September 2005, 08:44
Yeah, i got that "déjà vu" when i read your post.

It must be a good idea since we both came up with it. Now all we need is that Rubicon actually tries it and reports back what it sounded like.

/Ingvar

sougata
- 6th September 2005, 11:21
Hi everybody,

That's an interesting option posted by ingvar. However if both the PICs are in output mode then there can be current rush through (even with the capacitors in series with the pin).

Regards
Sougata

Rubicon
- 6th September 2005, 13:15
Thanks for all the reply posts.

Ingvar was right on the money with "Try making the pin INPUT right after each soundgenerating command."

I'd originally had TRISA = %11100, PORTA.1 an output but had changed it to an input before my original post. That had made the first startup beep go. Having read that due to DC bias the port should be an output and idled low I'd added a line after each SOUND command - PORTA.1 = 0 but that hadn't worked. Changing it to TRISA = %11110 made it work well enough. When the LEDs reach an end at a different time there's a regular beep. If the same time there's a slightly louder beep. If I make it beep twice or more per LED bank at either end and they reach it at a slightly different time then they fight it out with sometimes a squalk or two.

I have a question also. In the manual it stated that the SOUND command automatically makes a pin an output. I wasn't sure if it makes it a pin set as input an output for the duration of the sound then returns the pin to an input or not. From the look of it it doesn't. Does this apply to all the other commands that automatically change a pins state or are there exceptions?

I haven't tried the PortA.1-capacitor-piezo-PortA.1(on other pic) setup yet and sougata has put me off a little. If it's safe for the PICs I'll give it a go.

Many thanks,

Rubicon.

mister_e
- 6th September 2005, 16:38
i can't comment on the SOUND command but if it's like PWM, sometimes the pin return to Input, sometimes to Output state so...

As producing sound is not a big job, i suggest you to build a few line routine for that. That way, you'll be able to reach the exact resonnance frequency and get the maximum SPL of your piezo.

Don't worry, the suggested method is safe.

sougata
- 7th September 2005, 12:13
Hi,
Use a series limiting resistor and give the port to port via capacitor scheme a try. You bet you can produce interesting effecting where one PIC generates the sound and the other modulates it.

A recommendation would be to use a non-polar cap. Or two electrolytes back to back.

BTW in this scheme both has to be an output.

Regards

Sougata

Rubicon
- 8th September 2005, 01:51
O.K then I'll give it a go and report back.

I suppose if I really didn't want any beeping conflicts I could make the program check the pin for an input voltage before a SOUND command and if there is a voltage present then use another routine.

Rubicon.

Rubicon
- 9th September 2005, 04:24
With both PICs PORTA.1 pins set as outputs and making them again outputs after each SOUND command just to be sure I tried the PortA.1-1uF ceramic capacitor-piezo-PortA.1 and PortA.1-10uF electrolytic capacitor-piezo-capacitor PortA. schemes.

With both schemes I got the regular beep, a slightly louder regular beep and if both LED banks were completely in-sync the beeping sped up by a what sounded like a factor of four. That was it.

Many thanks again,

Rubicon.