Shop OBEX P1 Docs P2 Docs Learn Events
nested for...next loops — Parallax Forums

nested for...next loops

GlimpyGlimpy Posts: 5
edited 2004-12-06 21:21 in BASIC Stamp
This code doesn't work for me.
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM2}
k VAR Word
l VAR Word
FOR k=400 TO 1200 STEP 20
DEBUG DEC k ,CR
FOR l=1 TO 10
PULSOUT 14,k
· PAUSE 20
NEXT
NEXT
If it works for you then let me know what I'm doing wrong.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-02 04:19
    I really dislike single-letter variables, so I made that change, but otherwise your code runs fine.· I checked the output on a 'scope (Parallax USB Oscilloscope) and can see the pulses getting wider as you code suggests they should.

    Main:
      FOR pWidth = 400 TO 1200 STEP 20
        DEBUG DEC pWidth, CR
        FOR idx = 1 TO 10
          PULSOUT 14, pWidth
          PAUSE 20
        NEXT
      NEXT
      GOTO Main
      END
    


    What is causing you to believe it's not working?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
    798 x 589 - 143K
  • GlimpyGlimpy Posts: 5
    edited 2004-12-02 13:37
    with your code, I still get only one output from debug; namely 400. No increasing pWidth. I thought that maybe the editor was corrupted and reloaded a new editor with same result. I'll have to try this code on another machine.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-02 13:47
    Is there something connected to your BASIC Stamp that is causing it to reset (is your PULSOUT pin connected to ground instead of some circuit)? If this is happening, then you would only ever see the first value. The easiest way to determine if this is the problem is with a simple line of DEBUG code above the main loop:


    Reset: 
      DEBUG "BASIC Stamp has reset", CR, CR
    
     
    Main:
      ...
    


    If you see the reset message more than once then you know the BASIC Stamp is being reset by some problem with your circuit or programming connection.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 12/2/2004 1:51:52 PM GMT
  • GlimpyGlimpy Posts: 5
    edited 2004-12-02 22:11
    you are correct. there is a flickering message showing "the stamp has reset" followed by the first value of the loop.

    I have white connected to P14 through a resistor, black is connected to ground and red is connected to +. These colors are the wire colors on the servo. Disconnecting the servo alleviates the problem. What suggestions have you? Could the servo be shorted white to black?
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-02 22:57
    No, the Servo is not shorted, or you wouldn't get *anything*. What is happening is when you command the servo through the 'PULSOUT', the servo is pulling so much current it is lowering the voltage on your BS2. This resets the BS2, and it tries again.

    This only happens when you don't have a large enough power supply driving the Servo.

    How are you powering this board? With a 9-volt battery? With a 6-volt wall-wart?
  • GlimpyGlimpy Posts: 5
    edited 2004-12-03 12:57
    power supply is a 6-volt ac adapter. There must be something wrong with this servo because it doesn't turn when light finger torque is applied. I'll try another servo from another kit to confirm this. What do think?
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-03 15:45
    The 7805 regulator needs 7.5 volts to reliably produce 5 volts. A 6-volt wall-wart will actually produce a volt or three above 6 volts when lightly loaded (like a BS2 by itself). However, when the load increases (like a Servo actually trying to move) it is possible to draw-down the wall-wart output to 6 volts -- at which time the 7805 regulator will 'brown-out' -- meaning it won't supply 5 volts to the BS2 anymore.

    Is the Servo connected to 'Vin' (which is the un-regulated output from the wall-wart) or the 'Vdd' (which is the 5-volt regulated output from the 7805)? With a 6-volt wall-wart, it should be connected to Vin.

    The 'holding' torque of servo's from different manufacturer's does vary. The Parallax supplied Futaba servo's can be turned by hand. I've held other vendor's servo's that couldn't. The servo output shaft is tied to the servo motor through reduction gears, which could make it difficult or impossible for you to turn the servo by hand.

    Possible solutions (one of the following may fix the problem)
    1. Use a 7.5 or higher voltage wall-wart, and drive the servo from Vdd (there's a jumper on the BOE to select this)
    2. Drive the Servo from Vin if you aren't already.
    3. Replace the 7804 with a low-drop-out regulator. (LM3804-5? Not sure of the exact part number) A low drop-out regulator will regulate down to about 0.5 volts difference between input and output voltages.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-03 15:46
    Oh, and a 'locked up' damaged or broken servo could in fact create the symptoms you describe. I just thought that the most unlikely scenario.
  • GlimpyGlimpy Posts: 5
    edited 2004-12-06 21:13
    That servo that is "locked up" is part of a ten kit order "Understanding Signals" that St. John Bosco Private School made a short while ago. We manually tested the other nine servos and all were turnable. I'm wondering how we can have the defective one replaced? You are correct with your diagnosis of the power supply. We found that powering the stamp and servo with separate isolated 6-volt supplies solved the problem we had. Our only problem now is that one of our students will not have a servo to experiment with unless you ship one to us. Thanks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-06 21:21
    Contact our Tech Support department: 1-888-99-STAMP.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.