LPTMR0 always shows 0?

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

LPTMR0 always shows 0?

Jump to solution
1,611 Views
yasuhikokoumoto
Senior Contributor I

Hello all,

I found a strange behavior.

LPTMR0_CNR always shows 0.

My scenario below is to occur the compare interrupt of LPTMR.

As the interrupt caused normally and I had not cared the LPTMR0_CNR value.

That is, LPTMR0_CSR varied from 0x41 to 0xC1 but LPTR0_CNR kept 0.

I would like to see changing the LPTMR0_CNR value.

What should I do to do it?

    SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;     LPTMR0_PSR = ( LPTMR_PSR_PRESCALE(0) // 0000 is div 2                  | LPTMR_PSR_PBYP_MASK   // LPO feeds directly to LPT                  | LPTMR_PSR_PCS(LPTMR_USE_LPOCLK)) ; // use the choice of clock     LPTMR0_CMR = LPTMR_CMR_COMPARE(1000);  //Set compare value (100ms)     LPTMR0_CSR =(  LPTMR_CSR_TCF_MASK   // Clear any pending interrupt                  | LPTMR_CSR_TIE_MASK   // LPT interrupt enabled                  | LPTMR_CSR_TPS(0)     //TMR pin select                  |!LPTMR_CSR_TPP_MASK   //TMR Pin polarity                  |!LPTMR_CSR_TFC_MASK   // Timer Free running counter is reset                                         //  whenever TMR counter equals compare                  |!LPTMR_CSR_TMS_MASK   //LPTMR0 as Timer                 );     LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;   //Turn on LPT and start counting     while(1){       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);       printf("%x %x\n",LPTMR0_CNR, LPTMR0_CSR);    }

Best regards.

Yasuhiko Koumoto.

Tags (2)
1 Solution
927 Views
vinkar
Contributor III

Hello Sir,

Kindly try this. I am refering the "KL04 Sub-Family Reference Manual" for this.

Pls refer" 32.4.5 LPTMR counter" in page 539.

"The CNR cannot be initialized, but can be read at any time. On each read of the CNR,

software must first write to the CNR with any value. This will synchronize and register

the current value of the CNR into a temporary register. The contents of the temporary

register are returned on each read of the CNR."


Pls try writing a junk value to the LPTMR0_CNR and the reading it.

I think u will be able to do it.

But, if you are using interrupt for a timeout then I wld like you to note the "TCF" bit in LPTMR0_CSR register

"

Timer Free-Running Counter

When clear, TFC configures the CNR to reset whenever TCF is set. When set, TFC configures the CNR to

reset on overflow. TFC must be altered only when the LPTMR is disabled.

0 CNR is reset whenever TCF is set.

1 CNR is reset on overflow."

The interrupt happens when the CNR is equal or > CMR. So I feel when there is an interrupt and you go to the ISR, the CNR is already > CMR and therefore

it (CNR) is reset. There is a confusion here for me :smileyhappy:

But even I find sometimes its a bit dodgy.

Vinod.

View solution in original post

0 Kudos
4 Replies
928 Views
vinkar
Contributor III

Hello Sir,

Kindly try this. I am refering the "KL04 Sub-Family Reference Manual" for this.

Pls refer" 32.4.5 LPTMR counter" in page 539.

"The CNR cannot be initialized, but can be read at any time. On each read of the CNR,

software must first write to the CNR with any value. This will synchronize and register

the current value of the CNR into a temporary register. The contents of the temporary

register are returned on each read of the CNR."


Pls try writing a junk value to the LPTMR0_CNR and the reading it.

I think u will be able to do it.

But, if you are using interrupt for a timeout then I wld like you to note the "TCF" bit in LPTMR0_CSR register

"

Timer Free-Running Counter

When clear, TFC configures the CNR to reset whenever TCF is set. When set, TFC configures the CNR to

reset on overflow. TFC must be altered only when the LPTMR is disabled.

0 CNR is reset whenever TCF is set.

1 CNR is reset on overflow."

The interrupt happens when the CNR is equal or > CMR. So I feel when there is an interrupt and you go to the ISR, the CNR is already > CMR and therefore

it (CNR) is reset. There is a confusion here for me :smileyhappy:

But even I find sometimes its a bit dodgy.

Vinod.

0 Kudos
927 Views
yasuhikokoumoto
Senior Contributor I

Hello vinod,

thank you! You are right.

I missed reading themt.

I became able to read LPTMR0_CNR.

Best regards,

Yasuhiko Koumoto.

927 Views
vinkar
Contributor III

u r welcome sir.

0 Kudos
927 Views
oleksandrpylype
Contributor I

Hi all,

I tried to implement simple timer interrupt every (not important) sec. I set up LPTimer code is below.

It is counting I print it and it count until Compared value then reset counter and start count again, but should be interrupt when counter reach Compared value and

I dont see it.

Here set up code:

  1. //enable clock for LPTMR0
  2.     SIM_SCGC5 |= SIM_SCGC5_LPTMR_MASK;
  3.     // reset LPTMR
  4.     LPTMR0_CSR = 0;
  5.     LPTMR0_PSR = 0;
  6.     LPTMR0_CMR = LPTMR_CMR_COMPARE(10000);
  7.     LPTMR0_CSR = (LPTMR_CSR_TCF_MASK      // Clear any pending interrupt   and LPT interrupt enabled
  8.                   | LPTMR_CSR_TIE_MASK
  9.                   |!LPTMR_CSR_TFC_MASK   // Timer Free running counter is reset  
  10.                                         //  whenever TMR counter equals compare 
  11.                   |!LPTMR_CSR_TMS_MASK   //LPTMR0 as Timer 
  12.                 ); 
  13.   //enable LPTMR module
  14.   LPTMR0_CSR |= (1 << 0);

Here ISR of timer:

  1. void LPTimer_IRQHandler( void )
  2. {
  3. GPIO_DRV_TogglePinOutput( kGpioLED1 );
  4. }

Where can be the problem?

Thanks in advance/

0 Kudos