[S12ZVC] About using interrupt routine..

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

[S12ZVC] About using interrupt routine..

1,194 Views
daehyeonkim
Contributor II

Hello,

 

I got a S12ZVC evaluation board lately and I'm trying to test some source codes.

but I can not find the example source using interrupt for S12ZVC.

here is a simple code that I modified the timer example source. this isn't working.

could you please check this code?

 

ps.

I also want to use an interrupt routine like that,

interrupt routine

   if(TIM_flag) { ... }

   if(ADC_flag) { ... }

   if(RX_flag) { ... }

   ... continuing

}

can be including all case of interrupt counditions. is it possible?

 

 

//////////////////////////////////////////////////// Test code /////////////////////////////////////////////////////

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

 

 /* I CAN SEE RED UNDERLINE AT ISR ON THE CODE WARRIOIR.

BUT NO PROBLEM TO COMPLIE */

interrupt VectorNumber_Vtim0ovf void TIM_ISR()     
{
 TIM0TFLG2_TOF = 1;
 PTP_PTP6 ^= 1;
}

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_DDRP5 = 1;
 DDRP_DDRP4 = 1;
 DDRP_DDRP0 = 1;
 
 PTP_PTP6 = 1;
 PTP_PTP5 = 1;
 PTP_PTP4 = 1;
 PTP_PTP0 = 1;
 
 /********************************************/
 /************ TIM INITIALIZATION ************/
 /********************************************/
 
 //1. Configure the prescaler (TSCR2[PR]).
 TIM0TSCR2_PR = 0b111;   // Bus Clock / 128
 
 //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). (Input Capture/Output Compare Interrupt)
 TIM0TIE = 1;
 
 //4. Set the timer enable bit (TSCR1[TEN]).
 TIM0TSCR1_TEN = 1;
 
 EnableInterrupts;

 for(;;){

 }
}

Labels (1)
Tags (2)
0 Kudos
2 Replies

658 Views
lama
NXP TechSupport
NXP TechSupport

I have forgotten,

TIM0TFLG2_TOF = 1; is incorrect flag clearing approach.

If the flag register contains only one fleg then it is ok but in the case there are moree flags in the register you have to use write to entire register because writing to bit perform read modify write to entire registers and 1 is rewrien by 1 wihch clears all flags.

Example;

Let flags register contains 01010101

We want to clear bit 0 by flags_bit0 = 1;

Then CPU reads entire byte 01010101, performs write to the bit 0 and write entire bite back. As you can see all flags will be cleared.

Correct approach is flags = 0B00000001;  // or flags = 0x01

Description can also be found in http://www.nxp.com/assets/documents/data/en/application-notes/AN2554.pdf .

Best regards,

Ladislav

658 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I am sorry for limited support because of Christmas time. I am answering you from home and the boards are at work. However, I have on my notebook an example code for a different MCU from the devices family. It could be a good template for the MCU you use. If you look into main.c file where the description of the example code is placed you will find that it present interrupt solutions well as polling mode you want to use.

The difference between these modes is only whether the interrupt is enabled or not. The flag for event is independent. However in both cases you should not forgot to clear it to be able to catch a new event.  It is use in SCI peripheral in the example. I use my own interrupt table (module interruptvectortable.c and .h) to be able to process all unexpected interrupts. All interrupt are defined in the *.prm file on the bottom of the file. For ZVC the vectors could be probably adjusted because of different amount of peripherals.

I believe the example will help you to understand how it works.

Best regards,

Ladislav

0 Kudos