Easter 2014
It is currently 21 Apr 2014 10:48

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 20 Jun 2011 17:33 
Offline

Joined: 30 Mar 2009 21:03
Posts: 16
I have a problem which I can't explain in the timer interrupt routine Blink() in the following code:

/*
 * Project name:
     CBF600 flasheralarm
 * Copyright:
     (c) Eaglevision, 2008-2011
 * Revision History:
     20110615:
       - initial release;
 * Description:
     Starts buzzer when flashers exceed maxflash
 * Test configuration:
     MCU:             PIC12F683
*/

void Blink();

unsigned short counter = 0;
bit stateon;
unsigned short defaultflash = 0;
unsigned short maxflash = 0;
unsigned short oldstate = 0;

void interrupt()
{
   if (PIR1.TMR1IF)
   {
      Blink();
   }
}

void Init_Main()
{
   OSCCON = 0b00110000;                 // 500 kHz
//  OPTION_REG = 0x80;                  // enable WPU
   ANSEL = 0x00;                        // No AD convertor

   CMCON0 = 0x07;                       // Turn off comparators
   TRISIO = 0b00101001;                 // Configure GP1 and GP2 as output
   GPIO = 0x00;                         // Initialize GPIO port

   //Timer1 setup
   T1CON = 0x00;                        // no prescaler   flaher frequency 70 times per minute.
   PIR1.TMR1IF = 0;
   PIE1.TMR1IE = 1;
   T1CON.TMR1ON = 0;
   TMR1H = 0x00;
   TMR1L = 0x00;
   // Enable global interrupts
   INTCON.GIE = 1;
   INTCON.PEIE = 1;
}

void main()
{
   Init_Main();
   GP1_bit = 0;
   GP2_bit = 0;
   GP4_bit = 0;
   stateon = 0;
   counter = 0;
   TMR1H = 0x24;
   TMR1L = 0x92;
   defaultflash = 10;
   maxflash = defaultflash;
   T1CON.TMR1ON = 0;
   PIR1.TMR1IF = 0;
   while (1)
   {
      if (GP0_bit == 1 && !stateon)                     // flasher switch on
      {
         stateon = 1;
         counter = 0;
         GP2_bit = 1;
         T1CON.TMR1ON = 1;                             // start flash sequence
      }
      else if (GP0_bit == 0 && GP5_bit == 0)           // flasherswitch of
      {
         stateon = 0;
         GP2_bit = 0;
         GP4_bit = 1;
         T1CON.TMR1ON = 0;
         PIR1.TMR1IF = 0;
         TMR1H = 0x24;
         TMR1L = 0x92;
         counter = 0;
      }
   }
}

void Blink()
{
   counter ++;
   PIR1.TMR1IF = 0;
   TMR1H = 0x24;
   TMR1L = 0x92;
   GP2_bit = ~GP2_bit;
   if (counter > 15)
   {
      counter = 0;
      GP4_bit = ~GP4_bit;
   }
}


When the GP2 port reversal is executed the next if statement is not executed anymore. If I comment out the GP2_bit = ~GP2_bit; line the if statement is executed and GP4 port is toggled every 15th time.

Anybody any idea what can be the cause of this?


Top
 Profile  
 
PostPosted: 29 Jun 2011 10:17 
Offline
mikroElektronika team
User avatar

Joined: 03 Aug 2004 12:59
Posts: 6608
Try to clear the IF flag just before exiting the interrupt() function:

void interrupt()
{
   if (PIR1.TMR1IF)
   {
      Blink();   
   }
 PIR1.TMR1IF = 0;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Bing [Bot], d3VjL, Exabot [Bot], MaGiK and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group