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.
Solved! Go to Solution.
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.
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.
Hello vinod,
thank you! You are right.
I missed reading themt.
I became able to read LPTMR0_CNR.
Best regards,
Yasuhiko Koumoto.
u r welcome sir.
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:
Here ISR of timer:
Where can be the problem?
Thanks in advance/