Switch bounce problem...

wildbill

Member
Hi to all, I have a wee problem that i just cant figure out.
motor:
pause 1000 ;WAIT 1 SEC BEFORE START
let pins= %10000000 ;MOTOR STARTS ON O/P 7
if pin 6 = 1 then stall ;RECORD MICROSWITCH HIT, JUMP TO STALL
goto motor ;OR ELSE KEEP MOTOR RUNNING
stall:
let pins= %00000000 ;MOTOR OFF
pause 500 ;WAIT 1/2 SEC
let pins= %11000000 ;MOTOR 1 ON, 2 ON (WIRED TO REVERSE)
pause 2000 ;TURN FOR 2 SECS
let pins= %00000000 ;MOTORS OFF
pause 500 ;WAIT 1/2 SEC
goto motor ;START FROM BEGINNING
Here's the wee problem. when the microswitch gets a hit, it goes high, however, there is about a 1 second delay befor the program jumps to stall, i can only assume this is due to switch bounce. I have read the manual and it suggests a pause 100 delay, to de-bounce the switch. I need the pause 100 delay to come in as soon as the if....then part of the program receives a hit, but i'm pulling out what little hair i have left, to get it to work. Can anyone help before i go completely bald (not far to go). Rather than give me the code at this stage, it would be good to just give me a clue ( as YLP88 often does ) and let me try and work it out. The clue should not be " Find a shop in yellow pages that sells wigs " Many thanks in advance, almostbaldbill.



 

Edited by - wildbill on 1/20/2006 1:13:33 AM
 

andrewpro

New Member
If your using a picaxe that supports interrupts, try putting the microswitch on an interrupt. This will make it fire off as soon as the interrupt is polled, and you can deal with it separately in the interrupt section of code.

If your not using an interrupt capable picaxe, theres always the good ole RC debounce circuit.

It seems as though either your pauses are causing it not to register immediately, or your missing the switch hit at first as your program is cycling through.

I hope that's not too much cluing! hehe.
Good luck.

--Andy P
 

wildbill

Member
Thanks for the rapid response andy, i have 36 and a half left, i had 47 last night as i checked in the mirror !!. I'm using an 'axe 18 on a project board at the moment. I've not got to interupts yet as my programming skills are a bit new, i'll have a look at the command in the manual, i get your point on the programming "cycling" aspect that may be contributing to the delay, however, if i hit the microswitch rapidly, it sometimes doesn't even register a hit. i have to hold it in for a wee bit to get it to register, this is why i'm thinking it might be bouncing.

 

Edited by - wildbill on 1/19/2006 11:32:14 PM
 

premelec

Senior Member
1 second of bouncing in a switxh would be quite a feat! :)

Your program has a 1 second delay at the start in the loop... that is likely your trouble - change it to .1 seconds and try again. Ain't learning fun? :)
 

wildbill

Member
premelec, Sorted !!! I remove the start-up delay completely and it seems to be fine now. Of course, 1 second of "bouncing", 1 second delay at the start, that was definately a Homer Simpson moment.
NOTE: anyone who takes up programming should do so early in life as clearly when you do pull your hair out, it removes a large quantity of brain cells at the same time !!! Thanks to all. Widbill.

EDIT: I have put the start-up delay at the very beginning before the label motor:, i now have the delay and the initial problem solved.

 

Edited by - wildbill on 1/19/2006 11:53:03 PM

Edited by - wildbill on 1/20/2006 12:15:50 AM
 

Michael 2727

Senior Member
The easiest way I have found is to place a 0.1µF monolithic Cap across the switch contacts, you could go even bigger if needed.
Micro switches would be prone to more noise
than most switches due to the longer arm of
the switching contact. A folded "S" shape.
 
Top