Shop OBEX P1 Docs P2 Docs Learn Events
Pwm-servo help — Parallax Forums

Pwm-servo help

PitchingOnePitchingOne Posts: 24
edited 2006-05-02 01:01 in General Discussion
·Ok, since I do not have any idea why the PSC is not responding with the test program. I would like to test my motors with the PWM.·Does this·PWM avoid the use of PSC?

I see that there is a test program that can cotrol motors with the PWM Object in the javelin manual. I want to test it out, but the manual does not tell me how to wire it.· However, the code has static PWM servo = PWM (CPU.pin12,173,2304). So I am assuming that I can use pin12 for the·serial line.·

Am I correct?·

Thanks

Comments

  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-30 23:05
    I tried the PWM test program with the servo, the servo finally responds..it moves once, but then it seems to get stuck.
    I don't understand how this PWM Object works.
    For example, PWM (CPU.pin12,173,2304) How do the parameters 173 and 2304 tell the servo to go to center position?

    Thanks
  • bulkheadbulkhead Posts: 405
    edited 2006-05-02 01:01
    173 is the high time value of the pulse, 2304 is the low time value. How long the high value of the pulse is determines the position of your servo. Based on my experience with the javelin, servos range from 60 to 300ish, but each individual servo is different so be careful!

    The 2304 doesn't really matter, it's just the down time between pulses. It serves as the "refresh rate" of the servo positions. I believe 2304 is the value for a 20ms delay between pulses. At that rate, it is still updating the servo's positions 50 times a second. I've tried halving the value to get higher torque from my servos, but they end up just jittering really quickly and heating up also. IMO, just leave 2304 alone.

    Here is a program I used to use to find the PWM values that gave certain positions of my servos. For example, I had an arm on my robot, and I used this program to find the optimal PWM values that constituted its open/closed positions.

    This was when I ran servos directly off of the javelin's pins. This is NOT a good idea, but if you can't get the PSC to work, this is a good place to start. I say this is not a good idea because it really is a waste of the javelin's capabilities. Also, you can only run 6 servos max (6 virtual peripherals is the max). Also, you have to write your own ramping functions. If you want servo to go from PWM value 100 to PWM value 200, if you simply say myPWM.update(200,2304), your servo will jerk to its new position instantly. That is bad for the servo and your hardware. You should use a for loop with CPU.delay(20) in the loop to slowly ramp the servo to its position. With the PSC, however, you just send one command that includes a "ramp rate." The PSC does all the ramping for you. When your project gets more complicated, you will really see the merits of using the PSC to control servos.

    //10/23/05  updated 11/5/05
    //sets servo to position given in terminal window
    import stamp.core.*;
    
    public class servoValueTester
    {
      public static int value;
      public static StringBuffer buff;
     public static PWM pulse;
     
    
      /***** copied code *****************/
    
      //this is where i copied the initialization states of the other pins of my javelin, since when you run
      //     this program the javelin's pin states may be floating-i just copy and paste from my main program
    
    
      /****** end copied code*****************************/
      public static void main()
      {
      
        //  IMPORTANT- set pin (for ex, CPU.pin11)
        pulse = new PWM(CPU.pin,173,2304);   ///////173 starts servo at roughly middle
    
        buff= new StringBuffer();
        System.out.println("Starting up Javelin...");
        while(true)
        {
           buff.clear();
           System.out.println("Enter 3 digit number: ");
           buff.append(Terminal.getChar());
           buff.append(Terminal.getChar());
           buff.append(Terminal.getChar());
           value=Integer.parseInt(buff.toString());
           System.out.print("Value entered : ");
           System.out.println(value);
           pulse.update(value,2304);
        }
      }
    }
    
    
Sign In or Register to comment.