I am creating a simple bug repeller, all it consists of is a ramping frequency between 20khz and 61khz.
I'm using a PIC16F688 at 20Mhz.
I use timer0 interrupt to switch a pin on and off to create a square wave.
I use timer1 interrupt at its slowest setting to increment the timer0 register, thus increasing the frequency.
when the variable for the timer0 gets to a certain point (61khz, 655315) I reset the variable to 140( 20khz)
The first pass starts correct frequency but the IF statement in the ISR to reset the numbers is totally ignored.
Timer0 just goes from 0 to 65535. Ignoring my "if " statement it seems.
very strange.
anyone help please, what am I doing wrong?
I'm using a PIC16F688 at 20Mhz.
I use timer0 interrupt to switch a pin on and off to create a square wave.
I use timer1 interrupt at its slowest setting to increment the timer0 register, thus increasing the frequency.
when the variable for the timer0 gets to a certain point (61khz, 655315) I reset the variable to 140( 20khz)
The first pass starts correct frequency but the IF statement in the ISR to reset the numbers is totally ignored.
Timer0 just goes from 0 to 65535. Ignoring my "if " statement it seems.
very strange.
anyone help please, what am I doing wrong?
Rich (BB code):
sbit FOUT at RC0_bit;
sbit FOUT_Direction at TRISC0_bit;
unsigned int Timer_Count;
void InitTimer1(){ //.1sec
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1H = 0x00;
TMR1L = 0x00;
TMR1IE_bit = 1;
}
void InitTimer0(){ //freq
OPTION_REG = 0x88;
TMR0 = Timer_Count;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = Timer_Count;
FOUT = ~FOUT;
}
if(TMR1IF_bit){ //0.2 second
TMR1IF_bit = 0;
TMR0IE_bit = 0;
Timer_Count ++;
if (Timer_Count > 65513) Timer_Count = 140; //65513 is 61khz, 140 is 20khz
TMR0IF_bit = 0;
TMR0IE_bit = 1;
}
}
void main() {
ANSEL = 0;
ADCON0 = 0; //turn off analog functions
CMCON0 = 7; //turn off comparators
PORTC = 0;
TRISC = 0; // port C outputs
Timer_Count = 140;
INTCON = 0xE0;
InitTimer1(); //.1 sec
InitTimer0(); //freq
while (1)
{
}
}