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

Servo Rotation Problem With CCS C

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



Joined: 09 May 2018
Posts: 1

View user's profile Send private message

Servo Rotation Problem With CCS C
PostPosted: Wed May 09, 2018 2:01 am     Reply with quote

Hi. I am trying to control my servo with this code. But my servo just rotates 90 degrees and then stops. According to my code it should move to 2 different degrees. Please help. I couldn't figure out what to do. Thanks.

Code:

void servo(unsigned long int b)
{                   
 output_high(pin_d0);
 delay_us(b);
 output_low(pin_d0);
 delay_us(20000-b); 
}

void main()
{
lcd_init();

while(1)
  {
   delay_ms(1000);
   servo(400);
   delay_ms(1000);
   servo(600);
   delay_ms(1000);
  }   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Wed May 09, 2018 3:33 am     Reply with quote

Servos require a pulse of 0.5mSec for one end of their travel to 2.5mSec for the other end. The standard pulse repetition 'interval' is every 20mSec. 2mSec full scale range.

Think about it. With your code, the pulse is changing from 400uSec to 600uSec. The first shorter than the shortest servo pulse is meant to be, and the second only 100uSec into the range. About 9 degrees (assuming a 180 degree servo travel).

Code:

while(1)
  {
   delay_ms(1000);
   servo(500); //Minimum allowable pulse
   delay_ms(1000);
   servo(1000); //1/4 scale movement
   delay_ms(1000);
  }   
}


This also assumes you have got your chip's oscillator setup correctly with #use delay.
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