switches

barneydog

Member
Hi,

I'm sure this is straight forward, and one of you wizards will tell me instantly...

i have 2 tactile switches on my circuit, do i need to debounce them with a picaxe or can they just be left how they are straight connected...

longest any button will be pressed is 2 seconds. and no matter how long its pressed the same result happens.

button 1 pressed - counter starts
button 2 pressed counter stops
depending on the count does X or Y
resets counter
goes back to start

thanks in advance and i hope i have given enough info :p
 

Adamey

Senior Member
Connect them to your PICAXE and use software debouncing. Manual 3 pages 26-27 show everything you need to know.
 

westaust55

Moderator
I recognise that the PICAXE manual 3 gives pauses of 100 ms which is to be on the really safe side and in human terms still not very long.

I found this website
http://www.ganssle.com/debouncing.htm
amongst others on the topic of switch contact bounce where the guy has supposedly performed 300 tests on numerous switches for open and close times.

Seems that with a couple of exceptions the typical worst case results were less than 6.5 msec.

So in theory the PAUSE 100 could be reduced to something like PAUSE 50 and still give a good safety margin.
 

william47316

New Member
or you can do a nested if which traps in a loop until the button is released eg
buttonloop:
if inputx = 1 then
if inputx = 0 then routine
goto buttonloop
uses a bit of space but means you can hold the button down for any period then release and it does the function
 

MartinM57

Moderator
do i need to debounce them with a picaxe or can they just be left how they are straight connected...
Always good to debounce switches - but I'm not sure your requirement needs it. You seem to just want to do something on the initial press of two independent buttons. Just work through your requirement and code logic and see if it can be affected by switch bounce occurring on either switch for, say 10mS, after the initial press.

If you were counting the number of switch presses then bounce would obviously cause a problem - one press could cause multiple counts.

If you were toggling a LED on each key press then bounce could cause a problem - if you got, effectively, two switch presses (the actual and one bounce) then you would get a double toggle i.e. no net change.

But if you are turning something on with one key and off with another then maybe bounce wouldn't be a problem?


..or you could just go, in the first instance, with an external RC filtering method (despite what Mr. Ganssle says)
 

barneydog

Member
what im trying to make is a gatso camera... for an rc truck layout...

switch one when wheel presses it, starts a count...when switch 2 is pressed it stops the count

if count is lower than a certain amount it then flashes an led twice and a small pin hole camera is activated twice.

i have added the pause 100 into the code and it makes no difference to speed in the slightest....everything seems to be running perfectly..

many thanks for all your replies :cool:
 

eclectic

Moderator
what im trying to make is a gatso camera... for an rc truck layout...

switch one when wheel presses it, starts a count...when switch 2 is pressed it stops the count

if count is lower than a certain amount it then flashes an led twice and a small pin hole camera is activated twice.

i have added the pause 100 into the code and it makes no difference to speed in the slightest....everything seems to be running perfectly..

many thanks for all your replies :cool:
Sounds interesting.
Please tell us more. :)


e
 

barneydog

Member
sorry for delay heres what i have so far on the code...

delays need some tweaking, but cant do that till i have have a test circuit to try it out on and the camera

Code:
'Gatso Speed Camera
'Pin 1 - first trigger
'Pin 3 - second trigger
'Pin 0 - flash
'Pin 4 - pin hole camera


symbol varF = b5


let dirs = %00010101


main:
label_60:	let pins = 0	' %00000000
		if pin1 = 1 and pin3 = 0 then label_62	'Decision command
		goto label_60

label_62:	pause 100	'Wait command
label_54:	let varF = varF + 1	'Inc command
		pause 200	'Wait command
		if pin3 = 1 then label_61	'Decision command
		goto label_54

label_61:	pause 100	'Wait command
		if varF <= 25 then label_51	'Compare command
		let varF = 0  	'Expression command
		goto label_60

label_51:	gosub prc_FLASHPICS	'Do Procedure 
		let varF = 0  	'Expression command
		goto label_60

prc_FLASHPICS:
		let pins = 1	' %00000001
		pause 200	'Wait command
		let pins = 0	' %00000000
		pause 200	'Wait command
		let pins = 1	' %00000001
		pause 500	'Wait command
		let pins = 0	' %00000000
		pause 500	'Wait command
		let pins = 16	' %00010000
		pause 1000	'Wait command
		let pins = 0	' %00000000
		pause 1000	'Wait command
		let pins = 16	' %00010000
		pause 1000	'Wait command
		let pins = 0	' %00000000
		return		'Return
 
Top