Hi all im trying to control a servo using the timer interrupt. so when the 20ms interrrupt occurs a counter is incremented which sets the servo at a specific position which does happen however, i want it to change position when the second counter increments but this is not working... can any one help?
my code:
Moderator edit: added code tags
my code:
Code:
unsigned int count, Adcval;
unsigned int a =2000;
//Timer0
//Prescaler 1:256; TMR0 Preload = 100; Actual Interrupt Time : 19.968 ms
//Place/Copy this part in declaration section
void InitTimer0(){
OPTION_REG = 0x87;
TMR0 = 100;
INTCON = 0xA0;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 100;
count++;
}
}
void main()
{
TRISB=0; // PORTB IS OUTPUT
PORTB=0;// PORTB INITIAL VALUE IS 0
ADC_init();
//count=0;
InitTimer0();
while(1)
{
if (count==1)
{
RB0_BIT=1;
//Adcval = ADC_Read(2);
Delay_us(500);
RB0_BIT=0;
//count=0;
TMR0=100;
}
if (count==2)
{
RB0_BIT=1;
//Adcval = ADC_Read(2);
Delay_us(1500);
RB0_BIT=0;
TMR0=100;
count=0;
}
}
}