- Thu Nov 30, 2006 8:56 am
#22775
Can someone please verify my calculations for driving my continuous rotation servo motor via my pwm channel. I am having some odd behaviour.
I am running a pic 18f4520 and am running it 8mhz using the internal osc.
Everything runs fine and i can get the motor to turn in one direction. My PWM is setup as follows.
OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(75);
So my PR2 is 251
my DC is at 75
and my timer2 prescaler is set to 16.
I am trying to generate a 1.5ms pulse at ~20ms intervals. I ran through the calculations an this appears to be correct. THe motor does indeed run and i can change the speed of the motor by adjusting the DC. However, i am unsure of how to get the motor to turn the other direction. It seems no matter how i adjust the DC it still goes in the same direction. Perhaps i need to adjust the set screw on the servo?
Additionally i have a servo motor that is not continuous rotation that i have setup as above. To test the motor, i have a loop setup that will move the motor through different positions in a loop.
Pseudo code is
OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(55);
while(1)
{
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(95);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(55);
}
When i intialize the motor originally it goes to a position and then begins to rotate through the positions i have listed. I am running this in the debug mode of the icd2. However after a few positions, i dont actually know which one, the program will die and go into pause mode. I am not sure why this is happening. THe only guess i have is that by jerking the motor around so frequently that i am drawing too much power? I have the motors power connected to the same powersource as the pic. As well the power source, a 9vdc 600ma wall wart is powering two pics, and some leds in addition to my motor. I have capacitors running between power and ground. Does this sound like a reasonable explanation for why my program would go into pause?
THanks
Brian
I am running a pic 18f4520 and am running it 8mhz using the internal osc.
Everything runs fine and i can get the motor to turn in one direction. My PWM is setup as follows.
OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(75);
So my PR2 is 251
my DC is at 75
and my timer2 prescaler is set to 16.
I am trying to generate a 1.5ms pulse at ~20ms intervals. I ran through the calculations an this appears to be correct. THe motor does indeed run and i can change the speed of the motor by adjusting the DC. However, i am unsure of how to get the motor to turn the other direction. It seems no matter how i adjust the DC it still goes in the same direction. Perhaps i need to adjust the set screw on the servo?
Additionally i have a servo motor that is not continuous rotation that i have setup as above. To test the motor, i have a loop setup that will move the motor through different positions in a loop.
Pseudo code is
OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(55);
while(1)
{
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(95);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(55);
}
When i intialize the motor originally it goes to a position and then begins to rotate through the positions i have listed. I am running this in the debug mode of the icd2. However after a few positions, i dont actually know which one, the program will die and go into pause mode. I am not sure why this is happening. THe only guess i have is that by jerking the motor around so frequently that i am drawing too much power? I have the motors power connected to the same powersource as the pic. As well the power source, a 9vdc 600ma wall wart is powering two pics, and some leds in addition to my motor. I have capacitors running between power and ground. Does this sound like a reasonable explanation for why my program would go into pause?
THanks
Brian