Shop OBEX P1 Docs P2 Docs Learn Events
Some help with simple codes. — Parallax Forums

Some help with simple codes.

haninatorhaninator Posts: 6
edited 2006-08-01 03:23 in BASIC Stamp
Hi all,

i have been trying to make a servo sweep 180 degrees twice. However, it tends to sweep out of control, many many times instead of 2. i have the follwing code. It loks very simple, but still it doesn't work?!

I would really appreciate some help.

' {$STAMP BS2sx}

DEBUG "Test Sweeping"

counter VAR Byte
counter2 VAR Byte
outercounter VAR Byte

FOR outercounter = 1 TO 2

FOR counter = 1 TO 30
PULSOUT 14, 500
PAUSE 20
NEXT

FOR counter2 = 1 TO 30
PULSOUT 14, 2850
PAUSE 20
NEXT

NEXT

that's all to my code. it sweeps many many times instead of the 2 times as specified by the outercounter. sometimes it stops abruptly, sometimes it goes on forever. Also, i noticed that "Test Sweeping" gets printed many times too shouoldn't it only print once?.

pls help. thank you guys so much!

haninator

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2006-07-28 11:02
    The big clue is that "test sweeping" gets printed more than once. That means that the program is resetting over and over. Are servos powered from the same power supply as the Stamp? If the servos drag down the system power, the stamp will reset.

    Also, the code as shown puts the servo in one position 30 times then puts it in the other position 30 times in a total of about 600 msec for each position. Is that really what you want?

    Cheers
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-28 12:01
    haninator -

    If you're using the word "sweep" meaning to move through a range of values quickly and smoothly, your code, as it is, isn't going to do that at all. However you have all of the elements to do so, right at your disposal.

    You may have to tweak this program below a bit, to work with your specific servos, but try something like this:

    ' {$STAMP BS2sx}

    DEBUG "Test Sweeping"
    'Note If "Test Sweeping" appears more than once, the Stamp is resetting!

    counter VAR Byte
    counter2 VAR Byte
    outercounter VAR Byte

    FOR outercounter = 1 TO 2

    FOR counter = 1 TO 30
    PULSOUT 14, 500+(5 * counter)
    PAUSE 20
    NEXT

    FOR counter2 = 1 TO 30
    PULSOUT 14, 2850- (5 * counter)
    PAUSE 20
    NEXT

    NEXT

    END

    Regards,

    Bruce Bates
  • haninatorhaninator Posts: 6
    edited 2006-08-01 03:23
    Thank you all very much Bruce and stamptrol,

    i recently changed the power supply to the basic stamp from a battery pack of 9V to a constant power supply of 9V through an adapter. The moment i changed it back, the code works fine!!!! hop.gif Thank you guy so very much for the advice. I will·NEVER nono.gif buy china made adaptors EVER again...

    As for the code, yes that is very much what i want, up to 600ms per cycle.

    Bruce, your tweak is·very interesting, will definately study that and see if it helps in my application.

    Once again, thank you guys for your help, really appreciate it!!

    Haninator
Sign In or Register to comment.