Shop OBEX P1 Docs P2 Docs Learn Events
Servo Pulse Train — Parallax Forums

Servo Pulse Train

bxgirtenbxgirten Posts: 79
edited 2005-07-12 18:42 in General Discussion
As I am transitioning from the BASIC Stamp to the Javelin Stamp, I'm trying to convert my code around the PWM VP. If I have the following:

PWM servoL = new PWM(CPU.pin1, 50, 50);

and it spins the axle clockwise, how do I get the servo on the right (servoR), to spin its axle counter-clockwise?

Thanks!

Comments

  • bxgirtenbxgirten Posts: 79
    edited 2005-07-12 15:02
    Maybe, I should ask my question differently.

    I'm not sure how to affect the duty cycle of the PWM so I can have a servo go from forward to reverse. I can do it fine on the BASIC Stamp but I'm having difficulty with the Javelin Stamp. Can someone help me with some insight on this?

    Thanks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-12 15:26
    Servos want a high-going pulse from 1.0 ms to 2.0 ms in width, with 1.5 ms being the center position. In an CR-modified servo, the center position is stop. So, all you have to do is setup your PWM object to output a pulse between 1.0 ms (full speed one direction) to 2.0 ms (full speed the other direction) with a 20 ms delay between the pulses. I haven't used the Javelin in a while, but I know this is possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • bxgirtenbxgirten Posts: 79
    edited 2005-07-12 17:28
    Jon,

    Thanks for your response. I know that 1.5ms is center. Where I'm having a challenge is in the Java code. PWM is extended from VirtualPeripheral. The slice I'm alloted is 8.25ms and the documentation is not clear how much of a fraction of that slice should be set high/low in order for me to reverse the servo. This is what is confusing to me. If the documentation was just a tad clearer, I know I could solve this riddle.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-12 18:33
    The documentation makes it pretty clear that the high-time and low-time resolution for a PWM object is 8.68 uS (microseconds).· So, 1.5 milliseconds would be about 173 units; the 20 ms update time between pulses would be about 2304 units.

    If you look in the Projects\Examples\Manual_v1_0 folder you should find this servo demo:

    // Program Listing 4.5 - Basic Servo Control
    import stamp.core.*;
     
    public class ServoControl {
     
      static PWM servo = new PWM(CPU.pin12,173,2304);
     
      public static void main() {
     
        System.out.println("Welcome to Servo Control: ");
        System.out.println(" r - right");
        System.out.println(" l - left");
        System.out.println(" c - center");
     
        while (true) {
          switch ( Terminal.getChar() ) {
          case 'r':
            servo.update(130,2304);
            break;
          case 'l':
            servo.update(220,2304);
            break;
          case 'c':
            servo.update(173,2304);
            break;
          }
        }
      }
    }
    


    Note that the Parallax CR servos are really best for Javelin apps as they allow access to the centering pot -- that allows you to calibrate them to the center (stop) value output by the Javelin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • bxgirtenbxgirten Posts: 79
    edited 2005-07-12 18:42
    Jon,

    I see where I went wrong: like an idiot I misread microseconds for milliseconds.

    'Nuff said.

    Thanks, again.
Sign In or Register to comment.