PIC pwm for servo
Hi guys,
I was wondering whether this could be the right place to ask.
I am starting with microcontrollers and I have developed a few things. I am currently trying to make a servo to move. I have a code... the servo does move, but it moves like in steps, not a continuous movement as I move the potentiometer. I am using a pic16f690 at 500kHz. the servo is a Spectrum digital ds821. I would like to know whether I am making something wrong in order to make the servo to move more smoothly. Any suggestion will be helpful.
---------------------------
void main()
{
TRISC = 0b00100000;
PORTC = 0b00000000;
OSCCON = 0b00110101; //500kHz fosc
CCP1CON = 0b00001100; //
//CCPR1L = 0b11111111;
PIR1 = 0x00;
TRISC = 0x00;
// ADC portion
//==================
T2CON = 0b00000111; // prescaler = 16 + turn on TMR2;
PR2 = 0b10011011;
CCPR1L = 0b00000000;
ANSEL = 0b00000001;
ANSELH = 0;
/* Init ADC */
ADCON0 = 0b00000000; // select left justify result. ADC port channel 0
ADCON1 = 0b00110000;
ADON = 1; // turn on the A2D conversion module
//CCPR1L = 0b00000000;
// <Initiate the ADC conversion>
double constant1 = 0.06;
double constant2 = 6.2;
while(1)
{
TMR2IF = 0;
for(;
{
TMR2IF = 0;
GODONE = 1;
while(GODONE) continue; // Wait conversion done
//constant3 = floor(constant1*ADRESH + constant2); // this is to make wider the potentiometer // turns
CCPR1L = ADRESH;// constant3;
//adc end
while(TMR2IF == 0)
{
//just wait until it overflows
}
} //end for
}
}