Thread: Proportional servo motor control Help Needed

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    1

    Proportional servo motor control Help Needed

    I am in the process of building a autonomous yacht with proportional steering. The input for Proportion Control is taken from 5V Pot ( no stop ). This input is then sent to the output of a 180 degree servo motor. I have succeeded in controlling this system with a Arduino UNO. I want to control the same hardware on a Galileo in C. I have a test function wrote and will attach. In this function you can see how the full duty cycle is calculated but, what I want to do is input one figure to the function that will control the ON cycle and the OFF cycle. Any help would be appreciated.
    Cheers,
    John

    Code:
    
    ***********************************************
    void servoPWM(int);
    int ON,OFF,x;
    int servo = 9;
    
    
    void setup(){
      Serial.begin(9600);
      pinMode(9,OUTPUT);
    }
    
    
    void loop() 
    {
     int Dir;
    
     //if(Dir==
       for(Dir=-90;Dir<90;Dir++)
       {   
         servoPWM(Dir);
         delay(10);
       }
       for(Dir=90;Dir>-90;Dir--)
       {   
         servoPWM(Dir);
         delay(10);
       }
    
    
    }
    
    
    void servoPWM(int Dir)
    {
         ON = map(Dir,-90,90,550,2250); 
         OFF = 20000 -ON;
    
    
         digitalWrite(servo,HIGH);
          delayMicroseconds(ON);
          digitalWrite(servo,LOW);
          delayMicroseconds(OFF);
      
       Serial.print("Direction  ");
          Serial.println(Dir);
          Serial.print("ServoON  ");
          Serial.println(ON);
          Serial.print("ServoOFF  ");
          Serial.println(OFF);   
    } 
    
    ***************************************************************************
      

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    Hi John,
    It appears your duty cycle is dependent on the Map function which is not included.
    The full duty cycle is 20000 at this time.
    The OFF will just be the part that is not ON out of 20000.
    I'm not real clear on what you need.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arduino Programming for Servo motor
    By ddang in forum C Programming
    Replies: 4
    Last Post: 07-16-2013, 11:04 PM
  2. Servo rotation
    By buzmay in forum C Programming
    Replies: 1
    Last Post: 04-27-2010, 08:11 AM
  3. Replies: 3
    Last Post: 03-18-2006, 11:15 AM
  4. help needed with edit control & encryption
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 08:21 PM
  5. Stepper Motor Control .......
    By svglolla in forum C Programming
    Replies: 1
    Last Post: 02-18-2002, 11:03 AM

Tags for this Thread