Shop OBEX P1 Docs P2 Docs Learn Events
Please assist, cannot find reason for high pin 23 — Parallax Forums

Please assist, cannot find reason for high pin 23

KarmanKarman Posts: 4
edited 2011-02-28 07:57 in Propeller 1
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]

Comments

  • RaymanRayman Posts: 14,886
    edited 2011-02-27 14:47
    Please post the code with the "wrap [code]" options, so we can see the indentation.
    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
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-27 16:34
    All your arrays based on T_buttons have zero length. Highly unlikely that's what you want (an array is declared with the number of elements not some index magic). So since buttonDelay[0] is now the same as abuttonState[0] you'll get a 1 in bit 23 (buttonDelay[0] is initially 0, ++/-- will toggle its bit 0). Once you adjusted your array sizes make sure you keep the loop Finish parameter in sync.
  • RaymanRayman Posts: 14,886
    edited 2011-02-27 17:57
    good catch, that definitely looks like a problem...
  • KarmanKarman Posts: 4
    edited 2011-02-27 23:19
    Hi,

    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:

    _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 = 10
    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[i] := ina[button0]
    
        if but[i] == in
          debounce_time_ref[i] := debounce_delay + CNT
          ButtonDelay[i]++
        else
          buttondelay[i]--
    
    outa[23] := abuttonState[0] 
    
  • KarmanKarman Posts: 4
    edited 2011-02-27 23:24
    O yes,

    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:
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-27 23:26
    kuroneko wrote:
    ... make sure you keep the loop Finish parameter in sync.
    If an array is defined as long data[N] then the available indices are 0..N-1 which means your loop should run from 0..T_buttons-1.
    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[COLOR="red"]-1[/COLOR] ' check all 10 buttons
      ' but[i] := ina[button0]
    
        if but[i] == in
          debounce_time_ref[i] := debounce_delay + CNT
          ButtonDelay[i]++
        else
          buttondelay[i]--
    
    outa[23] := abuttonState[0] 
    
    If that doesn't solve the problem we simply keep looking. Note that local variables are not cleared to zero meaning your if but == in may be a bit of a gamble.
  • KarmanKarman Posts: 4
    edited 2011-02-28 07:57
    Thanks all!!
    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:
Sign In or Register to comment.