Shop OBEX P1 Docs P2 Docs Learn Events
CNT Confusion / Blinking LED Stalls — Parallax Forums

CNT Confusion / Blinking LED Stalls

biznodebiznode Posts: 2
edited 2012-04-23 07:52 in Propeller 1
I must be forgetting something basic about CNT but I'm not seeing it.

Running on a PropBOE, I'd expect the following to blink the LED continuously.

Every minute or so it stalls on or off for about 10 seconds.

What am I missing?

Thanks.

-- Al



CON
_clkmode = xtal1 + pll16x '80MHz operating frequency.
_xinfreq = 5_000_000
LED_HEARTBEAT = 3

var
long HeartbeatCnt
long HeartbeatInterval



Pub Start
DIRA[LED_HEARTBEAT] := 1
OUTA[LED_HEARTBEAT] := 1
HeartbeatInterval := clkfreq / 1000 * 50
HeartbeatCnt := Cnt + HeartbeatInterval


repeat
if Cnt > HeartbeatCnt
OUTA[LED_HEARTBEAT] := ! OUTA[LED_HEARTBEAT]
HeartbeatCnt := HeartbeatCnt + HeartbeatInterval

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-21 21:30
    CNT is a 32 bit unsigned number and > is a signed compare. You'll do better with
    HeartbeatCnt := CNT
    repeat
       if (CNT - HeartbeatCnt) > HeartbeatInterval
          !OUTA[LED_HEARTBEAT]
          HeartbeatCnt += HeartbeatInterval
    
  • pik33pik33 Posts: 2,398
    edited 2012-04-22 02:48
    cnt is going from $FFFFFFFF to $00000000 every 53 seconds
  • biznodebiznode Posts: 2
    edited 2012-04-23 07:37
    That was it.

    Thanks for your help.

    -- Al
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-04-23 07:52
    Here's another way to do that loop -- and you can do other things inside so long as the total timing doesn't take more than 50 ms
    pub start | t
    
      dira[LED_HEARTBEAT] := 1 
      outa[LED_HEARTBEAT] := 1
    
      t := cnt
      repeat
        !outa[LED_HEARTBEAT]
    
        ' other code here
    
        waitcnt(t += (clkfreq / 20))
    
Sign In or Register to comment.