Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

switches 'sticking' - debounce routine problem?

Status
Not open for further replies.

tempus

Member
Hey all;

I've built a switching unit around a PIC16F737. There are 14 switches, each going to a different pin on the PIC. Most of the time, things work fine, but every once in a while a switch may stick - IOW, it gets pressed, the proper result is obtained, but all the other switches are non-responsive. Most of the time I can get everything to work again by pressing the 'stuck' switch again, but sometimes I have to power down and restart. Also, I've found that I can make the switch 'stick' if I press it gently and release it very slowly (although it may stick under normal pressing conditions as well). It's possible that my switches suck, but I'm wondering if it's a code thing. Here's my switch debounce code:

Code:
db_down		movlw	0x1A			;max count = 20ms/768us = 26 = 0x1A
			movwf	dbcount
			clrf	dc1				;reset dc1
dn_dly		incfsz	dc1,f			;delay 256x3 = 768us
			goto	dn_dly
			btfsc	PORTE,3			;if button up (RE3 hi),
			goto	db_down			;	restart count
			decfsz	dbcount,f		;else repeat until max count is reached
			goto	dn_dly

dbcount and dc1 are counters. Can anyone see anything wrong with this? I'm pretty sure it's actually working, although I've been having doubts as I look more at it. For instance, if I held the switch down, wouldn't the PIC get caught in this loop and never get to the actual instructions?

Thanks
 
hey guyz,i have a problem on the program i'm tryin' 2 write,i'm using MPLAB IDE and i'm programing a PIKkit2,this programm is suppose 2 increment a count and when i press down the switch on the DEMO BOARD it suppose to stop and when i press again the button it suppose to continue with the count but i have problem on stoping the count.
 
hey guyz,i have a problem on the program i'm tryin' 2 write,i'm using MPLAB IDE and i'm programing a PIKkit2,this programm is suppose 2 increment a count and when i press down the switch on the DEMO BOARD it suppose to stop and when i press again the button it suppose to continue with the count but i have problem on stoping the count.

Hi bheki, Your problem is easy and looks common, but It would be better to start your own thread to get answers.
 
Last edited:
i'm sori man, i didn't know how to start my own thread previously. but now i think i can but there is still one problem how do i upload my source code.
 
Last edited:
i'm sori man, i didn't know how to start my own thread previously. but now i think i can but there is still one problem how do i upload my source code.

Although that's need another new thread since know you've spoiled the original thread here, but I'll answer your question. You have to put your code between two words (CODE) YOUR CODE (/CODE) using [ ] brackets insted of ( ) brackets and the real code instead of YOUR CODE
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top