simple way to control servo motor

LINIX Brushless, VEXTA Brushless, RC Servo, DC Geared, Linear, Stepper, Tamiya.....

simple way to control servo motor

Postby JaydenCheah » Sun Jul 13, 2014 11:48 pm

I am trying to control the servo motor with PIC 16F877A and mplabX.Below is my coding for servo motor turn 90 degree,and reversed 90 degree. Unfortunately, i can not move the servo motor. Can i know which pin and register are related to control the servo motor. I am glad to see somebody reply.Thanx:)





#include "delay.h"
#include<htc.h>
#include"adc.h"
#define _XTAL_FREQ 8000000

__CONFIG( HS & // External Crystal at High Speed
WDTDIS & // Disable Watchdog Timer.
PWRTEN & // Enable Power Up Timer.
BORDIS & // Disable Brown Out Reset.
//MCLREN & // MCLR function is enabled
LVPDIS);
void main(void)
{
//int x = 125;
PORTA=0;
PORTC=0;
TRISA=0;
TRISC = 0b11111111 ; // configure RC3 as input (1 for input and 0 for output)
PR2 = 0xFA; //oxFA for 250 (used to set time period)
CCPR2L = 125; // (used to set duty cycle)
CCP2CON = 0b00001100; // select for PWM mode
T2CON = 0b00000110; // enabling timer 2, prescalar 16
adc_initialize();


while(1)
{
RA1=1;

if(RC3==1) // forward
{
// x=x+1

CCPR2L = 250+125; // (used to set duty cycle)
T2CON = 0b00000110; // enabling timer 2, prescalar 16
RC1=1;
}
if(RC4==1) // back ward
{
// x=x-1

CCPR2L = 250-245; // (used to set duty cycle)
T2CON = 0b00000110; // enabling timer 2, prescalar 16
}
DelayMs(2);
}

}
JaydenCheah
Greenhorn
 
Posts: 2
Joined: Sun Jul 13, 2014 11:23 pm

Re: simple way to control servo motor

Postby ober » Tue Jul 15, 2014 9:48 am

It seem your PORTC is being configured as input, it cannot output signal if it is input.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: simple way to control servo motor

Postby JaydenCheah » Tue Jul 15, 2014 10:05 pm

Hey man, thanks for ur help.Finally my servo are moving.XD Thank you for take time to reply me:)
JaydenCheah
Greenhorn
 
Posts: 2
Joined: Sun Jul 13, 2014 11:23 pm


Return to DC Motor

Who is online

Users browsing this forum: No registered users and 10 guests

cron