Can anyone tell me what's wrong with servo motor control?

Discuss anything that may not be product related here.
Barlioh
Posts: 3
Joined: Sun Sep 11, 2016 10:59 pm

Can anyone tell me what's wrong with servo motor control?

Postby Barlioh » Thu May 18, 2017 3:00 am

I am trying to control a servo motor using PIC12F675(http://www.kynix.com/Detail/368304/PIC12F675.html). I was successful in driving the servo as well as achieving the speed control for the servo.

Now, my speed control is quite flaky. I tried tweaking my code here and there but I have had no success so far.

My main objective is that the servo should spin 0 to 90 and back based on the data from toggle switch. I achieved this goal. When I turn a potentiometer, the speed at which the servo rotates should change. I achieved this too. However, the servo is not rotating 90 degrees at all the time.

It rotates 90 ish -120 degrees at high speeds and rotates only 30-45 degrees on low speeds (or some weird behavior is happening). I want my servo to rotate 90 degrees but just my speed should vary.

Can any one point me to the error in my code?

Code: Select all

GO_DONE=1; // start ADC
while(GO_DONE); // wait for ADC to complete
V_in=(ADRESH<<8)|ADRESL; //copy ADC values into a variable V_in
quotient=V_in/200; // I am dividing this because I will have integers between 1 to 5
// I am using this quotient value to magnify/diminish my time delays for speed

if(quotient<=1)
{
    quotient=1; //fool proofing
}

if(GPIO&(1<<3)) //checking whether toggle switch is high. If yes, go forward else reverse
{
    while(counter>1000) //this counter is for the delay cycles.
    {
        counter=counter-(20*quotient);
        GPIO|=(1<<2);
        cnt_1=counter;
        while(cnt_1>0)
        {
            __delay_us(1);
            cnt_1--;
        }
        GPIO&=~(1<<2); //low signal
        __delay_ms(18);
    }
    cnt=1000;//reset of counter for reverse direction
}
elseif(!(GPIO&(1<<3))) // check if switch is low
{
    while(cnt<1500)
    {
        cnt=cnt+(20*quotient);
        GPIO|=(1<<2);
        cnt_2=cnt;
        while(cnt_2>0)
        {
            __delay_us(1);
            cnt_2--;
        }
        GPIO&=~(1<<2);
        __delay_ms(18);
    }
    counter=1500;//reset of counter for forward direction
}

om_tech_support_JS
Posts: 126
Joined: Tue May 10, 2016 4:48 pm

Re: Can anyone tell me what's wrong with servo motor control?

Postby om_tech_support_JS » Tue May 23, 2017 2:12 pm

Hi Barlioh,

Unfortunately we are unfamiliar with the syntax for the PIC12F675 code. However, if you are using the NX series servo motor package, then this package is a pulse input type package. Therefore, it will require pulse and direction signals from you PLC. Since the amount of pulses sent to the driver will determine the distance, I would reference the PLC material for sending the pulse information. One consideration would be your counter. Is this a pulse counter or a time counter? If it is time, then at slower speeds, the pulses sent to the driver would be less.

User avatar
IsrealHooley
Posts: 1
Joined: Fri Jun 02, 2017 2:53 am

Re: Can anyone tell me what's wrong with servo motor control?

Postby IsrealHooley » Fri Jun 02, 2017 2:57 am

The code is correct. My speed control is quite oddball, too.
It's time to cook some rice. You know, enough flavor comes from the rice itself. The rice itself creates a unique flavor. My new crp g1015f will come in handy.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest