why doesn't this code work???????
Pressus Limited
Posts: 23
Hi Guys,
Please can someone tell me why this bit of code doesn't work... It's doing my head in!!!!!
reset_folds:····································································· ' ROUTINE TO RESET FOLD
·step_ctr=0····································································· ' zero position counter
·AUXIO: HIGH res1·····························································' set driver reset pin to high
·AUXIO: LOW dir······························································· ' set driver direction pin to clockwise
·AUXIO: LOW steps··························································· ' set steps O/P low
·MAINIO: DO UNTIL IN13=TRUE··········································· ·' stay in loop until limit sw. reached
· AUXIO: PULSOUT steps,1················································· ' send 0.8uS pulse to stepper motor
· step_ctr=step_ctr+1······················································· ' add 1 to position counter
· PAUSE 1········································································' pause 1ms
·LOOP
·DEBUG "Limit reached",CR
·PAUSE 250······································································ ' pause 250ms for motor to settle
·AUXIO: HIGH dir······························································· ' set driver direction pin to counter clockwise
·DO UNTIL step_ctr=0························································ ' stay in loop until back to start position
· AUXIO: PULSOUT steps,1·················································· ' send 0.8uS pulse to stepper motor
· step_ctr=step_ctr-1························································ ' -1 from step position
· PAUSE 1········································································ ' 1ms pause
·LOOP
The problem is that the MAINIO: DO UNTIL IN13=TRUE... LOOP drops out after the first cycle regardless of the state of IN13.· If I use a pin on AUXIO for the DO UNTIL ... LOOP the routine works fine.· All pins have pullup resistors fitted so it's not because the pin is floating.
I am using a A4983 stepper driver in full step mode with a BS2p40 and pbasic 2.5
thanks
Jon
Please can someone tell me why this bit of code doesn't work... It's doing my head in!!!!!
reset_folds:····································································· ' ROUTINE TO RESET FOLD
·step_ctr=0····································································· ' zero position counter
·AUXIO: HIGH res1·····························································' set driver reset pin to high
·AUXIO: LOW dir······························································· ' set driver direction pin to clockwise
·AUXIO: LOW steps··························································· ' set steps O/P low
·MAINIO: DO UNTIL IN13=TRUE··········································· ·' stay in loop until limit sw. reached
· AUXIO: PULSOUT steps,1················································· ' send 0.8uS pulse to stepper motor
· step_ctr=step_ctr+1······················································· ' add 1 to position counter
· PAUSE 1········································································' pause 1ms
·LOOP
·DEBUG "Limit reached",CR
·PAUSE 250······································································ ' pause 250ms for motor to settle
·AUXIO: HIGH dir······························································· ' set driver direction pin to counter clockwise
·DO UNTIL step_ctr=0························································ ' stay in loop until back to start position
· AUXIO: PULSOUT steps,1·················································· ' send 0.8uS pulse to stepper motor
· step_ctr=step_ctr-1························································ ' -1 from step position
· PAUSE 1········································································ ' 1ms pause
·LOOP
The problem is that the MAINIO: DO UNTIL IN13=TRUE... LOOP drops out after the first cycle regardless of the state of IN13.· If I use a pin on AUXIO for the DO UNTIL ... LOOP the routine works fine.· All pins have pullup resistors fitted so it's not because the pin is floating.
I am using a A4983 stepper driver in full step mode with a BS2p40 and pbasic 2.5
thanks
Jon
Comments
Thank you so much, some times it's the most obvious things you can't see!!!!
Jon
It is redundant to use an AUXIO or MAINIO on consecutive statements as you're doing. Once a MAINIO or AUXIO command is executed it stays on that bank until switched by the opposite command.· So when you have several statements in a row each one doesn't need to have an IO select command if they're the same.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
I know I don't need to do it, but it's a (bad) habit i've got into to ensure I don't forget to switch banks.
Does each time I add the AUXIO or MAINIO command use a bit of program memory or does the interpreter ignore them if they are not needed?
thanks
Jon
Each token consumes program memory. See see how much you can look at the memory map and then remove one redundant AUXIO command and check it again. Some commands (like SEROUT and DEBUG) use more memory than others. One thing to remember is that even though you have exra program memory it is not contiguous. You still have a 2K limit per program that could quickly fill up. I have seen many a programmer fill up program memory and then have to decide how to optimize their program. If you always think about that during programming then it usually never becomes and issue.
P.S. - The only thing in your program that doesn't take up space if not used is constants.· You can have more constants than you need / use but these don't really take up space.· Everything else added does.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
OK, you've converted me.... having had to rewrite the code twice already and split it across multi program banks and still got the dreaded 'eeprom full', i'll go back through the program and delete them.
thanks again for your advice.
Jon
That was just one way to save on program space. there are many more depending on exactly what you're doing. Don't be afraid to throw stuff out here for others to suggest optimizations on, since that's how you can get more ideas. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·