Please assist, cannot find reason for high pin 23
Karman
Posts: 4
Hi
Please can someone explain why below code make pin23 go high .... If i move the order of the Var's around, the pin sometimes go high, other times not..
I suspect that 1 variable is leaking accross to other, but cannot seem to figure out what... 6 hrs later.. i'm stump
any assistance much apprecaited
Liaan
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
' Set this to the pins you have connected to the 74HC595's
in = 1
T_buttons = 0
SR_CLOCK = 1
SR_LATCH = 2
SR_DATA = 3
button0 = 7
delay1 = 1 '1second
delay10 = 10 '10seconds
var
long temp
long delay
word out
long x
long butcnt
long abuttonState[T_buttons]
long buttonDelay[T_buttons]
long button_press[T_buttons]
long button_double[T_buttons]
long button_now[T_buttons]
long timeout
long button_last_down[T_buttons]
long debounce_time_ref[T_buttons]
PUB Main | i, button,led_state
dira[7]~ ' set buttons as in
dira[16..23]~~ ' set led's as out
abuttonState[0] := 0
delay := clkfreq * delay1 '1s
' temp := delay + CNT
repeat
doubleclick
Pub DoubleClick | butcnt2, xx, but_time ,i ,but[T_buttons],debounce_delay
delay := clkfreq * delay1
debounce_delay := clkfreq/1000 * 300 '30ms
repeat i from 0 to T_buttons ' check all 10 buttons
' but := ina[button0]
if but == in
debounce_time_ref := debounce_delay + CNT
ButtonDelay++
else
buttondelay--
outa[23] := abuttonState[0]
Please can someone explain why below code make pin23 go high .... If i move the order of the Var's around, the pin sometimes go high, other times not..
I suspect that 1 variable is leaking accross to other, but cannot seem to figure out what... 6 hrs later.. i'm stump
any assistance much apprecaited
Liaan
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
' Set this to the pins you have connected to the 74HC595's
in = 1
T_buttons = 0
SR_CLOCK = 1
SR_LATCH = 2
SR_DATA = 3
button0 = 7
delay1 = 1 '1second
delay10 = 10 '10seconds
var
long temp
long delay
word out
long x
long butcnt
long abuttonState[T_buttons]
long buttonDelay[T_buttons]
long button_press[T_buttons]
long button_double[T_buttons]
long button_now[T_buttons]
long timeout
long button_last_down[T_buttons]
long debounce_time_ref[T_buttons]
PUB Main | i, button,led_state
dira[7]~ ' set buttons as in
dira[16..23]~~ ' set led's as out
abuttonState[0] := 0
delay := clkfreq * delay1 '1s
' temp := delay + CNT
repeat
doubleclick
Pub DoubleClick | butcnt2, xx, but_time ,i ,but[T_buttons],debounce_delay
delay := clkfreq * delay1
debounce_delay := clkfreq/1000 * 300 '30ms
repeat i from 0 to T_buttons ' check all 10 buttons
' but := ina[button0]
if but == in
debounce_time_ref := debounce_delay + CNT
ButtonDelay++
else
buttondelay--
outa[23] := abuttonState[0]
Comments
Or, just attach the spin file.
One thing I see right away is that you don't initialize OUTA...
Right before your DIRA statement, you might try a OUTA:=0
thanks very much for responce..
I should not post questions at 12:30 am... I posted one of the many versions i tried to troubleshoot the same issue.
the orginal array size was 10. I created the variable array size to try and troubleshoot the problem.
When i remove the line: ButtonDelay++, pin28 don't go high. when i move long temp, and long delay to the bottom of var list., the pin28 randomly goes up / down.(seems to be linked by "cnt"offset)
at this time, my only guess is that buttondelay array is "leaking" into abuttonstate when delay value gets to big.
of course, i'm very new to spin, so can be on completely wrong path
L:
forgot to add, if i debug.dec(abuttonState[0]) it increments from 0-255 and then back to 0 the whole time. (debug code not added in above post as i removed it thinking maybe causing the problem)
L:
seems to be the -1 that caused all the #%*#$*
lesson learned
Will try post my final code when i eventually get my logic fixed
cheers
L: