AnsweredAssumed Answered

S12ZVC timer Interrupt function

Question asked by 建江 袁 on Oct 10, 2018
Latest reply on Oct 11, 2018 by Daniel Martynek

I wrote the timer overflow interrupt function. It feels normal. But after debugging, I found that it can be used. Who can solve this problem?

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
unsigned int m_sec=0,m=0;
interrupt 20 void TOI_ISR(void);

void main(void) {

/********************************************/
/************ PLL INITIALIZATION ************/
/********************************************/
CPMUCLKS_PLLSEL = 1; //FBUS = FPLL/2. FBUS = 32MHz,
CPMUREFDIV_REFFRQ = 1; //Reference clock between 2MHZ and 6MHZ.
CPMUREFDIV_REFDIV = 0x1; //FREF=8/(1+1) = 4MHZ
CPMUSYNR_VCOFRQ = 0x1; //FVCO is between 48MHZ and 80MHZ
CPMUSYNR_SYNDIV = 0x7; //FVCO = 2xFREFx(SYNDIV+1) = FVCO = 2x4x(7+1) = 64MHZ
CPMUPOSTDIV_POSTDIV = 0x0; //FPLL = FVCO/(POSTDIV+1). FPLL = 64MHZ/(0+1) FPLL = 64MHz
CPMUOSC_OSCE = 1; //External oscillator enable. 8MHZ. FREF=FOSC/(REFDIV+1)
while(!CPMUIFLG_LOCK){} //Wait for LOCK.
CPMUIFLG = 0xFF; //clear CMPMU flags

/********************************************/
/*********** GPIO INITIALIZATION ************/
/********************************************/

//Use PP6 as output for LED
//DDRP_DDRP6 = 1;
DDRP_DDRP4 = 1;
/********************************************/
/************ TIM INITIALIZATION ************/
/********************************************/

//1. Configure the prescaler (TSCR2[PR]).
TIM0TSCR2_PR = 0b111;
//TIM0TC0 = TIM0TCNT + 1000;
//2. Configure needed channels as Input Capture (TIOS[IOSx]=0) or Output Compare (TIOS[IOSx]=1).
TIM0TIOS = 0;

//3. Enable interrupts if needed in the timer interrupt enable register (TIE).
TIM0TIE = 0;

//4. Set the timer enable bit (TSCR1[TEN]).
TIM0TSCR1_TEN = 1;
//TIM0TIE_C0I = 1;
EnableInterrupts;

/********************************************/
/************ LED BLINK LOOP ****************/
/********************************************/
for(;;){
;
}
}

interrupt 20 void TOI_ISR(void)// vector defined in the prm file
{
m++;
if(m==500)
{
PTP_PTP4 ^= 1;
m=0;
}

TIM0TFLG2 = 0x80;
EnableInterrupts;
}

Outcomes