“Software Compare” mode - timer interrupt is triggered at every TPM2_MOD value, and not at TPM2_C0V value

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

“Software Compare” mode - timer interrupt is triggered at every TPM2_MOD value, and not at TPM2_C0V value

1,058 Views
anand-k
Contributor III

Hello,

I was trying to generate timer interrupt on TPM2 of KL15 processor.

I used following function in setting up the timer interrupt.

void Tpm2Init(void)

{                               

                //! Status and Control Register (TPM2_SC)

                //! - Clear status and control register

                TPM2_SC = (uint32_t)0x00000000;

               

                //! Modulo Register (TPM2_MOD)

                // TODO: Update these values based on power modes

                //! - Period value is 10 milli seconds / (1/6MHz)  = 60000

                TPM2_MOD = (uint32_t)0x0000EA60;

               

                //! Channel Status and Control Register (TPM2_C0SC)

                //! - Enable channel interrupt [CHIE = 1]

                //! - TPM Channel disabled [MSB = 0, MSA = 1, ELSB = 0, ELSA =0]

                TPM2_C0SC = (uint32_t)0x00000050; 

               

                //! Channel Value (TPM2_C0V)

                // TODO: Update these values based on power modes   

               //! - Period value is 1 milli second / (1/6MHz)  = 6000       

                TPM2_C0V = (uint32_t)0x00001770;

               

               

                //! Status and Control Register (TPM2_SC)

                //! - Timer Overflow Interrupt Enable [TOIE = 0]

                //! - LPTPM counter operates in up counting mode [CPWMS = 0]

                //! - LPTPM counter increments on every LPTPM counter clock [CMOD = 1]

                //! - Prescaler Factor Selection is divide by 4 [PS = 2]

                TPM2_SC = (uint32_t)0x0000000A;

}

I checked and found out that timer interrupt is triggered for every 10 milli seconds with the above mentioned code (at TPM2_MOD value) and not at TPM2_C0V value.

I would like to know whether TPM2_C0V will be used in “Software Compare” mode. 

In “SIM_SOPT2” register MCGFLLCLK is selected as TPM clock source and I have configured MCGFLLCLK as 24 MHz.

Could anyone help me on this?

Thanks in advance,

Regards,

Anand

0 Kudos
Reply
1 Reply

734 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Anand,

The reason is you aren't correct set TPM mode to output compare, please check below picture, which need [ELSnB:ELSnA] with correct setting (not all 0).

And you also enable timer overflow interrupt, which will generate interrupt when MOD value reached.

Wish it helps.

B.R.

Ma Hui

TPM Mode.jpg

0 Kudos
Reply