Replies: 3 comments 4 replies
-
Sporadic issues like this to me scream "stack overflow or underflow", and from a cursory test of your code, it is apparent that it is stack underflow. I have done a modification of your code to emulate input using random values in the place of actual switch inputs (as I have no switches attached to the Pico W board I am using), and I am getting the following: Here is the output from your code with it now dumping the output of
Here is your code as I have modified it - note the sections marked as "debugging" and the use of
|
Beta Was this translation helpful? Give feedback.
-
I would suggest putting checks in your code like:
throughout your code to narrow down the source of the stack underflow. This is probably the fastest way of doing it that I can think of. |
Beta Was this translation helpful? Give feedback.
-
@rdoetjes Note my comment about; the check I specified won't work, because it will always incorrectly trap an issue due to |
Beta Was this translation helpful? Give feedback.
-
I am polling a pin to see if it's pressed in a synchronous application (a simple SIMON says toy) on the RP2040.
But eventually I get a pin out of range thrown, it can take up to two days (but usually with 6-12 hours) and this is just a learning project for me to get experience with the RP2040 and ZeptoForth just to see how reliable they both are, so I am actually automating the game play with an arduino. Hence I know this eventually triggers this error.
The fact thing is that the pin toggle and the corresponding beep tone (associated with each button) are execute which says that the port number is correct.
Yet in that begin until loop, that I continuously check if the button is still pressed, it throws that error albeit sporadically. I have printed all button presses to the console and I have yet to see a pin that is not within the 3-29 range.
Just to eliminate the stack I refactored it to let my poll-keys word set the port number in a variable and even that failed eventually.
I looked at ZeptoForth's gpio code but nothing special could go wrong with the u< and advert.
Any suggestions how to troubleshoot this weird and very inconsistent issue?
I almost start to distrust the Pi Pico but when I wrote a C version that ran perfectly for 3 days. So frankly I am at a loss :D
The code with the offending line: (the whole code can be found here: https://github.com/rdoetjes/tuts/blob/main/forth/simon/simon.fs
``
: key-is-down ( switch_pin -- n ) \ lights up the led as long as pressed and returns the step value calculated from switch number (- 6)
dup 4 - toggle-pin \ subtract 4 from the pressed switch to turn on corresponding led
dup 6 - play-beep \ subtract 4 from the pressed switch that corresponds with the sound of the led
begin dup pin@ -1 = until \ FOR SOME REASON THIS THROWS PIN OUT OF RANGE (SPORADICALLY BUT EVENTUALLY)
stop-beep \ stop the pwm to stop the sound
dup 4 - toggle-pin \ subtract 4 from pressed switch to turn off corresponding led
6 - \ subtract 6 from switch pin to get the step value of the sequence
50 ms ; \ debounce the release
: poll-keys ( -- ) \ checks for a keypress and timeout after ~1500ms of not being a keypressed
0 \ counter for timeout
begin
10 ms \ delay to add to time out (150 * 10 ms is 1500ms and then exit with -1) doubles as debounce
1 + dup 150 = if drop -1 exit then
0 6 pin@ = if drop 6 key-is-down exit then
0 7 pin@ = if drop 7 key-is-down exit then
0 8 pin@ = if drop 8 key-is-down exit then
0 9 pin@ = if drop 9 key-is-down exit then
again ;
``
Beta Was this translation helpful? Give feedback.
All reactions