strange interrupt behaviour

General discussion on mikroElektronika website & forums.
Post Reply
Author
Message
graham2550
Posts: 4
Joined: 22 Jun 2014 09:00

strange interrupt behaviour

#1 Post by graham2550 » 22 Jun 2014 09:19

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)
But timer0 seems to just go from 0 to 65535. Ignoring my "if " statement it seems.
very strange.
anyone help please, what am I doing wrong?

Code: Select all

 
sbit FOUT at RC0_bit;
sbit FOUT_Direction at TRISC0_bit;

unsigned int Timer_Count;

void InitTimer1(){
  T1CON	 = 0x31;
  TMR1IF_bit = 0;
  TMR1H	= 0x00;
  TMR1L	= 0x00;                 //max time available 100ms
  TMR1IE_bit = 1;
  INTCON = 0xC0;
}

void InitTimer0(){
  OPTION_REG = 0x88;
  TMR0 = Timer_Count;
  INTCON = 0xA0;

}

void Interrupt(){

  if (TMR1IF_bit){
    TMR1IF_bit = 0;
    Timer_Count ++;
    if(Timer_Count == 65513) Timer_Count = 140;      //65513 is 61khz, 140 is 20khz
  }

   if (TMR0IF_bit){
     TMR0IF_bit = 0;
     TMR0 = Timer_Count;
     FOUT = ~FOUT;
  }
}



void main() {
ANSEL = 0;      // all digital
ADCON0 = 0;     //turn off analog functions
CMCON0 = 7;     //turn off comparators
PORTC = 0;
TRISC = 0;      // port C outputs


Timer_Count = 140;
InitTimer1();
InitTimer0(); 

}


graham2550
Posts: 4
Joined: 22 Jun 2014 09:00

Re: strange interrupt behaviour

#2 Post by graham2550 » 25 Jun 2014 01:01

Solved. stupid me, an 8 bit timer.

Post Reply

Return to “Website & Forums General Discussion”