Pic port pin weirded out by piezo buzzer - Page 1
Forum section: electronics / general

author: DTJ
author_rank: Super Contributor
timestamp: November 16, 2016, 06:22:08 am
content: I've got a port pin on an 18F25k22 directly driving a small Piezo buzzer.It works fine for a couple of different brands but fails with one particular brand of buzzer.When the pin goes high to turn the buzzer on (for a long beep) it sounds but it does not turn off when the pin is taken low - the pin stays high as if its locked up.If subsequent on-off commands are sent to the pin it sorts itself out - and turns off.After this the buzzer works fine for short button press "chirps".The micro is still running ok, it's just the piezo buzzer output pin that appears to latch up.This is the buzzer that fails:http://akizukidenshi.com/download/ds/spl/PB04-SE12HPR.pdf3-18V @ 10mAThis buzzer works OK:https://www.jameco.com/Jameco/Products/ProdDS/138713.pdf3-16V @ 7mALooking at the port pin with the CRO the pin is at 5V with 500mV negative going spikes every 250uS.I tried a few quick hacks to see if things changed, none of these had any effect on the behavior.1N4148 across the buzzer100nF across the buzzerConnecting to the buzzer via a 1N4148Connecting the buzzer via a 18R resistorThe easy solution is to use the buzzer that works - but It'd be nice to know why it's behaving badly.

author: tatus1969
author_rank: Super Contributor
timestamp: November 16, 2016, 06:34:54 am
content: I am always cautios connecting things directly to GPIO pins, this one reassures me. I guess that your bad piezo has large supply current transients when it tries to operate. Maybe they just were too optimistic with the 3V lower VDD specification. I recommend to use a BJT to drive that one, and to try higher voltages, maybe 5V if that is available in your circuit.EDIT. I see that you are already using 5V... the 100nF decoupling capacitor should always be there, close to the supply pins. You can consider the buzzer being a digital switching circuit.

author: Ian.M
author_rank: Super Contributor
timestamp: November 16, 2016, 07:09:02 am
content: You are, I hope, writing to the LAT bit, not the PORT bit?

author: DTJ
author_rank: Super Contributor
timestamp: November 16, 2016, 08:05:21 am
content: Quote from: Ian.M on November 16, 2016, 07:09:02 amI hope so Ian....I'm an XC8 noviceI define the buzzer output in my header file using:#define BUZZER PORTCbits.RC4 //OUT for buzzer driveAnd then set it or clear it:BUZZER = 1;orBUZZER = 0;Look correct?

author: DTJ
author_rank: Super Contributor
timestamp: November 16, 2016, 08:09:55 am
content: Quote from: tatus1969 on November 16, 2016, 06:34:54 amI also tried adding an additional 100nF decoupling across the micro power & ground but it made no difference. The micro is running @ 5V.I often use a little mosfet but the proto's worked fine driving direct. I just tried half a dozen boards with the "good" buzzer and they all worked fine. They just cost a little more.

author: mac.6
author_rank: Regular Contributor
timestamp: November 16, 2016, 08:17:03 am
content: Can you try to reverse buzzer connection: use the gpio as current sink instead of source. 18F25k22 has symetrical sink/sources capacities, but most micro have better sink capacities and even true open drain mode sometimes.

author: JPortici
author_rank: Super Contributor
timestamp: November 16, 2016, 08:20:46 am
content: Quote from: DTJ on November 16, 2016, 08:05:21 amnot really.use this#define BUZZER LATCbits.LATC4 //OUT for buzzer drive

author: DTJ
author_rank: Super Contributor
timestamp: November 16, 2016, 08:32:57 am
content: Quote from: JPortici on November 16, 2016, 08:20:46 amThanks JPortici and Ian. Feeling daft as I now recall the port/latch issue from years ago.I'll change it and see how it goes.

author: DTJ
author_rank: Super Contributor
timestamp: November 16, 2016, 10:25:52 am
content: Thanks for the help gents.Ian & JPortici - its fixed. I changed the output pin definitions to latch rather than port and the buzzers that previously latched up the port pin now work fine.