PDA

View Full Version : 255 GoSub Limit?



HkySk8r187
04-14-2007, 05:06 PM
I hit a limit aparently. Tells me the limit of 255 GOSUBs was exceeded. Is this a language limitation or a BS2 limitation? I also have a BS2sx if maybe it will allow more GOSUBs.

Bruce Bates
04-14-2007, 06:48 PM
It is a PBASIC Language restriction. Sounds like combining some routines might be in order.

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

allanlane5
04-14-2007, 10:36 PM
You have more than 255 subroutines in 2000 bytes of program memory? That's amazing.

HkySk8r187
04-15-2007, 12:07 AM
Yes, I am trying to write a program that will basically do a LED light sequence that is about 1000 steps long. I got like 25% of the way through programming the squence and hit the limit. I'm not sure this is going to be possible anymore. I was doing something like this:



Main:
GOSUB blink_light_A
pause 100
GOSUB blink_light_B
pause 100
GOSUB blink_light_D
pause 100
GOSUB blink_light_C
pause 100
GOSUB blink_light_B
pause 150
GOSUB blink_light_A

< etc, etc... >

END

blink_light_A:
LEDs = %00000001
RETURN

< other functions for other lights B-D >


This is just kind of how the code was working, but then I hit the 255 max. I was doing it this way because I guess I dont have enough variable or eeprom memory to store the order of light flashes.

Anyone know how I can do this? There is going to be potentially 800-1200 light flashes that need to happen. The time between the flashes may change as well, if you look in my example sometimes it waits 150ms and sometimes 100ms

HkySk8r187
04-15-2007, 12:10 AM
Also worth mentioning is that the subroutines such as blink_light_A also have other stuff inside them, so I can't simply replace the GOSUB call with the LEDS = %00000001 line without getting extremely messy.

Unsoundcode
04-15-2007, 12:30 AM
Without seeing all the code its hard to give a full answer but from what we have I can see ways of trimming it down some.
The Leds don't have to be in a subroutine just give them a variable in your main loop

x=some_number
LEDS=x

do the same with the pause you might even use the same variable if you don't need to retain it

x=another_number
PAUSE x

If the subroutines are doing similar functions try and do it all with one subroutine but pass it different paramaters

my_output=1
GOSUB whatever
my_output=4
GOSUB whatever

whatever :
HIGH my_output
RETURN

Jeff T

allanlane5
04-15-2007, 02:46 AM
Yup, this just cries out for using a 'temp' variable.

MAIN:
MyTemp = 1
GOSUB DoSomething
MyTemp = 2
GOSUB DoSomething
GOTO MAIN ' Also known as, "the main loop"

DoSomething:
IF MyTemp = 1 THEN
Do Stuff
ENDIF
IF MyTemp = 2 THEN
DoOtherStuff
ENDIF
RETURN

This is the 'classic' way to begin 'parameterizing' subroutine calls. It makes life MUCH easier if "DoStuff" and "DoOtherStuff" are quite similar.

Looking at your code, you could have two calls -- long blink and short blink, and set a number of which LED to blink as a 'parameter'.

Another way to do this would be with DATA statements -- a duration, and the LED pattern.· Then your program becomes very simple.

MaxPat = 800
LEDPat = 0

MAIN:
··READ LEDPat, TimeVal
· READ LEDPat + 1, LEDVal
· GOSUB BlinkLED· ' (TimeVal, LEDVal)
· LEDPat = LEDPat + 2
· IF LEDPat > MAXPat THEN
··· LEDPat = 0
· END IF
· GOTO MAIN

BlinkLED:
· LEDS = LEDVal
· PAUSE TimeVal
· RETURN

DATA 100, $01, 150, $02, 'etc -- you'll have to input the pattern of LED blinks,
' but it will be WAY shorter than typing in 800 "LED = xxx: PAUSE 100" statements.


Post Edited (allanlane5) : 4/14/2007 7:54:35 PM GMT