Guest
|
Generating PWM for Servo Motor Application PIC18F |
Posted: Sun Mar 22, 2009 4:50 pm |
|
|
Hello all,
I'm working on a motor project and I need some help debugging some code. I am fairly new with the microcontroller world in general, so I apologize in advance if I don't understand the full ins and outs.
I am using a Parallax (Futaba) Continuous Rotation Servo .
Right now I'm just trying to generate a 20ms duty cycle to drive a continuous rotation servo motor. It is my understanding that if you feed the servo a 20ms duty cycle with a width of 1.0 - 2.0 ms of high time, the position of the servo can be controlled. Now I've calibrated the potentiometer of the servo to the neutral position using a 1.5 ms / 20ms signal.
I expect that a 2.0 ms pulsewidth should drive the servo +180 degrees (?). However, upon generating a single pulse the servo rotates barely 5-10 degrees. I observed the pulse on an oscilliscope and I indeed am generating a 20 ms duty cycle with 2.0 ms width. If someone could help me, maybe suggest some alternative way or provide an explanation of why this is happening I'd greatly appreciate it.
------------------------------------------------------Servo Code
Code: |
#include <18F4431.H>
#fuses HS, NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define carr1 PIN_B0
long carr1pulse=5*50*16; //2000 us pulse
long carrDuty=5*50*170; //17,000 us (Accomodates error)
int carrSignal=0;
#INT_TIMER1
void CarriageTimerISR() {
switch(carrSignal)
{
case 0:
{
set_timer1(65536-carr1pulse);
output_high(carr1);
carrSignal++;
}
break;
case 1:
{
set_timer1(65536-carrDuty-carr1pulse);
output_low(carr1);
carrSignal++;
}
break;
case 2:
{
disable_interrupts(INT_TIMER1);
}
break;
}
void main() {
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // setup interrupts
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1); // loop forever
}
|
|
|