AnsweredAssumed Answered

LPTMR KL05

Question asked by Filipe Branco on Mar 18, 2014
Latest reply on Jun 19, 2014 by KL04 User

Hello,

 

I'm facing some problems using the KL05 FRDM board and i'm trying to toggle a pin using the LPTMR.
The LPTMR is clocked by the MCRIRCLK (32KHz) and i'm using a prescaler of 2 so the clock would be 16Khz. The result that i'm getting is 2msecs instead of 60uSecs.

Please find the code below:

 

#include "derivative.h" /* include peripheral declarations */

int main(void)

{

        SIM_SOPT1 |= (0<<18); //32K Oscillator clock

        SIM_SOPT1 |= (0<<19);

        SIM_SOPT1 = 0x00000000;

        SIM_SCGC5 |= (SIM_SCGC5_LPTMR_MASK | SIM_SCGC5_PORTB_MASK);// LPTMR gated PORTB

        PORTB_PCR8 |= 0x00000100;    // alternative pin mux selection //

        GPIOB_PDDR |= 0x00000100;    // pin direction //

        asm(" CPSIE i");

        NVIC_ICPR = 1 << (28);

        NVIC_ISER = 1 << (28);

 

       LPTMR0_CSR=0;

       LPTMR0_CSR |= 0x00000040; // HEX timer interrupt Enable

          /* Set the compare value to the number of ms to delay */

       LPTMR0_PSR = LPTMR_PSR_PCS(1)|LPTMR_PSR_PBYP_MASK;

       LPTMR0_CMR = 10; //Check what is the lowest we can get ?

          /* Start the timer */

       LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

}

 

void LPTimer_IRQHandler(void){

                  LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;

                  LPTMR0_CSR |= LPTMR_CSR_TCF_MASK;

                  GPIOB_PTOR |= (1<<8);

                  LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

        }

 

If anyone knows why this is happening please let me know.


Many Thanks

Filipe Branco

Outcomes