rangerskm
Full Member level 4
compiler used -hi tech c .20 mhz osc
Hi friends,just nw i started to learn servo motor ,but not able to understand the concepts,
1)actually we are giving the pwm signal to the motor how we can pass the pwm signals in to it??
2)please explain me the given code for servo control .
Hi friends,just nw i started to learn servo motor ,but not able to understand the concepts,
1)actually we are giving the pwm signal to the motor how we can pass the pwm signals in to it??
2)please explain me the given code for servo control .
Code:
#include<pic.h>
#define _XTAL_FREQ 20000000
#define SRV RC0
char ch,duty=0;
unsigned int servo_h=0;
void interrupt isr()
{
if(TMR1IF)
{
TMR1IF=0;
TMR1H=0xff;
TMR1L=0x54;
TMR1ON=1;
servo_h++;
}
if(servo_h<=duty) SRV=1;
else SRV=0;
if(servo_h>500)
{
servo_h=0;
}
}
void main (void)
{
int x=500;
TRISC=0x80;PORTC=0;
SPEN=1;CREN=1;SYNC=0;BRGH=1;SPBRG=129;
TMR1IE=1;TMR1IF=0;
GIE=1;PEIE=1;
TMR1H=0xff;
TMR1L=0x54;
TMR1ON=1;
TMR1IF=1;
duty=37;
__delay_ms(1000);
duty=25;
while(1);
}