Interrupts stopped workin

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Interrupts stopped workin

1,396 Views
Coderunner
Contributor III

Hello,

 

Maybe someone here can help me.

 

I was writing software and everything was working, untill at one point all my interrupts quit working.

 

I was using full PE emulator to check my timer count minutes hours etc. But now it will never hit the ISR???

 

/*****************************************************************************
 MC9S08JM60
 
 Program Function:

*****************************************************************************/
#include <hidef.h>          //for EnableInterrupts macro
#include <MC9S08JM60.h>     //include peripheral declarations
#include "LEDDEF.h"         //include external file with declarations and definitions

/*define led's*/
#define LED1 PTED_PTED2     //Port E 2 (LED1)
#define LED2 PTED_PTED3     //Port E 3 (LED2)
#define LED3 PTFD_PTFD0     //Port F 0 (LED3)
#define LED4 PTFD_PTFD1     //Port F 1 (LED4)
#define BUZ1 PTFD_PTFD4     //Port F 4 (BUZZER)

/*define switches*/
#define BTH10 PTGD_PTGD0    //Port G 0 (Hour 10s Button)
#define BTH1  PTGD_PTGD1    //Port G 1 (Hour 1s Button)
#define BTM10 PTGD_PTGD2    //Port G 2 (Minute 10s Button)
#define BTM1  PTGD_PTGD3    //Port G 3 (Minute 1s Button)


int i=0,H10=1,H1=1,M10=0,M1=6,S10=0,S1=0;



//*** Timer Interrupt ISR - 100ms
interrupt 15 void intTPM1OVF(){
  byte count=10;  
  count--;
  if(!count){                 //if count is 0 then 1 second passed
    count=10;
    S1++;
    if(S1>9){
      S10++;
      S1=0;
      if(S10>5){
        M1++;
        S10=0;
        if(M1>9){
          M10++;
          M1=0;
          if(M10>5){
            H1++;
            M10=0;
            if(H10>2){
              H10=0;
            }
          }
        }
      }
    }
  }
 
  TPM1SC_TOF = 0;         //reset timer overflow flag
}
                                    
      
/******************************MAIN********************************/
void main(void) {

  //*** Configure Multi-purpose Clock Generator (MCG) for 24MHz bus frequency
  //Switching from FEI Mode to PEE Mode
  //FEI --> FBE
  MCGC2 = 0x36;           
  while(!MCGSC_OSCINIT);              //loop until crystal has been initialized, OSCINIT = 1
  DisableInterrupts;                             //disable interrupts so no extra steps occur in 1.5MHz range
  MCGC1 = 0x98;                                 //CLKS=10 (Ext. ref); RDIV=011 (12MHz/8=1.5MHz)
  while(MCGSC_IREFST == 1);        //loop until IREFST = 0; Ext. reference is source
  while(MCGSC_CLKST != 0b10);   //loop until external ref. clock is selected to feed MCGOUT
  //FBE --> BLPE
  MCGC2 = 0x3E;                                 //LP = 1; BLPE MODE ON
  EnableInterrupts;
  MCGC3 = 0x48;                                 //1.5MHz*32=48MHz; PLL is selected (prepared for PBE)
  while(!MCGSC_PLLST);                  //loop until current source for PLLS clock is PLL; PLLST=1
  //BLPE --> PBE
  MCGC2 = 0x36;                                 //LP = 0; BLPE MODE OFF, PBE MODE ENTERED
  while(!MCGSC_LOCK);                   //loop until PLL acquired lock; LOCK=1
  //PBE --> PEE
  MCGC1 = 0x18;                                 //CLKS = 00; output of PLL or FLL is selected
  while(MCGSC_CLKST != 0b11);   //loop until PLL output is selected to feed MCGOUT  
 
  //EnableInterrupts;             //enable interrupts
 
  //Initialize Inputs
  PTGDD = 0;                    //initialize Port G as Input (Data Direction Register)
  PTGPE = 0x0F;                 //pullups on (PTG0..3)
  //Initialize Outputs  
  PTEDD = 0x0C;                 //initialize Port E bits 2 and 3 as Outputs
  PTFDD = 0x13;                 //initialize Port F bits 0, 1, and 4 as Outputs

  //*** Initialize TIMER module (TPM1)
  //Since MCG is in PEE mode, MCGFFCLK=1.5MHz, fixed sys clock=750kHz (1.5MHz/2)
  TPM1MOD = 0x493D;             //modulo value (terminal count): 18,749
  TPM1SC = 0x52;                //fixed sys clk (750kHz), prescaler 4 (TPM1 CLK=187.5kHz)
  TPM1SC_TOF = 0;               //timer has not overflowed




    
    
  //*** FOREVER LOOP
  for(;:smileywink:
  {
    __RESET_WATCHDOG();         //feeds the dog
    
    LED1 = BTH10;
    LED2 = BTH1;
    LED3 = BTM10;
    LED4 = BTM1;


  }
} /* please make sure that you never leave main */

/**************************END*MAIN********************************/

Labels (1)
0 Kudos
6 Replies

634 Views
bigmac
Specialist III

Hello,

 

Your ISR code seems to be based on a code snippet that I suggested in another post, with the exception that the count variable should be static, rather than local.

 

 

static byte count = 10;

 

 

Such a variable will only be visible from within the ISR function, but will retain the current value between calls to the function.  Also it will not be re-initialised for each call.

 

Regards,

Mac

 

0 Kudos

634 Views
CompilerGuru
NXP Employee
NXP Employee

Are you sure the issue are the interrupts?

The count variable is a local, therefore it will always be 9 when it reaches the if. Therefore the time digit variables are not incremented even if the interrupts happen.

Also I would make your digits a unsigned char, and as they are written from the interrupt handler also volatile.

Using a single variable for seconds (instead of one per second digit) would also simplify it, right now the H10 digit for example is not incremented.

 

Daniel

 

interrupt 15 void intTPM1OVF(){
  byte count=10; 
  count--;
  if(!count){ // count is 9 here...

0 Kudos

634 Views
Coderunner
Contributor III

OK I found what is causing my problem but not sure I fully understand why.

When I declare "byte count=100;" withing an ISR I get no updating of variables* in emulator (which seemed like interrupts were not being handled)

When I move that declaration out side of ISR, then it works.

 

*I have variables: MIN, HRS, SEC and count. And when I run the emulator I can see those values change (time count).

0 Kudos

634 Views
bigmac
Specialist III

Hello,

 

I think that you need to read a good basic text on C programming to understand the difference between global, static and local variables.

 

Regards,

Mac

 

0 Kudos

634 Views
Coderunner
Contributor III

Yeh, I'm realy new to C. I mean I've used it here and there but this is the first time when I'm starting to really use it. Thanks for everyone's help though.

0 Kudos

634 Views
Coderunner
Contributor III

I think it's interrupts because, you know how you can follow the code execution in PE Emulator? Well when it WAS working it would jump to the timer ISR, now it always statys in the FOREVER LOOP at the bottom of the MAIN. By the way it is not frozen since the button assignments to the LEDS that are inside teh FOREVER LOOP do work. ???

0 Kudos