A piezo buzzer that affect the MCU behaviour - Page 1
Forum section: electronics / general

author: mcinque
author_rank: Unknown
timestamp: March 23, 2014, 10:54:10 pm
content: 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 doin hardwareto 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?

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 23, 2014, 11:38:46 pm
content: 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.

author: mcinque
author_rank: Unknown
timestamp: March 24, 2014, 12:34:06 pm
content: Thank you for the the replies.Quote from: Mr Smiley on March 23, 2014, 11:38:46 pmUnforunately 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.Quote from: Mr Smiley on March 23, 2014, 11:38:46 pmThe sound volume using the 12V piezo is fine and is loud enough. It's in the driving method where probably I'm missing something.Quote from: Mr Smiley on March 23, 2014, 11:38:46 pmI've tried in the past to use a resistor, I will try with a low value inductor. Ok for the frequency.Quote from: Mr Smiley on March 23, 2014, 11:38:46 pmIt's in his plastic resonant chamber.Quote from: AhhhChoo on March 24, 2014, 01:31:50 amAlready done, the schematic attached was only to describe the buzzer driveQuote from: AhhhChoo on March 24, 2014, 01:31:50 amI'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).

author: diyaudio
author_rank: Frequent Contributor
timestamp: March 24, 2014, 02:59:19 pm
content: Quote from: mcinque on March 23, 2014, 10:54:10 pmyou 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.

author: Rufus
author_rank: Super Contributor
timestamp: March 24, 2014, 03:25:01 pm
content: Quote from: mcinque on March 23, 2014, 10:54:10 pmA 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.

author: SeanB
author_rank: Super Contributor
timestamp: March 24, 2014, 06:41:11 pm
content: 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.

author: mcinque
author_rank: Unknown
timestamp: March 24, 2014, 10:11:14 pm
content: Quote from: AhhhChoo on March 24, 2014, 01:31:50 amYou're damn right, thanks

author: mcinque
author_rank: Unknown
timestamp: March 24, 2014, 10:43:52 pm
content: Quote from: SeanB on March 24, 2014, 06:41:11 pmLike this?p.s. I didn't understand where you suggest to place the zener. Could you please be more specific?

author: Zero999
author_rank: Super Contributor
timestamp: March 24, 2014, 11:12:28 pm
content: 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.

author: mcinque
author_rank: Unknown
timestamp: March 24, 2014, 11:15:53 pm
content: Quote from: Hero999 on March 24, 2014, 11:12:28 pmRight... I must have misunderstood SeanB suggestions...

author: mariush
author_rank: Super Contributor
timestamp: March 24, 2014, 11:41:06 pm
content: 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 anAP1509may 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.

author: Psi
author_rank: Super Contributor
timestamp: March 24, 2014, 11:54:24 pm
content: 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 frequencyYep, remove R4 and C7With 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)

author: han
author_rank: Frequent Contributor
timestamp: March 25, 2014, 12:09:58 am
content: 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.

author: miguelvp
author_rank: Super Contributor
timestamp: March 25, 2014, 12:13:20 am
content: From the datasheethttp://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

author: mcinque
author_rank: Unknown
timestamp: March 25, 2014, 06:44:44 pm
content: 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.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 25, 2014, 06:52:15 pm
content: All your zeners are the WRONG way roundThey 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

author: mcinque
author_rank: Unknown
timestamp: March 25, 2014, 07:25:46 pm
content: Quote from: Mr Smiley on March 25, 2014, 06:52:15 pmoooops.Quote from: Mr Smiley on March 25, 2014, 06:52:15 pmYou're right. Could you provide me an example schematic? (edit: for the micro pins, I don't know what they are...)

author: miguelvp
author_rank: Super Contributor
timestamp: March 26, 2014, 02:13:16 am
content: Quote from: miguelvp on March 25, 2014, 12:13:20 amQuoting 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 2814HzLet us know what resonant frequency you found your buzzer to be.

author: granz
author_rank: Regular Contributor
timestamp: March 26, 2014, 03:03:24 pm
content: Quote from: Mr Smiley on March 25, 2014, 06:52:15 pmYep. 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.

author: mcinque
author_rank: Unknown
timestamp: March 26, 2014, 07:43:41 pm
content: Oh. I understand only now what he said with "two micro pins"... twoMCUpins. Probably I'm an idiot.However I've tried first whatmiguelvpandMr Smileysaid about resonant frequency and volume with low voltages: I discovered thatit'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 hisQuote from: Mr Smiley on March 25, 2014, 06:52:15 pmYou should consider that I'm still a noob in many fields, and my lack of knowledge make me thought that since a piezo buzzerwith an internal oscillatorIS 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!.

author: Christe4nM
author_rank: Unknown
timestamp: March 27, 2014, 12:06:12 pm
content: 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 pinsAttached 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!

author: mcinque
author_rank: Unknown
timestamp: March 27, 2014, 12:20:23 pm
content: 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!

author: Jeroen3
author_rank: Super Contributor
timestamp: April 11, 2014, 09:23:33 pm
content: 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.