Stuttering led
Yianie
Posts: 49
I wrote a simple program to learn about the power of the RCTIME command. The problem is that the led I have connected stutters (HIGH 3). I was told from a friend familiar with STAMP2 that the program is running in a loop, but I don't get it. Why is the led stuttering when its on?
' {$STAMP BS2}
' {$PBASIC 2.5}
result VAR Word
HIGH 9
PAUSE 1
RCTIME 9, 1, result
DEBUG DEC ? result
IF result>1100 THEN
HIGH 3
ENDIF
' {$STAMP BS2}
' {$PBASIC 2.5}
result VAR Word
HIGH 9
PAUSE 1
RCTIME 9, 1, result
DEBUG DEC ? result
IF result>1100 THEN
HIGH 3
ENDIF
Comments
Why does it loop?
E.g.
Start by using named constants for pins and writing code in modules to the degree you can; this takes very little extra time and helps prevent errors.
Because you terminated the program with END (you don't even need to use the keyword for that to happen). When the BS2 hits END the internal watchdog timer stops getting reset; when it times out this will cause an outputs to be disabled for a moment. You'll note this is happening at a specific rate -- you're watching the watchdog repeatedly time out.
This is from END in the online manual:
During execution of power conserving commands (END, NAP, POLLWAIT, and SLEEP), current will occasionally be interrupted on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter firmware regains control of the processor, it restores the I/O direction dictated by your program.
Also, after a program ends, it's normal that your LED winks once every 2.3 seconds.
Another way to reduce the stutter electrically is to put a capacitor in parallel with the R+LED circuit at the Stamp output pin.