yohanevindra
New Member
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.
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);
}