Disconnecting piezo from circuit stops program running

Celestialsphere

New Member
Hello All.

Apologies if this has been asked before but I have a issue with a piezo speaker.

I am testing a simple morse code beeper connected to a Picaxe 08.

The program uses the command: sound 2,(90,12) and works fine if the piezo is connected, but if I disconnect the piezo the program stops at the 'sound' command line. I know the program stops here because it sends a debug variable correctly from the line before.

Any ideas what is happening here?

Cheers

Andrew,

Melbourne, Australia
 

Circuit

Senior Member
Andrew, I think that we need to see your code and schematic before we can possibly comment. Can you post it please? Then perhaps the forum can help you. Clearly it makes no sense for the mere disconnection of a piezo speaker on output pins to disrupt the programme flow within a PICAXE.
 

rossko57

Senior Member
A recent thread along the lines of "funny things happen with this connected or disconnected" ran to four pages, before it was found the Picaxe serin pin had been left floating.
 

westaust55

Moderator
Guessing in the absence of a schematic and photo, but have you verified that you do have power to the PICAXE Vcc and Gnd/0V pins when the piezo is disconnected. That is, check the piezo is not providing a "phantom" circuit to complete the power supply.
 

nick12ab

Senior Member
Do you have a decoupling capacitor fitted?

If yes, or fitting one didn't fix the problem, a schematic and photo is required.
 

Celestialsphere

New Member
Sorry for the delay - sometimes life just gets in the way.

Here's my circuit diagram

Morse Code Circuit Diagram.jpg

I have solved the problem. In writing my program I accidently assigned two separate Symbols to the same pin 2, first to "STOP_BUTTON" which was to be a button which would stop the loop in "morse_SPMBC:" when the pin went high. The second assignment was to "SPEAKER" to sound the piezo. The button was not installed on the breadboard for the test but the piezo was installed. I presume the piezo keeps the pin low until it's disconnected in the middle of the loop in "morse_SPMBC:" When the piezo is disconnected I presume the pin must go high and trigger the "STOP_BUTTON" line sending the program to "WaitToStart:".

Code:
; -----[ I/O Definitions ]-------------------------------------------------

Symbol LIGHT = 4                                                	; Output pin connected to an LED on pin 4 (Leg 3)
Symbol COMMENCE = pin1                                          	; Input pin1 connected to momentary push button
Symbol STOP_BUTTON = pin2							; Input pin2 connected to momentary push button
Symbol Speaker = 2                                             	; Play a note on pin 3 connected to piezo 

; -----[ Variables ]-------------------------------------------------------

symbol Length_DIT = b2
symbol Length_DAH = b3
symbol Length_Between_Light = b4
symbol Length_Between_Letter = b5

; -----[ Constants ]-------------------------------------------------------

let Length_DIT       		= 120							; Time in milliseconds                                       
let Length_DAH     		= 240
let Length_Between_Light   	= 500
let Length_Between_Letter 	= 750

; -----[ EEPROM Data ]--------------------------------------------------

 
; -----[ Initialization ]------------------------------------------------------

let pins = 0                                                                    ; Reset all outputs to low
b0 = 0
b1 = 0                                                                          

; -----[ Program Code ]----------------------------------------------------

WaitToStart:

 
b0 = 0
If COMMENCE = 1 and STOP_BUTTON = 0 then morse_SPMBC				; wait for the commence button to be pressed. When it is pressed start the action !
goto WAITTOSTART                                                                                     ; or keep waiting...
                                

morse_SPMBC:

for b0 = 0 to 20

	if STOP_BUTTON = 1 then goto WAITTOSTART					; if the Stop button is oressed then go to the stat and wait.
  
	lookup b0,(1,1,1,3,1,2,2,1,3,2,2,3,2,1,1,1,3,2,1,2,1),b1                    ; twenty one actions

	select case b1                                                                            ; choose a case depending on the value of b1, i.e. if b1 = 3 then 'case 3' will be selected.

	case 1

            high LIGHT

            sound SPEAKER,(90,12)					; make a short 'Dit' sound

            low LIGHT

            pause 200

	case 2

            high LIGHT

            sound SPEAKER,(90,40) 					; make a long 'Dah' sound

            low LIGHT

		pause 300

	case 3

            pause 480                                                      ; The longer pause

	end select

next b0

goto WAITTOSTART

end

If I remove any references to the "STOP_BUTTON" I can disconnect piezo at any time and the program still continues to run (just flashing the morse LED) until the end.
I have also added four extra lines in "WaitToStart:" to make the LED flicker proving that the program is sitting waiting here.

Code:
; -----[ I/O Definitions ]-------------------------------------------------

Symbol LIGHT = 4                                                	; Output pin connected to an LED on pin 4 (Leg 3)
Symbol COMMENCE = pin1                                          	; Input pin1 connected to momentary push button

Symbol Speaker = 2                                             	; Play a note on pin 3 connected to piezo 

; -----[ Variables ]-------------------------------------------------------

symbol Length_DIT = b2
symbol Length_DAH = b3
symbol Length_Between_Light = b4
symbol Length_Between_Letter = b5

; -----[ Constants ]-------------------------------------------------------

let Length_DIT       		= 120							; Time in milliseconds                                       
let Length_DAH     		= 240
let Length_Between_Light   	= 500
let Length_Between_Letter 	= 750

; -----[ EEPROM Data ]--------------------------------------------------

 
; -----[ Initialization ]------------------------------------------------------

let pins = 0                                                                    ; Reset all outputs to low
b0 = 0
b1 = 0                                                                          

; -----[ Program Code ]----------------------------------------------------

WaitToStart:

 
b0 = 0
If COMMENCE = 1 then morse_SPMBC				; wait for the commence button to be pressed. When it is pressed start the action !
high LIGHT
pause 40
low light
pause 40
goto WAITTOSTART                                                      ; or keep waiting...
                                

morse_SPMBC:

for b0 = 0 to 20

	lookup b0,(1,1,1,3,1,2,2,1,3,2,2,3,2,1,1,1,3,2,1,2,1),b1     ; twenty one actions

	select case b1                                               ; choose a case depending on the value of b1, i.e. if b1 = 3 then 'case 3' will be selected.

	case 1

            high LIGHT

            sound SPEAKER,(90,12)					; make a short 'Dit' sound

            low LIGHT

            pause 200

	case 2

            high LIGHT

            sound SPEAKER,(90,40) 					; make a long 'Dah' sound

            low LIGHT

		pause 300

	case 3

            pause 480                            ; The longer pause

	end select

next b0

goto WAITTOSTART

end

I hope this rather long winded explanation helps someone.

Thanks everyone!

Cheers

Andrew
 

geoff07

Senior Member
A piezo is a very high impedance device so I doubt it is going to make any difference to the pin voltages. They work by resonating at around 3kHz due the varying voltage across the crystal, but they don't draw measurable current. The Picaxe can hardly detect that it is connected.

Possible explanations:

- something else got changed on the breadboard
- it looks like a piezo, quacks like a piezo, but it isn't actually a piezo, rather a low impedance buzzer with some other kind of interaction with your circuit.
- ??
 

hippy

Ex-Staff (retired)
A piezo is a very high impedance device so I doubt it is going to make any difference to the pin voltages ... The Picaxe can hardly detect that it is connected.
I suspect the connected piezo will be enough to hold the pin low when read as an input and the pin will float when not connected.
 

geoff07

Senior Member
Essentially I think they act at DC as a very low leakage (megs) capacitor. How that might interact with a cmos high impedance input pin is debateable. I feel an experiment coming on. But I can't find a piezo so it will have to wait.
 

MikeM100

Member
Bear in mind that a piezo can generate quite high voltages when physically 'tapped'. I once designed a PIC based product and had reports of the product not working after installation in the field. In the end it was diagnosed as voltage spikes from the piezo actually damaging the PIC itself !!

Might be worth experimenting with (say) a 1k resistor in series with the piezo (to ensure internal protection diodes to work) and a 1M across the piezo ? (to define pin state)

Just a thought ?
 

tmfkam

Senior Member
It may be a Piezo with an internal oscillator. These are still high impedance, but much less than a plain piezo. I had some that I was sure were plain piezo elements that I drove using PWM successfully but only later found out they were in fact oscillator types. They would 'buzz' irrespective of which way round they were attached to the PWM output. I only found out when I was measuring the current drain that seemed excessive.

Connect the red/black leads of the piezo to 5V. If they buzz by themselves, they've got an oscillator hidden inside them.
 

inglewoodpete

Senior Member
Despite all the discussion above, I don't think the problem has actually been solved yet. I suspect that Leg 8 (0v) is not connected to the 0v supply properly.
 
Top