Pause Counter
Neoneuron
Posts: 9
Greetings!
I have a theory that the FOR counter = (first number) not only starts counting at that number, but is also the amount of delay. Is this correct? Because when I started counting using a WORD for room, and starting the counter = 800 to 900 the light flashed slower to begin with. Is this correct?
Also it seemed that the Bs2 stamp always adds 1ms to the delay for each time the program is run though FOR..NEXT is this correct?
Here is a copy of the program I ran with notes. Please correct me!
Thanks for any Help,
Neo
---
' ($Stamp BS2)
' {$PBASIC 2.5}
counter VAR Nib ' Equals number of counts Nib=15 Byte=255
' DEBUG "Program Running!"
'DO
FOR counter = 13 TO 50 ' Example: 13 is where you start
'counting. Also represents 13ms delay with 1 ms added
' In this case it will stop at nibble 15 (and reset itself
' to zero when it reaches its goal and goes to next?
DEBUG ? counter ' This was added to be able to
'watch the counts on the screen.
HIGH 15 ' red
LOW 14
PAUSE counter
LOW 15 ' Green
HIGH 14
PAUSE counter
LOW 15
LOW 14
PAUSE counter
NEXT
'LOOP
I have a theory that the FOR counter = (first number) not only starts counting at that number, but is also the amount of delay. Is this correct? Because when I started counting using a WORD for room, and starting the counter = 800 to 900 the light flashed slower to begin with. Is this correct?
Also it seemed that the Bs2 stamp always adds 1ms to the delay for each time the program is run though FOR..NEXT is this correct?
Here is a copy of the program I ran with notes. Please correct me!
Thanks for any Help,
Neo
---
' ($Stamp BS2)
' {$PBASIC 2.5}
counter VAR Nib ' Equals number of counts Nib=15 Byte=255
' DEBUG "Program Running!"
'DO
FOR counter = 13 TO 50 ' Example: 13 is where you start
'counting. Also represents 13ms delay with 1 ms added
' In this case it will stop at nibble 15 (and reset itself
' to zero when it reaches its goal and goes to next?
DEBUG ? counter ' This was added to be able to
'watch the counts on the screen.
HIGH 15 ' red
LOW 14
PAUSE counter
LOW 15 ' Green
HIGH 14
PAUSE counter
LOW 15
LOW 14
PAUSE counter
NEXT
'LOOP
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Again Thanks!
That is correct, because that is the way you programmed it. Your program code would sure enough flash slower starting with counter=800 than with counter=80, because of the "PAUSE counter" command.
In the snppet like this, the led flash will slow down:
counter VAR Word
FOR counter=100 to 1000
TOGGLE led
PAUSE counter ' <--- the pause and the rate of flashing depend on the current value of counter
NEXT
There are much much smaller effects having to do with the size of the variables. I should have said "the interpreter has to use fewer bits to store the address of a word than a nib, because it only takes 4 bits to address one out of 16 word locations in ram, versus 1 out of 64 nib locations. But the difference there is only a few microseconds.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
This behaves the same as the program that Tracy wrote, but it only uses a nibble for the counter.
Room VAR Word
For room = 800 to 900
··· .....
··· pause 100
next
Now you have· FOR loop with "fixed" delay of 100 ms.
When you use variable room as value to your pause it will naturally vary with the actual loop index.
Or better yet - do not use variable name·"counter"· if you really doing "delay".
Cheers
Vaclav