Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 26th October 2009, 04:32 PM   #1
Default servo control problems

so im using the PICDEM2+ board and the minimal PIC18 board, and the servos just wont respond to the control signals

the servos keep twitching and dont respond to the control signals from the PIC..sometimes the twitching is more controlled with a control signal, & sometimes it isnt.they twitch from the time i plug in the power..

the oscillocope shows perfect pulses of min 1ms and max 2ms. what am i doing wrong/not doing?

the power supply for it is 5V regulated 3A.

we've tried about 3 different servos, same story..

it doesnt work in proteus either... here's the code again.. for 10Mhz..this code has been modified using the code given in the "junebug servo code" thread by pommie...

as per be80be reply, my board does not have the Y1 oscialltor and C4 and C5 capacitors. Y2 is the 4MHz osciallator.

Code:
#include <p18f452.h>

#define AzimuthServoPin PORTAbits.RA2
//#define ElevationServoPin PORTAbits.RA5

int ServoPosition;

void CCP2_ISR();

#pragma code high_pri_vec = 0x0008
void high_pri_vec()
{
	_asm
	GOTO CCP2_ISR
	_endasm
}

#pragma interrupt CCP2_ISR
void CCP2_ISR()
{	
	if(AzimuthServoPin==1)
	{
		AzimuthServoPin = 0;
		CCPR2 = 25000 - ServoPosition;
	}
	else
	{
		AzimuthServoPin = 1;
		CCPR2 = ServoPosition;
	}
	PIR2bits.CCP2IF = 0;
	
}

#pragma code
void main()
{	
	ADCON1 = 0x07;
	TRISAbits.TRISA2 = 0; //Set Pin A2 as an output for the Servo	
	AzimuthServoPin = 0;
	CCP2CON = 0b00001011; //Setup CCP2 to generate special event
	ServoPosition = 1875; //Mid point position for Servo
	CCPR2 = ServoPosition;
	T1CONbits.RD16 = 1;
	T1CONbits.T1OSCEN = 1;
	T3CON = 0b11001001; //Setup timer3, prescaler=2
	//TMR3H = 0;
	//TMR3L = 0;
	PIE2bits.CCP2IE = 1; //Enable CCP2 interrupt
	INTCONbits.PEIE = 1; //Enable peripheral interrupts
	INTCONbits.GIE = 1; //Enable all interrupts
	while(1);
}
yohanevindra is offline  
Old 27th October 2009, 04:15 AM   #2
Default

What's the low period between high pulses? They will twitch like that if the low period is too long. Check on your CRO and make it 1.5mS HIGH period and 20mS LOW period. That should centre the servo with no twitching.
Mr RB is offline  
Old 27th October 2009, 05:14 AM   #3
Default

Just noticed that you haven't got a config line. Are you setting your config manually?

Maybe you should add a config line,
Code:
#include <p18f452.h>

#pragma config WDT=OFF,LVP=OFF,OSC=XT,OSCS=OFF,DEBUG=ON

#define AzimuthServoPin LATAbits.LATA2
Without a config it will default to RC oscillator and that would cause problems. It also explains why it works in the simulator.

If your not using debug then set it to OFF.

Mike.

Last edited by Pommie; 27th October 2009 at 05:20 AM. Reason: Changed debug to on.
Pommie is online now  
Old 27th October 2009, 05:49 AM   #4
Default

so that configuration line is to configure
watch dog timer - off
low voltage programming - off
OSC -?
OSCS - ?
DEBUG - on?

im using the PICDEM2+ with a 4MHz crystal and then later on on a 10MHz crystal on a minimal PIC18 board...
will i hav to change the config stuff once i program it on the final PIC?
yohanevindra is offline  
Old 27th October 2009, 06:00 AM   #5
Default

With the 4Meg crystal you should use OSC=XT and for the 10MHz use OSC=HS. Actually, both should work fine as HS. See table 2.2 in the data sheet.

The OSCS setting stands for Oscillator Switch which allows the system to switch to the timer1 oscillator so this is best left off.

Mike.
Pommie is online now  
Old 27th October 2009, 06:27 PM   #6
Default

we ran the servos on a test circuit we found on the internet, and it seemed to work ok. but when we run it on the code it behaves really weird... did the onfig bit change, and still the same...
yohanevindra is offline  
Old 28th October 2009, 03:05 AM   #7
Default

Didn't you read my post??
Mr RB is offline  
Old 28th October 2009, 11:46 PM   #8
Default

Hi

Here's a great tutorial that uses a servo controlled by a PIC18:
http://www.dwengo.org/tutorials/light-tracker

It shows how to build a very simple light tracking robot with only a servo and two light sensors.

Slorn
Slorn is offline  
Reply

Tags
control, problems, servo

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
servo control robotdog Robotics Chat 7 26th March 2009 11:55 AM
Servo problems bananasiong Micro Controllers 0 16th September 2007 03:16 AM
continous servo control chyun84 Electronic Projects Design/Ideas/Reviews 4 20th November 2006 04:50 AM
How do you control digital servo. haku87 Robotics Chat 5 1st July 2006 11:49 AM
servo control with 16f84a mikeville Micro Controllers 2 20th January 2006 02:05 PM



All times are GMT. The time now is 04:20 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker