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

hardware problems of 16f876a

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







hardware problems of 16f876a
PostPosted: Wed Dec 30, 2009 2:47 am     Reply with quote

This program to generate the pulse for control digital servo. I have done it with 16f877a without problem. When I change to more small PIC, 16f876a the pulse can't be generate. I have simulate the program in proteus and it can generate pulse. When I download the program into pic16876a, its fail... can anyone help to solve this? Sad
Code:

#include <16f876a.h>
#include <stdio.h>
#use  delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp,NOBROWNOUT,PUT

#byte porta=5
#byte portb=6
#byte portc=7

int count;

void main()
{

   set_tris_b(0);
   //portb=0b00000000;

   while(true)
   {

         //0deg both servo
         for(count=0;count<170;count++)
         {
         output_high(pin_b0);     //right servo
         output_high(pin_b1);     //left servo
         delay_ms(1);
         output_low(pin_b0);
         output_low(pin_b1);
         delay_ms(1);
         }

         //40 degree for both servo
         for(count=0;count<170;count++)
         {
         output_high(pin_b0);
         output_high(pin_b1);
         delay_ms(1);
         delay_us(950);
         output_low(pin_b0);
         output_low(pin_b1);
         delay_ms(1);
         delay_us(950);
         }
   }
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Dec 30, 2009 7:16 am     Reply with quote

Most servo motors like a pulse rate of about 50 pulses per second. In your first loop you are sending 500 pulses and 250 pulses in the second loop.

Change both loops to take about 20ms each, or have a look at some example programs here: http://www.ccsinfo.com/forum/viewtopic.php?t=40239
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Wed Dec 30, 2009 4:23 pm     Reply with quote

As ckielstra already wrote your problem is in pulses you send to servo. You have to send a pulse every 20ms to the servo and with width you control how much servo moves. Pulse length will roughly be between 1ms for full left and 2ms for full right (it may be other way around) and at about 1.5ms it will be in the middle.
These times depends on servo model. I have posted some time ago an example written for PIC18F4550 how to control 8 servos with timer interrupt function. This could be rewritten to your PIC and if you have only two servos it will be easier.

If you still need help don't hesitate to ask 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