The new Picaxe bug?

Consider this test code for Picaxe.

#picaxe40x2
#no_data
high 5
for w0 = 1 to 65535 next w0
high 6
for w0 = 0 to 65535 next w0
high 7

Please feed it to your Picaxe, whatever breed. Change the directive #picaxe.... accordingly or remove it. The directive #no_data just speeds up the program load.

Now tell me, how long does it take for the ports to go high (for the LEDs to light up)?

Here are my results.
picaxe 40x2 (firmware B.0): 5 immediately, 6 after about 57 seconds, pin 7 never went high
picaxe 28x1 (firmware A.3): 5 immediately, 6 after about 80 seconds, pin 7 never went high

What is going on here? The for...next that starts at 1 has no problem, the for...next that starts at zero never completes?!

running it in the sim, it
running it in the sim, it doesn’t even get to high 6. It stops at 32k on the first loop.

Add a step one…

Just curious,

for w0= 0 to 65535 step 1 next w0

and try

for w0= 0 to 65534 step 1 next w0

I don’t know picaxe from

I don’t know picaxe from shinola but how about this.

 

per the data sheet “When the end value is exceeded the looping stops”.

I take this to mean that the value is tested after it’s incremented. But 65535 plus one would leave 0 in the register, which is “start” again. Just a thought.

exceed
I take "exceed" to mean "be greater than". For the looping to stop, the var must be outside the specified range. Manual could be clearer.

step by step
Adding "step 1" makes no difference. A step value of 32768 greatly speeds up testing though.

Here: http://www.picaxeforum
Here: http://www.picaxeforum.co.uk/showthread.php?t=12602

use overflow

You can make use of this "bug". if you want to assign 65535 to w0: write it like this:

let w0=-1

Means the same thing and it shaves 1 (sometimes 2??) bytes of your program.