Searching \ for '[SX] Need Help With Switch De-Bounce' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/ubicom/devices.htm?key=sx
Search entire site for: 'Need Help With Switch De-Bounce'.

Exact match. Not showing close matches.
PICList Thread
'[SX] Need Help With Switch De-Bounce'
2006\05\18@205728 by NAGCSn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, NAGCS wrote:

Here is a project I started a few days ago for the XBOX 360 The circuit uses RGB LED's Port RA.3 is used for switching patterns or colors. 3 Lines on the RB Ports switch the grounds on the RGB LED's. Port RC Controls the common Postive terminal of the RGB LED. I am having a big problem with switch bounce when I press the button I want to go cleanly to the next pattern not jump around. I will show some pictures then show the code if any one can help It would be great.

http://www.newagepsx.com/images/uploads/3608.JPG

http://www.newagepsx.com/images/uploads/3606.JPG

http://www.newagepsx.com/images/uploads/3607.JPG


http://www.newagepsx.com/images/uploads/3609.JPG

http://www.newagepsx.com/images/uploads/innerringlight360.jpg


http://www.newagepsx.com/images/uploads/360cb1.JPG



http://www.newagepsx.com/images/uploads/360ip.JPG


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
Select  VAR RA.3   ' Pattern Select
TRIS_Sel VAR TRIS_A
Blue  VAR RB.0
Green  VAR RB.1
Red  VAR RB.2
Light  VAR RC
TRIS_Light VAR TRIS_C
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
Delay    CON 100   ' 180 ms between steps
Delay1  CON 80   ' 220 ms between steps
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
maxSteps VAR Byte   ' steps in sequence
idx  VAR Byte   ' step pointer
' =========================================================================
 PROGRAM Start
' =========================================================================
Pattern0:
 DATA  8
 DATA %11111110
 DATA %11111101
 DATA %11111011
 DATA %11110111
 DATA %11101111
 DATA %11011111
 DATA %10111111
 DATA %01111111
Pattern1:
 DATA  8
 DATA %01111111
 DATA %10111111
 DATA %11011111
 DATA %11101111
 DATA %11110111
 DATA %11111011
 DATA %11111101
 DATA %11111110
' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------
Start:
 Light = %00000000  
 TRIS_Light = %00000000
Main:
 PAUSE Delay
 HIGH Red
 READ Pattern0. maxSteps
IF idx <= maxSteps THEN S2_Go
 idx = 1
S2_Go:
 READ Pattern0 + idx, Light
 idx + idx + 1
 TOGGLE Red
 PAUSE 200
 HIGH Green
 READ Pattern0. maxSteps
IF idx <= maxSteps THEN S3_Go
 idx = 1
S3_Go:
 READ Pattern0 + idx, Light
 idx + idx + 1
 TOGGLE Green
 PAUSE 200
 HIGH Blue
 READ Pattern0. maxSteps
IF idx <= maxSteps THEN S4_Go
 idx = 1
S4_Go:
 READ Pattern0 + idx, Light
 idx + idx + 1
 TOGGLE Blue
 PAUSE 200
 IF Select = 0 THEN Main0
 PAUSE 50
 GOTO Main
Main0:
 PAUSE Delay1      
 HIGH Green
 READ Pattern0, maxSteps
 IF idx <= maxSteps THEN S5_Go
 idx = 1
S5_Go:
 READ Pattern0 + idx, Light
 idx = idx + 1
 PAUSE 25
 IF Select = 0 Then Main1          
 GOTO Main0
Main1:
 PAUSE Delay1      
 HIGH Blue
 READ Pattern0, maxSteps
 IF idx <= maxSteps THEN S6_Go
 idx = 1
S6_Go:
 READ Pattern0 + idx, Light
 idx = idx + 1
 PAUSE 25
 IF Select = 0 Then Main2        
 GOTO Main1
Main2:
 PAUSE Delay1      
 HIGH Red
 READ Pattern0, maxSteps
 IF idx <= maxSteps THEN S7_Go
 idx = 1
S7_Go:
 READ Pattern0 + idx, Light
 idx = idx + 1
 PAUSE 25
 IF Select = 0 Then Main3          
 GOTO Main2
Main3:
 PAUSE 200
 If Select = 0 THEN Main
 Light = %11111111
 GOTO Main3
---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=126640
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)

2006\05\20@143210 by Electronegativityn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Electronegativity wrote:

Hi NAGCS.

That project looks awesome!

The easiest thing to do is wait for a millisecond between checking to see if a key is pressed.
That is a conservative value and should work fine, but you can play around with reducing the delay to find out what the actual timescale of bouncing is.

Good Luck.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=126640#m126915
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)

2006\05\20@155543 by beann/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote:

Now there is someone who knows how to post a question. Nice job, described the exact problem, post ALL the code and even showed the PCB.

NAGCS,
 I see you have PAUSE 200, but I don't quite follow your select logic ?  Is select = 0 when the button is pressed or does it equal 1 when the button is pressed ?

BTW: If you download the latest version of SX/B you use IF...THEN...ENDIF blocks instead of all the GOTOs and labels. Also has DO...LOOP loops. Would make the code alot easier to follow.

Bean.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=126640#m126922
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)

2006\05\21@080346 by NAGCSn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, NAGCS wrote:

If Select = 0   Basicly means if there is a ground pulse or (0) on RA.3 switch to the next subroutine. I was wondering if PULSEIN would be a better command but I don't know how to use it right. I am just a beginner when it comes to SXBASIC I excell in the hardware aspect but programming is a struggle for me. Basicly when powered up the circuit displays the first routine. When the NO Push button is pressed a ground is sent to RA.3 sending it to the next routine. There is a 10k pull-up resistor on the input to B+. I was wondering also if I have the input circuitry right. I also tried a transistor debounce circuit with no betters results.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=126640#m127007
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)

2006\05\21@115346 by beann/a
flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote:

Okay, the part I don't understand is here:


S7_Go:
 READ Pattern0 + idx, Light
 idx = idx + 1
 PAUSE 25
 IF Select = 0 Then Main3          
 GOTO Main2
Main3:
 PAUSE 200
 If Select = 0 THEN Main
 Light = %11111111
 GOTO Main3




After the PAUSE 25, you are saying if the button is pressed then goto Main3.
So let's assume the button is pressed, now we are at Main3, if the user releases
the button during the PAUSE 200 you will be stuck in the Main3 loop forever.

Bean.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=126640#m127047
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...