Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to play different tones using PIC and a buzzer?

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
Hello!! Everyone

I have to play various types tones using PIC18f4550 micro-controller and a piezo-electric buzzer.
Various Types of tones are:
1) Key Accept Tone (Whenever someone presses the key and the key is valid then i have to play a short tone for acceptance)
2) Invalid Key Tone (Whenever someone presses the key and the key is not valid then i have to play a key tone which is annoying)
and more like that.

how can i proceed in this task??

Right now i am learning how to use PWM of PIC and wrote some basic functions for PWM such as PWM Set Frequency, duty cycle, start and stop, which i will use to play tones but after doing this i realize this is not what i wanted as for my project duty cycle and pwm frequency will remain constant through out the life of product.


Which frequency will be suitable for hearing purpose.
In proteus i simulated with 4khz and its very bad.
The reason i choose 4Khz is because i am operating PIC at 48MHz and due to which i am not able to go below 4Khz, am i right or doing something wrong.
 

A good pitch to try is between 500 to 2500 Hz. It's a range which is easy for the human ear to detect, and easy to produce from a piezo unit.

Can you devise a program to turn the 4kHz tone on and off at a rate of 500-2500 Hz?

There are piezo beepers and buzzers. There are 2-wire piezo units and 3-wire type. Some types require a pulse train to drive them. Some only require a DC power supply. It is your job to provide the correct method to activate it.
 
Can you devise a program to turn the 4kHz tone on and off at a rate of 500-2500 Hz?

I didn't understand this.

I am using 2khz frequency and 50% duty cycle. (Able to hear these properly)
The one i have has two wires and it is working with DC supply as well as with PWM Pulse of 2Khz and 50% duty cycle.

I even managed to generate tones now i have to make some generic functions which can used to trigger the particular tone.
 

I wrote: "Can you devise a program to turn the 4kHz tone on and off at a rate of 500-2500 Hz?"

I didn't understand this.

I was suggesting a way to modulate 4kHz in order to generate a lower audio frequency (because you first stated 4 kHz was as low as you can go).

Since you now can play 2 kHz, that's excellent.

--------------------------------------

As for what sort of tones are suitable...
A key that is accepted might cause a cheerful sound, example, a pitch that swoops upward in frequency, or warbles.

A key that is incorrect might cause a pitch that drops in frequency as though disappointed.

TV game shows often play similar sound effects.
 
Do you have PWM output available? You can use that for many sound effects, I presume.
 

I wrote: "Can you devise a program to turn the 4kHz tone on and off at a rate of 500-2500 Hz?"



I was suggesting a way to modulate 4kHz in order to generate a lower audio frequency (because you first stated 4 kHz was as low as you can go).

Since you now can play 2 kHz, that's excellent.

--------------------------------------

As for what sort of tones are suitable...
A key that is accepted might cause a cheerful sound, example, a pitch that swoops upward in frequency, or warbles.

A key that is incorrect might cause a pitch that drops in frequency as though disappointed.

TV game shows often play similar sound effects.

Yes i changed my oscillator frequency to 20MHz from 48MHz
And Now i am able to generate 2KHz frequency PWM pulse.

Key Accept Tone : 100 ms On and 100 ms Off
Key Invalid Tone : 100 ms On and 100 ms Off for 4 times

Now i am able to generate tones, will use these in my project.
Thanks

- - - Updated - - -

Do you have PWM output available? You can use that for many sound effects, I presume.

Yes i am using PWM output.
Yes i am using these PWM outputs to generate different types of tones, i wish if there are some standard tones available with frequency and duty cycle.
 

You can design your own complex tones - producing some new or original tones for 200-300ms will be simple, I presume.
 
I believe you are getting what you may want but not by the way you think. They way it sounds (pardon the pun) is that you are using a standard buzzer that emits a tone when connected to a power supply ("The one I have has two wires and it is working with DC supply as well as with PWM Pulse of 2Khz and 50% duty cycle.") Usually, these will sound at a given frequency (+/- some relatively wide %) after a finite amount of time. You might be able to change the tone by turning it on and off at different rates to take advantage of the fact thr buzzer takes some time to get to its design frequency.

If I can suggest, if you want better control and have a wider range of possibilities of the sounds that can be played, replace the buzzer with a speaker. You should be able to find a small speaker in the same form factor and voltage. This would allow much more precise sound generation since you can control the frequency of the tone through the PWM frequency and the loudness (to an extent) with the duty cycle.

If you plan on building more than 1 unit and you want them all to sound the same, a speaker is the way to go. This is from experience.
 
Let us say you have a 500Hz tone 100% amplitude modulated with a 10Hz signal, you can make a drawing of the waveform and then convert it to a PWM signal. This need not be very elaborate and you need not waste too much memory on this. Similar but different tones can be made and stored and played back. As it has been pointed out (#8) above, these buzzers are having poor frequency response and you may not get exactly what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top