Design timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Design timer

136 Views
Contributor I

Hello;

   i want to design 1us timer.Why it doesn't work?MCU:9S12ZVL32

void InitTIM(void)
{
TIM0TSCR1_TEN = 0;
// TIM ch0 output compare
TIM0TIOS_IOS0 = 1;

// Precision timer disabled
TIM0TSCR1_PRNT = 0;

// TIM ch0 output no action
TIM0TCTL2_OL0 = 0;
TIM0TCTL2_OM0 = 0;

// Load prescaler value (one tick = bus clock / 32 = 32MHz / 32 = 1us)
TIM0TSCR2_PR = 5;
TIM0TSCR2_TOI = 1;

// TIM ch0 initial interrupt period
TIM0TC0 = TIM_PERIOD;

// Disconnect all output compare pins
TIM0OCPD = 0xFF;

// TIM ch0 interrupt enable
TIM0TIE_C0I = 1;

// TIM global enable
TIM0TSCR1_TEN = 1;
}

__declspec(interrupt) void TIMch0_ISR(void)
{
// Load period
TIM0TC0 = TIM0TC0 + TIM_PERIOD;
PTP = 0xff;
if(timer1s++>=1000)
{
//PTP = ~PTP;
}

// Clear flag
TIM0TFLG1 = TIM0TFLG1_C0F_MASK;
}

0 Kudos
3 Replies

24 Views
NXP TechSupport
NXP TechSupport

... and add....

      if(timer1s++>=1000)

      {

            PTS = ~PTS;

            timer1s = 0;       //      clear timer1s

      }

0 Kudos

24 Views
NXP TechSupport
NXP TechSupport

Hi,

You use interrupt function but it is not assigned to any vector....

One of the solutions:

Delete:

__declspec(interrupt) void TIMch0_ISR(void)

and use
interrupt VectorNumber_Vtim0ch0 void  TIMch0_ISR(void)

The constant VectorNumber_Vtim0ch0 is from mc9s12zvl32.h file. Do the same for PWM interrupt function

The another possibility is to define vector address or vector number in the prm file....

Also a suggestion: https://community.nxp.com/docs/DOC-330312 

Best regards,

Ladislav

0 Kudos

24 Views
Contributor I

This demo code

0 Kudos