AnsweredAssumed Answered

[Help] MC9S12XS PIT Problem

Question asked by Pogo Lin on Oct 20, 2013
Latest reply on Feb 19, 2018 by 赵子成

Hi all,

I try use PIT to do something on MC9S12XS, but it only can work for PIT0.

The following list is my code.

 

void vfnScheduler_Init(void)

{  

    PITCFLMT_PITFRZ = 1;        /* PIT counter freeze while in Freeze mode */    

   

    PITMTLD0        = PIT_MICROTIMER_DIV0;/* PIT microtimer register = 40, PIT microtimer period = 40MHz/40   = 1Mhz */

    PITMTLD1        = PIT_MICROTIMER_DIV1;/* PIT microtimer register = 200, PIT microtimer period = 40MHz/200 = 200Khz */

 

 

    //Timer for laptimer, drag racing  1ms 

    PITMUX_PMUX0    = 0;        /* 16-bit timer 0 counts with micro time base 0 */

    PITCE_PCE0      = 1;        /* Enables PIT channel 0 */

    PITINTE_PINTE0  = 1;        /* Interrupt of PIT channel 0 is enabled */       

    PITTF_PTF0      = 1;        /* Clear PTI interrupt flag */

    PITLD0          = 999;      /* PIT register = 999, 1MHz/1000 = 1KHz = 1ms period */


    //send data to host 4Hz

    PITMUX_PMUX1    = 1;        /* 16-bit timer 1 counts with micro time base 1 */

    PITCE_PCE1      = 1;

    PITINTE_PINTE1  = 1;        /* Interrupt of PIT channel 1 is enabled */

    PITTF_PTF1      = 1;        /* Clear PTI interrupt flag */

    PITLD1          = 49999;     /* PIT register = 49999, 200KHz/50000 = 4Hz = 250ms period*/

   

    PITMUX_PMUX2    = 0;        /* 16-bit timer 2 counts with micro time base 0 */

    PITCE_PCE2      = 1;        /* Enables PIT channel 2 */

    PITINTE_PINTE2  = 1;        /* Interrupt of PIT channel 2 is enabled */       

    PITTF_PTF2      = 1;        /* Clear PTI interrupt flag */

    PITLD2          = 4999;      /* PIT register = 4999, 1MHz/5000 = 200Hz = 5ms period */

}

void interrupt ISR_PIT0_Timer(void)

{

    /* Verify that Real Time Interrupt caused the interrupt */

         if (PITTF_PTF0)

         {

...    

         }

    /* Clear the real time interrupt flag */

    PITTF_PTF0 = 1;

}

 

void interrupt ISR_PIT1_Timer(void)

{

    if( PITTF_PTF1 )

    {       

    ...

    }

    PITTF_PTF1 = 1;

}

void interrupt ISR_PIT2_Timer(void)

{

    if( PITTF_PTF2)

    {

...

    }

    PITTF_PTF2 = 1;//clear interrupt flag

}

 

 

PIT0 can work well, but PIT1 and PIT2 can't work. Please give me any suggestion. Thanks a lot.

Outcomes