Newbie here and i seriously need some help with input's on the SX28
I just got my SX programmer today and have been messing with it, but I cannot get the inputs figured out!
I am attempting to make an up and down counter with a specific output, but for some reason, I just cannot get the inputs to read anything. I need to be able to send a positive signal to an input and it add "1" to variable my_counter, then gosub to process the new value.
I set the chip to delay before each new setting to test if the outputs even worked. They do, but if 2 outputs are on at the same time, one is LED is brighter than the other. Any way to fix that?
Any help would be greatly appreciated!
I am attempting to make an up and down counter with a specific output, but for some reason, I just cannot get the inputs to read anything. I need to be able to send a positive signal to an input and it add "1" to variable my_counter, then gosub to process the new value.
I set the chip to delay before each new setting to test if the outputs even worked. They do, but if 2 outputs are on at the same time, one is LED is brighter than the other. Any way to fix that?
Any help would be greatly appreciated!

Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
I am using RB.0 and RB.1 as the positive output going to an LED then to ground for testing purposes for now.
RA.0 and RA.1 are the inputs that are supposed to add(RA.0) or subtract (RA.1)
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "FOR-NEXT" level_up PIN RA.0 INPUT level_down PIN RA.1 INPUT sol_a VAR RB.0 sol_b VAR RB.1 TRIS_sols VAR TRIS_B TRIS_levelselect VAR TRIS_A level VAR Byte newlevel VAR Byte PROGRAM Start Set_level SUB 1, 1 Start: TRIS_sols = %11111100 level = 1 Main: Set_level 1 IF level_up = 1 THEN level = level + 1 IF level >= 4 THEN level = 4 ENDIF Set_level level ENDIF IF level_down = 1 THEN level = level - 1 IF level <= 1 THEN level = 1 ENDIF Set_level level ENDIF GOTO Main Set_level: newlevel = __PARAM1 IF newlevel = 1 THEN sol_b = 1 sol_a = 1 ENDIF IF newlevel = 2 THEN sol_b = 0 sol_a = 1 ENDIF IF newlevel = 3 THEN sol_b = 0 sol_a = 0 ENDIF IF newlevel = 4 THEN sol_b = 1 sol_a = 0 ENDIF RETURNNote, too, that you should have pull-downs on your input pins.
Post Edited (JonnyMac) : 1/15/2008 2:18:24 AM GMT
Main: level = level + level_up ;; wont increase if not level_up level = level - level_down ;; wont decrease if not level_down IF level >= 4 THEN level = 4 ENDIF IF level <= 1 THEN level = 1 ENDIF Set_level level ;; <set an appropriate pause here> GOTO Main-Benoit
Main: IF level_up THEN level=level+1 DO pause 100 ;; adjust until the input is properly debouced LOOP WHILE level_up=1 ENDIF IF level_down THEN level=level - 1 DO pause 100 ;; adjust until the input is properly debouced LOOP WHILE level_down=1 ENDIF IF level >= 4 THEN level = 4 ENDIF IF level <= 1 THEN level = 1 ENDIF Set_level level PAUSE 100 GOTO MainThis is almost straight out of Jon's book, Practical SX/B (page 67)
-Benoit
' ========================================================================= ' ' File...... ' Purpose... ' Author.... ' E-mail.... ' Started... ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Conditional Compilation Symbols ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42 FREQ 4_000_000 ID "Name" ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- BtnUp PIN RA.0 INPUT BtnDn PIN RA.1 INPUT UnusedRA2 PIN RA.2 INPUT PULLUP UnusedRA3 PIN RA.3 INPUT PULLUP SolA PIN RB.0 OUTPUT SolB PIN RB.1 OUTPUT UnusedRB2 PIN RB.2 INPUT PULLUP UnusedRB3 PIN RB.3 INPUT PULLUP UnusedRB4 PIN RB.4 INPUT PULLUP UnusedRB5 PIN RB.5 INPUT PULLUP UnusedRB6 PIN RB.6 INPUT PULLUP UnusedRB7 PIN RB.7 INPUT PULLUP UnusedRC PIN RC INPUT PULLUP ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- IsOn CON 1 IsOff CON 0 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- level VAR Byte scan VAR Byte incLevel VAR scan.0 decLevel VAR scan.1 tmpB1 VAR Byte ' work vars tmpB2 VAR Byte tmpW1 VAR Word ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine / Function Declarations ' ------------------------------------------------------------------------- DELAY_MS SUB 1, 2 SET_LEVEL SUB 1, 1 SCAN_BUTTONS FUNC 1, 0 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: level = 1 Main: SET_LEVEL level scan = SCAN_BUTTONS IF level < 4 THEN level = level + incLevel ENDIF IF level > 1 THEN level = level - decLevel ENDIF DELAY_MS 100 ' minimum loop delay DO scan = SCAN_BUTTONS LOOP UNTIL scan = %00 ' force button release GOTO Main ' ------------------------------------------------------------------------- ' Subroutine / Function Code ' ------------------------------------------------------------------------- SUB DELAY_MS IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ELSE tmpW1 = __WPARAM12 ENDIF PAUSE tmpW1 ENDSUB ' ------------------------------------------------------------------------- FUNC SCAN_BUTTONS tmpB1 = %11 FOR tmpB2 = 1 TO 5 tmpB1 = tmpB1 & RA DELAY_MS 5 NEXT RETURN tmpB1 ENDFUNC ' ------------------------------------------------------------------------- SUB SET_LEVEL tmpB1 = __PARAM1 IF tmpB1 = 1 THEN SolB = IsOn SolA = IsOn ELSEIF tmpB1 = 2 THEN SolB = IsOff SolA = IsOn ELSEIF tmpB1 = 3 THEN SolB = IsOff SolA = IsOff ELSEIF tmpB1 = 4 THEN SolB = IsOn SolA = IsOff ELSE ' fix level error SolB = IsOn SolA = IsOn level = 1 ENDIF ENDSUB ' ------------------------------------------------------------------------- ' User Data ' -------------------------------------------------------------------------Post Edited (JonnyMac) : 1/15/2008 3:16:33 AM GMT
You could fix this in hardware or software. Both are handy ways to know....Got down the software path first....at some point you may run out of timing to do the waits/whiles to get rid of the 'bounciness' and you would have to revert to hardware.
For interests sake, you could connect a pull-up resistor to your switch and then put a capacitor across the switch. What you are doing is making what's called an RC circuit (R for resistor; C for Capacitor), which is basically a delay type of circuit or filter. There are some calculations you could make to determine what either should be....personally, I'd just use an appropriate pullup resistor, like Jon suggest, then pick a capacitor that works for you (this is easily done if you have an oscilloscope!).
The other way to debounce a circuit (and really the better way IMHO - unless you DO have noise; then the RC could act as a filter as well) is to use a schmitt trigger.
You set up your switch the same way (pull-up resistor, cap in parallel with switch - ~10nF) then where the resistor and the switch/cap join, you connect the input of a schmitt
Actually, here's a webpage for future reference...
www.all-electric.com/schematic/debounce.htm
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<FONT>Steve
What's the best thing to do in a lightning storm? "take a one iron out the bag and hold it straight up above your head, even God cant hit a one iron!"
Lee Travino after the second time being hit by lightning!
One more thing..... I need to be able to drive a 15vdc 10 amp motor with the sx-28 chip. What would be the best way to drop the power down to not burn up the chip, but still send as much voltage to the motor that i can from one power supply. I was thinking of putting a resistor before the chip and using an NPN transistor rated at 60v 15 amps to control the power. Is that a good way to do it, or should I do something else?
Control the motor with FETs and SSR's maybe to isolate the sx.
Not very helpful, but haven't tried it....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<FONT>Steve
What's the best thing to do in a lightning storm? "take a one iron out the bag and hold it straight up above your head, even God cant hit a one iron!"
Lee Travino after the second time being hit by lightning!