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 CCS Technical Support

Need help for this servo controller source code

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



Joined: 24 Aug 2009
Posts: 2

View user's profile Send private message

Need help for this servo controller source code
PostPosted: Mon Aug 24, 2009 9:17 am     Reply with quote

Hi, can anyone help me to solve this source code problem because I'm new to programming dont have idea on how to solve the problem and my project time is almost due. I copy this source code from website but then I load into CCS compiler lot of error come out. Currently I'm using PIC 16F877A microchip in my circuit.
Code:

// For CC5X C compiler
// Xtl frequency 4MHz
// A simple r/c servo test program.
// This version uses switches to control the servo position.
// Port B bit 1 is the servo control signal o/p
// Port A bit 0 = 0 resets the servo position to center (pulse = 1.5 ms)
// Port A bit 1  moves the servo clockwise when taken low.
// Port A bit 2  moves the servo anticlockwise when taken low.
//
// Note the pulse width range is specified as 1ms to 2ms giving a movement
// of 180 deg. but the precise pulse width and mechanical range varies from
// manufacturer to manufacturer.
//
// The pulse width range generated by this program has been found to work
// well with a range of servos.
//
// Connect the servo to a 5volt supply and take the control wire to port A
// bit 3, you will need a connection from the PSU 0V to the pic circuit
// supply 0V. Connect port A bit 0 to 3 to push buttons (with pullups).
// Do not leave the servo running at the extreme range of movement if it
// is pushing against the end stop. You can tell when this is happening
// by watching the current taken from the PSU which will be high if the
// servo is stalled.

#include "16F84.H"
#define CP_off |= 0x3FFF  // copy protect off for 16F84
#pragma config CP_off, PWRTE=on, WDTE=off, FOSC=XT

/* assign names to ports and pins */
#pragma bit servo       @ PORTB.1
#pragma bit RESET_S     @ PORTA.0
#pragma bit TURN_C      @ PORTA.1
#pragma bit TURN_A      @ PORTA.2

/* function prototypes */
void delay_min (void);
void delay_var (char n);
void pause (void);

void main( void)
{
    PORTB = 0b.0000.0000;  /* initial value */
    TRISB = 0b.0000.0000;  /* Port B all o/p */
    PORTA = 0b.0.0111;     /* initial value */
    TRISA = 0b.1110.0111;  /* xxx0 0001 */

char position=107;  // total time 1.5ms   center position

while(1) // endless loop
{
servo=1;
delay_min();
if (position>0)
  delay_var(position);
servo=0;
pause(); // 20 ms delay before next pulse
if ((TURN_C==0)&&(position<255))
 position++;
if ((TURN_A==0)&&(position>0))
 position--;
if (RESET_S==0)
 position=107; // center the servo
}

} // end of main


void delay_min (void)  // 750 uS including overhead
{
char n=248;
do ; while(--n>0);
nop(); //  padding to produce precise time
}
// delay = 2 + 2 + (n x 3) -1 +1 +2 = 750us  @ 4MHz
// 2 for call, 2 for preset n, (n x 3)-1 for loop, 1 padding, 2 for return

void delay_var (char n) // adc x 7 uS = 1790us max.
{
do {nop(); nop(); nop(); nop();} while(--n>0);
}
// delay= 2 + 2 + (t x 7) -1 +2 us  @ 4MHz

void pause (void)  // delay between pulses approx 20 ms
{
char n;
for (n=0;n<26;n++)
 {
 delay_min();   // 750 us
 }
}
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 9:45 am     Reply with quote

Your main problem here is that this is written for the CC5X compiler, which is totally different from the CCS compiler. You should go to their website, http://www.bknd.com/cc5x/, to seek help

r.b.
wleesh



Joined: 24 Aug 2009
Posts: 2

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 7:33 am     Reply with quote

Could anyone can help me write a simple source code to control servo angle and hold on the position. I'm using PIC16F877A, with hitec-HS 422 servos
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 10:55 am     Reply with quote

wleesh wrote:
Could anyone can help me write a simple source code to control servo angle and hold on the position. I'm using PIC16F877A, with hitec-HS 422 servos
Search on forum. I have posted an PIC18F4550 example to control 8 servos. You can easily use that code and implement it with your controller. Wink
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