Author Topic: A piezo buzzer that affect the MCU behaviour  (Read 12978 times)

0 Members and 1 Guest are viewing this topic.

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
A piezo buzzer that affect the MCU behaviour
« on: March 23, 2014, 10:54:10 pm »
I've designed a battery powered, 24 hours ATMEGA328P MCU based LCD start/stop timer that during counting, ticks every second with a short but STRONG "beep" sound that is being generated by the Tone library (1KHz 50mS 5V squarewave).

It have a software trigger that stops the count when a pin (say pin 14) goes LOW (TTL, 0V).

This device must be produced in a small series, so I've keeped in mind the KISS concept, making it easy to assemble, cheap and using the lowest number of component possible.

The main feature that I've keep in mind in this device is that it must have low current consumption, because is battery operated and must work for 24 hours, so both for the KISS and for the current consumption, I can't use an 1W audio amplifier circuit driven by the square wave only to make sound a traditional loudspeaker!

So I've used a traditional piezo buzzer.

Now, all the firmware is done and functional, and also the hardware works good. Only the sound is a little problematic: it is too quiet.

I need to add some "power" to the "ticking" sound. I guess that any 5V squarewave drived piezo is too quiet. I need something that could reach at least 92dB at 0,5M.

So I tried to use a small mosfet to drive a high volume 12V piezo (Kingstate KPEG-276 A) with two 10V zener in push-pull, and apparently it seemed to work fine.

Unfortunately, few hours later this mod, I discovered that this method cannot manage at all the voltage glitches coming out the piezo, and this have an impact on the entire circuit and affect the execution of the firmware AND MOST OF ALL, THESE GLITCHES SOMEHOW TRIGGERS SPORADICALLY AND RANDOMLY THE PIN 14 (the "stop" pin)!

I fear that this is caused by the glitches that randomly affect the linear regulator that generates the 5V used also to read the state of the "stop" pin, and this is confirmed by a DSO trace that I've captured during a long running in "one shot" mode.

Of course this is strange to me, because if it's a bad engineered circuitry issue, it should happen always, and not randomly. But I must accept that with a cheap 5V buzzer I've got no problems at all.

I must find a solution.

What do you suggest to do in hardware to drive the piezo and produce a loud sound without affecting the circuitry and the MCU behaviour? Do you agree using a transistor instead a mosfet? Or what else?

Can you suggest a schematic of your solution?
« Last Edit: March 23, 2014, 10:56:02 pm by mcinque »
 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: A piezo buzzer that affect the MCU behaviour
« Reply #1 on: March 23, 2014, 11:38:46 pm »
First thing I'd do is get rid of those zeners, if your Vds is very low, your clamping your 12v supply to approx 10.6v with no current limiting.

But then again, if your not driving your mosfet to saturation your probably getting away with it and you won't be getting the max from your peizo.

Put either a 1k resistor or a low uH inductor across the piezo and hit it with the peizo resonant frequency or a harmonic of that fundamental.

Also, how is the peizo mounted, is it just a disk or mounted on a resonant chamber. You won't get much out of it if it's not mounted properly.

 :)
« Last Edit: March 23, 2014, 11:42:26 pm by Mr Smiley »
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #2 on: March 24, 2014, 12:34:06 pm »
Thank you for the the replies.

First thing I'd do is get rid of those zeners, if your Vds is very low, your clamping your 12v supply to approx 10.6v with no current limiting.
Unforunately without the zeners the piezo gives back a huge spike to the linear regulator that affects all the circuitry and the MCU crashes. I've took that configuration from a Linear document about piezo driving.
 
But then again, if your not driving your mosfet to saturation your probably getting away with it and you won't be getting the max from your peizo.
The sound volume using the 12V piezo is fine and is loud enough. It's in the driving method where probably I'm missing something.

Put either a 1k resistor or a low uH inductor across the piezo and hit it with the peizo resonant frequency or a harmonic of that fundamental.
I've tried in the past to use a resistor, I will try with a low value inductor. Ok for the frequency.

Also, how is the peizo mounted, is it just a disk or mounted on a resonant chamber.
It's in his plastic resonant chamber.

Add a proper reset circuit to the RESET pin - cap to ground, res to vcc.
Already done, the schematic attached was only to describe the buzzer drive :)

Insert say a 1k series resistor to the fet gate. Fets look just like capacitors to the processor which will cause current switching spikes on the waveform edges.

I've tried also this method in the past, but it works only for the pin that drives the mosfet.

In this case  the spikes seems to affect a different pin behaviour (the "stop" pin) so the glitch must come from another place.

An unstable or glitched power supply will affect surely the MCU behaviour, that in some cases can even skip some IF statements of the code when those statements are related to HIGH or LOW states.

I'm confident that all my troubles are related to the piezo: this is confirmed because using an expensive piezo "sounder" (one with an internal oscillator, electronic circuitry and dip switches for the sound selection) I've got zero problems. But it's too expensive and too big (and most of all, I want to understand where I'm wrong).
 

Offline diyaudio

  • Frequent Contributor
  • **
  • !
  • Posts: 683
  • Country: za
Re: A piezo buzzer that affect the MCU behaviour
« Reply #3 on: March 24, 2014, 02:59:19 pm »
I've designed a battery powered, 24 hours ATMEGA328P MCU based LCD start/stop timer that during counting, ticks every second with a short but STRONG "beep" sound that is being generated by the Tone library (1KHz 50mS 5V squarewave).

It have a software trigger that stops the count when a pin (say pin 14) goes LOW (TTL, 0V).

This device must be produced in a small series, so I've keeped in mind the KISS concept, making it easy to assemble, cheap and using the lowest number of component possible.

The main feature that I've keep in mind in this device is that it must have low current consumption, because is battery operated and must work for 24 hours, so both for the KISS and for the current consumption, I can't use an 1W audio amplifier circuit driven by the square wave only to make sound a traditional loudspeaker!

So I've used a traditional piezo buzzer.

Now, all the firmware is done and functional, and also the hardware works good. Only the sound is a little problematic: it is too quiet.

I need to add some "power" to the "ticking" sound. I guess that any 5V squarewave drived piezo is too quiet. I need something that could reach at least 92dB at 0,5M.

So I tried to use a small mosfet to drive a high volume 12V piezo (Kingstate KPEG-276 A) with two 10V zener in push-pull, and apparently it seemed to work fine.

Unfortunately, few hours later this mod, I discovered that this method cannot manage at all the voltage glitches coming out the piezo, and this have an impact on the entire circuit and affect the execution of the firmware AND MOST OF ALL, THESE GLITCHES SOMEHOW TRIGGERS SPORADICALLY AND RANDOMLY THE PIN 14 (the "stop" pin)!

I fear that this is caused by the glitches that randomly affect the linear regulator that generates the 5V used also to read the state of the "stop" pin, and this is confirmed by a DSO trace that I've captured during a long running in "one shot" mode.

Of course this is strange to me, because if it's a bad engineered circuitry issue, it should happen always, and not randomly. But I must accept that with a cheap 5V buzzer I've got no problems at all.

I must find a solution.

What do you suggest to do in hardware to drive the piezo and produce a loud sound without affecting the circuitry and the MCU behaviour? Do you agree using a transistor instead a mosfet? Or what else?

Can you suggest a schematic of your solution?

you don't need a FET to drive the buzzer, any general purpose  high gain HFE > 200, 500mA will do the trick. what type of buzzer are you using, its a piezo buzzer right ? you don't need the zener clamps just stick to the working voltage of the piezo buzzer, its normally 5v as its developed for microcontroller, fact I used one directly from a 18F, 3.3V directly out a PORT and it was very annoying after a while.

You may use a signal diode IN4148 as a blocking diode to block any crap that may possibly enter the line, the capacitance of the buzzer it will present a short at some frequency as well.

« Last Edit: March 24, 2014, 03:06:04 pm by diyaudio »
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: A piezo buzzer that affect the MCU behaviour
« Reply #4 on: March 24, 2014, 03:25:01 pm »
Now, all the firmware is done and functional, and also the hardware works good. Only the sound is a little problematic: it is too quiet.

A piezo sounder is a capacitor which is deformed by applied voltage. Tying one end to a +ve supply and driving the other end low just charges the capacitor once and will make hardly any sound.

If you have to drive one with a switch to ground you need a resistor across the sounder to provide a discharge path and should have a series resistor to limit the charging current.
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16284
  • Country: za
Re: A piezo buzzer that affect the MCU behaviour
« Reply #5 on: March 24, 2014, 06:41:11 pm »
Resistor of around 1k across the piezo, no diodes and decouple the supply to the piezo with a series 100R resistor and a 100uF capacitor close to the piezo pins, having a short direct connection to the piezo drive and the FET, so you have the smallest loop. That, along with a zener diode of 24V across the capacitor will tame most of the transients and still give a loud tone. Gate stopper resistor as well, and use a high voltage mosfet ( 200V or more) so that spikes on the piezo side do not break down the gate insulation. High channel resistance will not be a worry here, it will actually help slow down the fast edges.
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #6 on: March 24, 2014, 10:11:14 pm »
Add some HF decoupling caps around your circuit.

You're damn right, thanks  :-+
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #7 on: March 24, 2014, 10:43:52 pm »
Resistor of around 1k across the piezo, no diodes and decouple the supply to the piezo with a series 100R resistor and a 100uF capacitor close to the piezo pins, having a short direct connection to the piezo drive and the FET, so you have the smallest loop.

Like this?
p.s. I didn't understand where you suggest to place the zener. Could you please be more specific?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: A piezo buzzer that affect the MCU behaviour
« Reply #8 on: March 24, 2014, 11:12:28 pm »
R4 and C7 will not help and could damage the MCU as a 12V spike will enter the I/O pin when the power is applied.
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #9 on: March 24, 2014, 11:15:53 pm »
R4 and C7 will not help and could damage the MCU as a 12V spike will enter the I/O pin when the power is applied.
Right... I must have misunderstood SeanB suggestions...  |O
 

Online mariush

  • Super Contributor
  • ***
  • Posts: 5027
  • Country: ro
  • .
Re: A piezo buzzer that affect the MCU behaviour
« Reply #10 on: March 24, 2014, 11:41:06 pm »
Nobody mentioned it yet but... you'll waste a lot of power getting 5v from 12v using a linear regulator. The efficiency will be under 50%, actually more towards the 40% area.

Even with a MC34063 you'll have about 65-70% efficiency and an AP1509 may go over 80%.

use decoupling capacitors.

Or think of using 4x1.5v batteries and a ldo that does 5v with just 1v dropout and maybe use a voltage doubler to get 12v to the buzzer.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9950
  • Country: nz
Re: A piezo buzzer that affect the MCU behaviour
« Reply #11 on: March 24, 2014, 11:54:24 pm »
Put your piezo buzzer onto a signal generator and figure out exactly what frequency peaks the resonance of it's plastic casing.
Then adjust your mcu code to produce that frequency


Yep, remove R4 and C7

With that 1K resistor in series with the mcu output its protected from spikes up to 30V  (1000R * 0.03A)

A 5V zener/TVS across the 10K would take the load off the MCU's clamp diodes to further protect the mcu input and also protect the mosfets gate from spikes.

A 15V TVS across the 12V rail would also help with generic spikes on the supply rail.


(Use uni-directional TVS diodes)
« Last Edit: March 25, 2014, 12:08:22 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline han

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: 00
Re: A piezo buzzer that affect the MCU behaviour
« Reply #12 on: March 25, 2014, 12:09:58 am »
i have been there...

When using 12v piezo buzzer (with internal transformator circuit), expect you will get HF noise with large E and H field.
in my case, the best solution is terminate every single pin in MCU, either drive it High or low (as an output) , or terminate input using resistor, since every pin in the MCU became antenna.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: A piezo buzzer that affect the MCU behaviour
« Reply #13 on: March 25, 2014, 12:13:20 am »
From the datasheet http://www.farnell.com/datasheets/16471.pdf:
Resonant frequency in KHz 2.8±0.5 (2.3KHz to 3.2KHz)
Sound pressure level in dB Minimum 93 at 30 cm/12VDC
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #14 on: March 25, 2014, 06:44:44 pm »
Thank you all for your replies and advices.

About the efficency issue, you're right mariush, I should try to use a MC34063.

I've applied all your suggesiton to the schematics, could you give it a look and tell me if all is fine before the test and debug?

Thank you for your help! I'm learning a lot from your advices.




 

Offline Mr Smiley

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: gb
Re: A piezo buzzer that affect the MCU behaviour
« Reply #15 on: March 25, 2014, 06:52:15 pm »
All your zeners are the WRONG way round   :palm:

They act as diodes in that orientation, thus shorting out the input to the regulator and the output driving the mosfet.

ps, why bother with 12v, you can run the piezo in a push pull configuration using two micro pins or as is with a parallel inductor.

Alarm clocks run on 1.5v and there loud enough to wake you from sleep  :=\
There is enough on this planet to sustain mans needs. There will never be enough on this planet to sustain mans greed.
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #16 on: March 25, 2014, 07:25:46 pm »
All your zeners are the WRONG way round   :palm:
oooops. :palm: :-BROKE :-DD

ps, why bother with 12v, you can run the piezo in a push pull configuration using two micro pins or as is with a parallel inductor.
Alarm clocks run on 1.5v and there loud enough to wake you from sleep  :=\

You're right. Could you provide me an example schematic? (edit: for the micro pins, I don't know what they are...  :-//)
« Last Edit: March 25, 2014, 07:38:55 pm by mcinque »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: A piezo buzzer that affect the MCU behaviour
« Reply #17 on: March 26, 2014, 02:13:16 am »
From the datasheet http://www.farnell.com/datasheets/16471.pdf:
Resonant frequency in KHz 2.8±0.5 (2.3KHz to 3.2KHz)
Sound pressure level in dB Minimum 93 at 30 cm/12VDC

Quoting myself but after looking at the datasheet I wonder if they forgot to add the % after the ±0.5, that will make more sense giving you a resonant frequency in between 2786Hz to 2814Hz

Let us know what resonant frequency you found your buzzer to be.
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: A piezo buzzer that affect the MCU behaviour
« Reply #18 on: March 26, 2014, 03:03:24 pm »
ps, why bother with 12v, you can run the piezo in a push pull configuration using two micro pins or as is with a parallel inductor.

Yep.  You can just drive the piezo with two MCU pins and eliminate a bunch of parts.  You certainly have extra pins.  If you don't need the 12V for something else you could use a lower voltage battery pack also, and avoid the linear regulator losses mentioned.

 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #19 on: March 26, 2014, 07:43:41 pm »
Oh. I understand only now what he said with "two micro pins"... two MCU pins. Probably I'm an idiot.  :palm: :-DD

However I've tried first what miguelvp and Mr Smiley said about resonant frequency and volume with low voltages: I discovered that it's all about the resonant frequency. With a f.gen I've found the exact resonant freq of the buzzer and now it's very loud even with few volts (like Mr Smiley said about alarm clocks). No need for 12V to have a loud sound. Mr. Smiley has open my eyes with his

Alarm clocks run on 1.5v and there loud enough to wake you from sleep  :=\

You should consider that I'm still a noob in many fields, and my lack of knowledge make me thought that since a piezo buzzer with an internal oscillator IS NOT a loudspeaker (that require AC) or a piezo element, and that the internal circuitry limits it at a fixed frequency, so if I provide him 5VDC or 5VDC in PWM doesn't make any difference.

Still now, I can't understand how the buzzer can manage various frequency even if its piezo disc is drived from an internal oscillator and IS NOT directly connected to the external pins.

As always, the lack of knowledge make his victims (me); I want to thank you all for your thoughts and suggestions, I've learned a lot from yout advices and I hope to receive them again!.
« Last Edit: March 26, 2014, 08:58:29 pm by mcinque »
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: A piezo buzzer that affect the MCU behaviour
« Reply #20 on: March 27, 2014, 12:06:12 pm »
Hi mcinque,

Please allow me to post some advice with regards to drawing your schematic. There are a few rules of thumb that are useful when creating your schematic that will make sure other people will be able to read it easily. They're also useful for you if you look at your schematic a year from now and must figure it out.

*First, try to place power supply voltages at the top and ground at the bottom. Inputs at the left and outputs at the right. Your 7805 circuit does exactly that is very clear to read. On the other hand the in the circuit surrounding the Atmega voltage and ground terminals are placed in every direction possible.

*Secondly try to connect everything together if possible. If something goes to +5V, draw a line to the where the +5V wire is. If you place terminals all over your schematic it becomes hard to understand what is connected where. So minimize wires that end in a terminal.

*Finally, if possible, rearrange the pins in the symbol of your chips/microcontroller to make connections easier without wire having to cross everything. If you group voltage pins at the top, ground at the bottom that is a good start. Group the display pins

Attached is a small example that I quickly setup. It isn’t perfect and there are more ways to do it. Also normally I would spend time to rearrange the MCU pins too. My example is meant to help you understand what I mean.

Well hopefully this helps you along. Good luck!
 

Offline mcinqueTopic starter

  • Supporter
  • ****
  • Posts: 1129
  • Country: it
  • I know that I know nothing
Re: A piezo buzzer that affect the MCU behaviour
« Reply #21 on: March 27, 2014, 12:20:23 pm »
Many thanks Christe4nM!  I really appreciate your advices! I will try to follow them in my schematics! Thanks again for spending your time for me!
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: A piezo buzzer that affect the MCU behaviour
« Reply #22 on: April 11, 2014, 09:23:33 pm »
Piezo's are only loud at in a specific frequency range.
Ans since they are Voltage driven (they use very little current) you can use them on 3 or 5 volt easily if you buy the right ones.
The only detail you have is that a piezo also works inversed, if force is applied (by pushing or dropping your device), they generate (high) voltage.
That is why you commonly find a resistor over the piezo to create a small current of this voltage, since the energy of a piezo is low, a small load is enough to reduce the voltage drastically. The same applies to current transformers generating a ideally infinite voltage when they are open-looped, which is a theoretically infinite resistance.
I've never used diodes for piezos, you'll need fast esd diodes for this. (expensive)

Typically I use a transistor inverter circuit and a 1 M parallel resistor over the load. However, I also have a project where the piezo is directly on the mcu io (with a 1 M parallel resistor) and this works just fine. Not a high-end mcu though.
But, looking at EMC/FCC compatibility this might be an issue.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf