Stop Command Only Pauses

Dave E

Senior Member
Hello all.
I ran across an odd problem that maybe some of you can help with.

Just for a "see how long it takes" experiment I programmed a 28X1 to find prime numbers between 3 and 65535. It took a few hours to find them so naturally I tried to find ways to speed things up so I added about 80 IF-THEN statements to factor the numbers by the first 80 prime numbers first. See attached code. I know that these 80 IF-THEN statements can be replaced to make the code neater but that is not the problem.

The problem is that when the count reaches 65535, another IF statement causes the program to STOP. It does stop but for only about 51 seconds. Then it continues. It doesen't reset. It just looks like it continues because W1 goes back to 1 (rolls over?) but W4, which counts the number of primes, picks up where it paused and counts up from there as prime numbers are found again.

The program can be run as is to observe the problem, it only takes a few minutes with the chip at 16MHz, but if anyone wants to run the complete program, change the W1 = 65001 line at the top to W1 = 3.

The same issue occurs if I replace the STOP command with END.

The issue must be with the code because if I program the 28X1 to count from 65500 to 65535 then STOP, it does stop.

Has anyone ever seen this before?

Other info: The chip is bread boarded with an LED on pin 7, external resonator, battery powered and stays connected to my computer with a serial cable (non-USB) while the program runs.

Dave E

P.S. I first programmed an 08M with a very simple and heavy number crunching "find primes" program and it has been running for about 24 hours now at 8MHz and is up to 28111 which is the 3069th prime number.
Could be an interesting "see how fast it can be done with an 08M" contest.
 

Attachments

BCJKiwi

Senior Member
Manual indicates the stop or end should be at the end.

you could try;
Code:
ENDIF

IF W1 = 65535 THEN terminate
W1 = W1 + 2
LOOP
 
terminate:
STOP
and see if it behaves.

Would also rem out any and all debugs in the code when you run it.
 
Last edited:

Technical

Technical Support
Staff member
stop is a 'pseudo' compiler command, it simply outputs

label: goto label

to create an everlasting loop.

We'll try out your program later.
 

vk6bgn

New Member
Just for a "see how long it takes" experiment .....
Dave,

Prime numbers on a PICAXE! So what's the eventual outcome?

It’s people like you that make this world go round. :)
 

Dave E

Senior Member
Firmware version is A.2 on the 28X1.

The real odd thing is that I ran the program several times after I noticed it and it always stopped for between 50 and 51 seconds depending on my thumb reaction time on the stopwatch. Because of the consistancy of the pause time, I assumed something was timing out before it restarted.

As far as eventual outcome, several things. I read a book recently about codes, the Enigma machine and that sort of thing and found that very large (hundreds or thousands of digits) prime numbers are one of the main bases for modern codes. Also, my wife, a high school teacher, is teaching a sort of independant study course with some of the more advanced students and several of them seem interested in the odd gadgets I have made with microcontrollers. Thought some of them might be interested in a Pong-Sat project. One student was looking for a basic compiler for his computer and I was going to give him my old copy of Microsoft Quick Basic except when I dug it out from the attic I found that it was on 5 1/4" floppy discs. REAL floppy discs. Any way, depending on what this student wanted to do, I thought I could set him up with a PICAXE so he could use it as a stand alone computer for running BASIC. Also, a recent question on this forum was about speed tests for microcontrollers.
So I was sitting here watching the Olympics and thinking about all of this stuff and the thought occured to program a PICAXE to find prime numbers. Then the natural next step was to do it faster.
My 08M is almost 36 hours into the problem (found 4183 prime numbers so far) running a simple number crunching prime finder and the above attached program runs on a 28X1 in about 14 minutes with the programming upgrades.

Thanks again for the suggestions and input.
If anyone else has any input for this issue, it will welcome.

Dave E
 
Top