HELP: Question regarding: IncrementUntilCondition.spin
danstock
Posts: 2
I am new to .spin programming. I am using the QuickStart board and uploading the examples but having some mixed results using the IncrementUntilCondition.spin . The program seems to continually count(flash) changing the conditional value to anything >than 7. If I use a value less than 8, the program seems to work as expected. Using a value of 8 or higher, it continues to flash the outputs. What am I missing?? see the code below.
''
'' File: IncrementUntilCondition.spin
PUB BlinkLeds
dira[16..18]~~
repeat until ++outa[16..18]==8
waitcnt(clkfreq/2+ cnt)
repeat
''
'' File: IncrementUntilCondition.spin
PUB BlinkLeds
dira[16..18]~~
repeat until ++outa[16..18]==8
waitcnt(clkfreq/2+ cnt)
repeat
Comments
the value outa[16..18] is 3 bits for values of 0-7. It will never get to 8.
Cluso99 already explained the problem, so what is the fix? I would opt for
When going into the loop outa[16..18] is 0. As it is pre-incremented, it will be 1 when comparison takes place.
When outa[16..18] is 7 the pre-increment will make it 0 again.
Another solution would be
repeat 8 will make the LEDs being off after the loop, repeat 7 would leave them on.
Please be aware, both rely on the fact that the going in situation is that those three outa bits are really 0, otherwise you won't see the full cycle. (same is true for your initial code)
If you don't want to rely on this fact, you'd better use
Again 8 turns the LEDs off in the last cycle, 7 leaves both LEDs on.
And what you really should try is using outa[18..16] instead! Nice to know those little differences in SPIN.
These nice examples really help in understanding you propeller & SPIN & PASM much better.