LPTMR does not count.

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

LPTMR does not count.

1,159 Views
john71
Senior Contributor I

I set the LPTMR

SIM_SCGC5 |= SIM_SCGC5_LPTIMER_MASK;

    /* Reset LPTMR settings */
    LPTMR0_CSR=0;      

    /* Set up LPTMR to use 1kHz LPO with no prescaler as its clock source */
    LPTMR0_PSR = LPTMR_PSR_PCS(1) | LPTMR_PSR_PBYP_MASK;

    /* Set the compare value to the number of ms to delay */
    LPTMR0_CMR = 0xFFFF;

    LPTMR0_CSR |= LPTMR_CSR_TCF_MASK | LPTMR_CSR_TIE_MASK | LPTMR_CSR_TFC_MASK;

    /* Start the timer */
    LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;  

    enable_irq(85);

And I check

time = LPTMR0_CNR;

It's always 0. When I set break point and watch the registers - LPTMR0_CNR = 0x0000.

0 Kudos
3 Replies

678 Views
john71
Senior Contributor I

Thank you. Something new to me.  I used to simply read the counter register.

0 Kudos

678 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Mark is correct, On each read of the CNR, software must first write to the CNR with any value.

You can find the description in "42.4.5 LPTMR counter" of K10P144M120SF3RM.

LPTMR counter.png

I also notice that you have enable the Timer Free-Running Counter.

When 1kHz LPO is select as clock source. You may need to wait 65536ms , then run into LPTMR interrupt.

LPTMRx_CSR[TFC].png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

678 Views
mjbcswitzerland
Specialist V

Hi Evgeny

    unsigned long ulCnt;
    LPTMR0_CNR = 0;  // write any value to the counter register so that it puts its present counter value into a temporary register
    ulCnt = LPTMR0_CNR;  // read the value from the temporary register

If you read the register description in the manual you will see why. If you check the uTasker open source project you will probably already get all answers too.

Regards

Mark


uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html