Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Piezo PWM volume control problem

Status
Not open for further replies.

llrjt100

New Member
Hi,

I'm trying to control the volume of a piezo buzzer with a AVR Mega16 microcontoller using PWM. I've got the buzzer hooked up to the PWM pin (OCR1A) and I can set the frequency by choosing a suitable Clock prescale but I'm having problems with volume control. When I vary the PWM duty cycle, the volume DOESN'T change - I just hear some very slight alterations in the tone.

Is this because I'm using a piezo which requires a square wave input? Should I be using some other kind of DC input piezo, or is it just me?!

Any help would be appreciated.
Richard
 
Are you driving a transistor to the peizo or directlyed hook to the uC?

I found I had weird issues (with Atmel AVR max current output) when I do it direct, the uC in my case could not handle the peizo I was using. Maybe drop a 2K+ on the base of a 2n2222 and ground the emitter and drop the peizo to VCC and collector and see if that helps.

The freq will control the tone, not sure if the duty cycle will control the volume. Maybe an RC in there somewhere?
 
Ya, I think you'll have a problem trying to control volume with a piezo. How much volume control do you need? Perhaps a resistor ladder with multiple output pins off your uC would work for simple volume control.

Then you'll have a different volume level for each output pin you choose to use. I'll have to do an experiment with this and see if it works.
 
I've got PWM OC1A driving the common GND of a ULN2003 Darlington transistor array via a 2N2222 transistor. I've got one of the mc output pins connected to one of the ULN2003 input pins and the corresponding ULN2003 output pin driving the piezo with the other side of the piezo at Vcc.

The only way I got this to work before was with a resistor ladder :-( which is hungry on i/o.

I'm using a square wave direct drive piezo at the moment - what if I use a DC drive piezo with its own onboard oscillator, the frequency would be fixed, which is OK for this application and surely PWMing the DC input would give me volume control?
 
Ladder is a good idea as long has you have extra pins. I guess that transistor is not needed, but that was another test to make sure it was not a drive problem..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top