Hi,
Three months ago I posted a Code Snippet which has been "viewed" over 400 times. So I was a little surprised to discover recently that it totally "crashes" the PE6 Simulator and Editor 6.0.9.3 (at least I've found no way to recover from the "hang"). The snippet test harness works perfectly in the PE5 Simulator and a real PICaxe downloaded from PE6.
The cause is the program line for b1 = b1 to 255 step 16 which is rather unusual (and perhaps "risky") but was entirely intentional*. The potential issue is not the FOR b1 = b1 part (which is valid) but that in calculating if the "TO" value has been reached, the value might (will) overflow a single byte (which of course is all that b1 can contain). Thus the "end" condition might never be reached, which appears to be what's happening in the PE6 Simulator. However, normally the PICaxe interpreter calculates to a WORD resolution within any command (otherwise something like b1 = b1 * 250 / 251 wouldn't be calculated correctly) which appears to be happening in the real chips and PE5 Simulator.
* 255 seemed to be the only value that supports up to 16 iterations (loops) for the division routine, plus the four potential "flag" bits, within a single byte. Anybody have any better ideas? I guess the "counting" loop probably could be closed in some other way, but a FOR loop seems so much the "obvious" (self-documenting) and compact structure to use.
Cheers, Alan.
Three months ago I posted a Code Snippet which has been "viewed" over 400 times. So I was a little surprised to discover recently that it totally "crashes" the PE6 Simulator and Editor 6.0.9.3 (at least I've found no way to recover from the "hang"). The snippet test harness works perfectly in the PE5 Simulator and a real PICaxe downloaded from PE6.
The cause is the program line for b1 = b1 to 255 step 16 which is rather unusual (and perhaps "risky") but was entirely intentional*. The potential issue is not the FOR b1 = b1 part (which is valid) but that in calculating if the "TO" value has been reached, the value might (will) overflow a single byte (which of course is all that b1 can contain). Thus the "end" condition might never be reached, which appears to be what's happening in the PE6 Simulator. However, normally the PICaxe interpreter calculates to a WORD resolution within any command (otherwise something like b1 = b1 * 250 / 251 wouldn't be calculated correctly) which appears to be happening in the real chips and PE5 Simulator.
* 255 seemed to be the only value that supports up to 16 iterations (loops) for the division routine, plus the four potential "flag" bits, within a single byte. Anybody have any better ideas? I guess the "counting" loop probably could be closed in some other way, but a FOR loop seems so much the "obvious" (self-documenting) and compact structure to use.
Cheers, Alan.