View previous topic :: View next topic |
Author |
Message |
kingseow
Joined: 22 Jun 2008 Posts: 3 Location: Malaysia
|
Programming to control Servo Motor With PIC |
Posted: Tue Jun 24, 2008 11:46 am |
|
|
I am looking for programming to control 5 servo motor with PIC16F877 and stand alone(Basically the program just need start all the servo when power on)...which only will rotate 70 to 120 degree then go back to where it start rotate for each servo motor and all the servo moving at same time.Below is the list of servo motor i using:
1)Three unit,
Hitec HS-55 Servo(rotate 100,110,120 degree)
2)One unit,
HS-6975HB servo(rotate 70 degree)
3)One unit,
HS-65HB servo(rotate 80 degree)
hope u all can help me,thk alot |
|
|
kingseow
Joined: 22 Jun 2008 Posts: 3 Location: Malaysia
|
|
Posted: Wed Jun 25, 2008 2:58 am |
|
|
izzit possible i write like this ?
Code: |
/*
* Filename : pwm_servos.h
* I/O : P1.4 -> A1 (PWM-CEX1)
* P1.5 -> A2 (PWM-CEX2)
* P1.6 -> A3 (PWM-CEX3)
* P1.7 -> A4 (PWM-CEX4)
* P1.8 -> A5 (PWM-CEX5)
/* Control the A1 servo */
void ServoL_back()
{
CCAP1H = 243;
}
void ServoL_forward()
{
CCAP1H = 230;
}
void ServoL_stop()
{
CCAP1H = 0;
}
/* Control the A2 servo */
void ServoR_back()
{
CCAP2H = 230;
}
void ServoR_forward()
{
CCAP2H = 243;
}
void ServoR_stop()
{
CCAP2H = 0;
}
/* Control the A3 servo */
void ServoL_back()
{
CCAP3H = 243;
}
void ServoL_forward()
{
CCAP3H = 230;
}
void ServoL_stop()
{
CCAP3H = 0;
}
/* Control the A4 servo */
void ServoL_back()
{
CCAP4H = 243;
}
void ServoL_forward()
{
CCAP4H = 230;
}
void ServoL_stop()
{
CCAP4H = 0;
}
/* Control the A5 servo */
void ServoL_back()
{
CCAP5H = 243;
}
void ServoL_forward()
{
CCAP5H = 230;
}
void ServoL_stop()
{
CCAP5H = 0;
}
/* Initialize the PCA and PWM mode */
void Servos_init()
{
/* Initial Timer0 Generate Overflow PCA */
TMOD = 0x02; /* Timer0 Mode2 : 8bit auto reload */
TH0 = 16; /* 256-240, 8.125usec Auto-relead (20msec/PWM) */
TL0 = TH0;
TCON = 0x10; /* setb TR0, TCON or 0001,0000*/
CMOD=0x04;
CCAPM1=0x42;
CCAPM2=0x42;
CCAPM3=0x42;
CCAPM4=0x42;
CCAPM5=0x42;
CCAP1H=0x00;
CCAP2H=0x00;
CCAP3H=0x00;
CCAP4H=0x00;
CCAP5H=0x00;
CCON=0x40;
}while(1)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|