![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) | |
|
Quote:
Why don't you put the display routine in the ISR? So you don't need bother about the displaying.
__________________
Superman returns..
|
||
|
|
|
|
|
(permalink) |
|
Hi banansiong I’m not familiar with much more ISR.
I applied your codings too replacing the goto SHOW with goto $-1 after btfss command. That worked well but within the button pressed time the whole display is going off that is better without dimming the display. But I still trying to have a smooth count in my coding without going to ISR. Any suggestions will be greatly appreciated. |
|
|
|
|
|
|
(permalink) |
|
It's worthwhile to ask just what's so bad about making a debounce period longer than necessary? Well, if it's too long a second press would get interpreted as a bounce and ignored. But then who presses a button 10 or even 5 times a second? Probably advancing through a list of mp3 tracks or scrolling down a display, or- wait I know- advancing the alarm on a digital clock once you've let off the spin it does when you hold it down and need to step it minute-by-minute. Not sure how fast those are. Note that some buttons won't even pop back up fast enough to be pressed at such a frenetic pace.
Sometimes you get a crappy button in a bag of them, or one gets bouncier as it ages. As such it may be a good idea to figure out at what point is it possible that the debounce time will miss valid presses and set it substantially less than that, so it can be as tolerant as possible to bouncing.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
|
|
|
|
|
|
(permalink) |
|
You can use your show routine as a debounce delay.
Code:
loop call SHOW btfsc PORTA,0 goto loop; not pressed so wait ; is pressed call COUNTUP loop1 call SHOW btfss PORTA,0 goto loop1; still pressed, so wait goto loop |
|
|
|
|
|
|
(permalink) | |
|
Quote:
The other possibility is to have a timer that expires say every 25mS. The timer ISR decrements the debounce timer and reenabled the button at zero. So when you detect a press you might set the counter to 3 for a 75mS debounce time. Downside is that the period of the first count is uncertain because the counter is already running when the button is pressed- it might make a debounce period of 51mS to 75mS in this case. Frequent interrupt tend to eat up the processing time esp if you're running low freq clocks. They also mean you can't use SLEEP mode mid-code to save power. We could pull a trick to disable the timer if no debounce counter needs to be decremented, a really good idea actually, you just need to be very careful with what you're doing.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
||
|
|
|
|
|
(permalink) |
|
Wow what a piece of code Mike I will try your coding & tell the progress.It should work for sure.
Thanks Mike. |
|
|
|
|
|
|
(permalink) |
|
Thanks Oznog I'm going to study your codings as soon as possible.
|
|
|
|
|
|
|
(permalink) |
|
Use Pommie's code, for sure the displays won't turn off or dim or get crazy
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
Oznog,
I've discovered and developed some relatively simple and reliable methods for debouncing and managing multiple switches over the last few years. Would you mind if I share them with you? First, I use relatively simple switch state latch logic for managing one to eight switches (in parallel). Using a switch state latch allows you to process and act on a "new" debounced switch press or a "new" debounced switch release while ignoring the remaining portion of a switch cycle (how long the switch is pressed or released). Code:
;
SWKEYS equ 0x20 ; debounced switch bits, '1' = pressed
SLATCH equ 0x21 ; switch state latch
SWITCH equ 0x22 ; switch flag bits for MAIN
;
; this routine transfers a new debounced switch press to the SWITCH
; variable for MAIN
;
ISR_Switch_Press
movf SWKEYS,W ; debounced switch bits
xorwf SLATCH,W ; each '1' is a change (press or release)
andwf SWKEYS,W ; each '1' is a "new" switch press
xorwf SWITCH,F ; toggle switch flag bits for use by MAIN
movf SWKEYS,W ; update switch state latch
movwf SLATCH ;
;
; this routine transfers a new debounced switch release to the SWITCH
; variable for MAIN
;
ISR_Switch_Release
movf SWKEYS,W ; debounced switch bits
xorwf SLATCH,W ; each '1' is a change (press or release)
andwf SLATCH,W ; each '1' is a "new" switch release
xorwf SWITCH,F ; toggle switch flag bits for use by MAIN
movf SWKEYS,W ; update switch state latch
movwf SLATCH ;
Code:
;
; test "UP" switch
;
Test_UP btfss sw_UP ; is SWITCH,0 a '1' (new switch press)?
goto Test_DOWN ; no, branch, else
bcf sw_UP ; clear bit so we don't process again
; perform "UP" code here
;
We can also use our standard momentary push button switches to emulate toggle switches. That is, press a switch to toggle the switch flag bit from on-to-off or from off-to-on. This is extremely handy for lighted push button switches. Push it once to light the LED then push it again to toggle the LED off. In this case the only difference in the way you process the switch in MAIN is that you don't need to clear the switch flag bit after testing it. It gets toggled automatically in the ISR after each "new" press. Code:
;
; test SET mode toggle switch flag
;
SET btfss sw_SET ; is SWITCH,1 a '1' (SET mode on)?
goto NextProc ; no, branch, else
;
; perform SET functions in SET_loop
;
SET_loop
;
; has SET mode been turned off
;
btfsc sw_SET ; SET switch still on?
goto SET_loop ; yes, continue SET operations, else
;
; save any changes and exit
;
Code:
;
SWKEYS equ 0x20 ; debounced switch bits, '1' = pressed
SLATCH equ 0x21 ; switch state latch
SWITCH equ 0x22 ; switch flag bits for MAIN
BEEP equ 0x23 ; beep timer
;
; process "new" debounced switch "presses"
;
ISR_Switch_Press
movf SWKEYS,W ; debounced switch bits
xorwf SLATCH,W ; each '1' is a change (press or release)
andwf SWKEYS,W ; each '1' is a "new" switch press
;
skpz ; any "new" presses? no, skip, else
bsf BEEP,5 ; send short 32-msec 500-Hz "beep"
;
xorwf SWITCH,F ; toggle switch flag bits for use by MAIN
movf SWKEYS,W ; update switch state latch
movwf SLATCH ;
;
; BEEP routine (500-Hz when using 1 msec interrupts)
;
movf BEEP,W ; beep timer set?
bz ISR_Next ; no, branch, else
movf PORTA,W ;
xorlw 1<<SPKR ; toggle SPKR port bit in W
movwf PORTA ; toggle actual SPKR pin
decf BEEP,F ; decrement beep timer
;
ISR_Next
The important thing to note about this code and method is that it simply tests the switches during each 1 msec interrupt and doesn't tie up the processor unnecessarily by waiting for a switch to change state. I've also developed some similarly "tight" code for implementing multiple independant debounce timers (which work on both press and release), repeat timers, etc., but they use vertical counters which seems completely alien to most people so I won't impose those algorithms on you folks at this time (grin). Regards, Mike Last edited by Mike, K8LH; 4th August 2007 at 01:29 AM. |
|
|
|
|
|
|
(permalink) |
|
Here the request pics of a my tact switch during release. When zoomed out the button press always looks very clean. Yet its a different story when a 1 GS/s digital scope is called into action on the front line
![]()
__________________
I can still log in! Delete my account and all my post now. |
|
|
|
|
|
|
(permalink) |
|
Pommie,
I tried to send you a PM but your inbox is full. Len
__________________
Len |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| odd project, 1 button adds a light 1 button takes a light away with sound. | KevinAlaska | Electronic Projects Design/Ideas/Reviews | 15 | 6th June 2007 04:38 AM |
| Please help me in writing code | abdosat2000 | Micro Controllers | 9 | 5th June 2007 01:40 PM |
| 1 Hour Timer PIC 16F628A (Set Button) | Suraj143 | Micro Controllers | 11 | 26th April 2007 03:54 AM |
| button midi keyboard | jjjjjj | General Electronics Chat | 2 | 20th March 2006 04:10 PM |
| Push Button On/Off power to PIC | eblc1388 | Micro Controllers | 8 | 17th February 2006 01:31 PM |