CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Programming to control Servo Motor With PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kingseow



Joined: 22 Jun 2008
Posts: 3
Location: Malaysia

View user's profile Send private message Yahoo Messenger MSN Messenger

Programming to control Servo Motor With PIC
PostPosted: Tue Jun 24, 2008 11:46 am     Reply with quote

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

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Wed Jun 25, 2008 2:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 26, 2008 1:05 pm     Reply with quote

That's 8051 code that you got from here:
http://freewebs.com/80x51/source/servos/pwm_servos.h
Please don't post random code from all over the net.

There is multiple servo code right here in the CCS forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=33183


To find CCS code for multiple servos, you can do a search
with http://www.google.com for this search string. The keywords
are picked to look for servos (plural) and then a CCS-specific
function name that is likely to be used in servo source code:
Quote:
servos "output_low"

Here are some sample hits:

Here is a project.
http://www.kd7lmo.net/nsrv.html
Here's the code. It's fairly complicated, compared to the link given
above for the forum code. Don't ask me to explain it to you.
http://www.kd7lmo.net/nsvr_servo_source.html
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group