Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

control RC Micro servo motor using PIC16F877

Status
Not open for further replies.

annhenry

Newbie level 1
Newbie level 1
Joined
May 11, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
8
Hi,
I want to make a movement of RC Micro servo motor from 0 degree to 90 degree. Then, it will stop for a while and reverse back to 0 degree. I had made the servo motor move forward from 0 degree to 90 degree.But unsuccessfully make a reverse movement from 90 degree to 0 degree. I need a help to check my coding.What should i modify in my coding?I had done a lot of adjustment in the coding.But it still move to 90 degree.
Code:
#include <pic.h>                  // using 16F877
                        
//   configuration
//==========================================================================
__CONFIG ( 0x3F32 );           
                                 
#define servo   RB1

#define   MHZ   *1000L            /* number of kHz in a MHz */
#define   KHZ   *1               /* number of kHz in a kHz */

#define   Delay_us(x)   { unsigned char _dcnt; \
           _dcnt = (((x)*(20MHZ))/(24MHZ))|1; \
           while(--_dcnt != 0) \
              continue; \
         _dcnt = (((x)*    (20MHZ))/(24MHZ))|1; \
          while(--_dcnt != 0) \
           continue; }

void _Delay_ms(unsigned char y);    
                           // delay ms
void main(void)

{
  unsigned int i,a;
  TRISB = 0b00000001; // PORTB as Ouput Port(servo motor is RB1)
  PORTB = 0b00000000;  //clear portb
  
  while(1)
  {     
   //for(i=0;i<50;i++)
   //{
      
         servo=1;      //set servo pin low
         Delay_us(150);
         Delay_us(150);
         Delay_us(150);      
         
         servo=0;         //set servo pin high
         _Delay_ms(19);      
         Delay_us(50);     
         _Delay_ms(20); }
}
 
void _Delay_ms(unsigned char y)
{
   unsigned char   i;
   do {
      i = 4;
      do {
         Delay_us(250);
      } while(--i);
   } while(--y);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top