Reversing Servo Timing Pg 84

ChuckThomasChuckThomas Posts: 4
edited 2004-11-15 - 20:52:42 in Robotics
Hello,

Please educate me.

I am runing the program for Boebot page 84. I selected 11 seconds as my time value. Formula states to divide
selected time by .024 11 / .024 = 458.

Problem when "counter" variable exceeds 255 the "counter" varible·resets back to one and causes an endless loop.

Here is the program:

' Robotics with the Boe-Bot - BothServosThreeSeconds.bs2· Page 84
' Run both servos in opposite directions for three seconds, then reverse
' the direction of both servos and run another three seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG"Program Running!"

counter VAR Byte

FOR counter = 1 TO 255
DEBUG "First loop"
DEBUG ? counter
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
NEXT

PAUSE 500

FOR counter = 1 TO 256
DEBUG "Second loop"
DEBUG ? counter
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20
NEXT

END


Thank you,

Charles Thomas

Comments

  • glasoglaso Posts: 38
    edited 2004-11-15 - 19:10:48
    That's becasue a "byte" variable can store va from 0 to 255. To use values over 255 you need a "word" (16 bit) variable instead the Byte (8 bit) variable.

    To fix the bug you need to declare the counter variable like:

    counter VAR word
  • ChuckThomasChuckThomas Posts: 4
    edited 2004-11-15 - 20:52:42
    Thank you. I figured that was the problem but I wasn't sure of the solution.

    Chuck Thomas
Sign In or Register to comment.