LPC111x capture reset timer

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

LPC111x capture reset timer

614 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 05:02:43 MST 2012
Hi,

Regarding Timer32 on the LPC111x family, is there a way when an external capture occurs, for the timer to be reset?
i am trying to measure time between pulses. Each time i enter the interrupt routine, i reset TC (but obviously i am losing clock cycles from the time the capture occurs, until the reset code is executed in the interrupt).

I realise i can use a free running timer and subtract the previous read caputre value from the current capture value, but I prefer not to do this, as i am using match register functions to do certain other things, which will interfere with a free running timer. Doing it this way also requires more code to deal with when the timer "rolls over" at the end.

Any ideas? did i miss something in the manual? or is there a better way to do this? All i need to do is measure time between continuous pulses. Very similar to PWM demodulation, except i only want the frequency, not the pulse width, so i am only reading rising edges, ignoring the falling edges.

Thanks.
0 Kudos
Reply
10 Replies

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 18:21:08 MST 2012

Quote: ToBeFrank

LPC_TMR16B0->TC = 0;                    //reset timer
This doesn't reset the prescale counter.


yes you are right, sorry i cut and pasted that code from elsewhere.
i use: [FONT=monospace]
[/FONT]LPC_TMR32B0->TCR  = 0x02;       //stop timer
LPC_TMR32B0->TCR  = 0x01;       //start timer

which i think clears both the TC and PR, but i'll double check data sheet later.
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 21 12:52:26 MST 2012

Quote: elef
...how many clock cycles...



A few values are posted here:

http://knowledgebase.nxp.com/showthread.php?t=2484
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ToBeFrank on Wed Mar 21 12:25:35 MST 2012

Quote: elef
Doing it this way also requires more code to deal with when the timer "rolls over" at the end.



Use unsigned math.

LPC_TMR16B0->TC = 0;                    //reset timer
This doesn't reset the prescale counter.
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 06:04:00 MST 2012

Quote: Zero
Didn't measure that, since I'm losing the same time next rising edge :rolleyes:


actually the more i think about it, probably not such a good idea to  assume i'm losing the time is the same as the previous one, because you could have  different delays depending if the capture occurs during normal code, existing interrupt, or tailchaining of interrupts, etc...

I think the only way to measure it accurately is to use a free running timer, so i  guess now i have to use another timer to do my match functions. Oh well.
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 05:51:39 MST 2012

Quote: Zero
Didn't measure that, since I'm losing the same time next rising edge :rolleyes:


good point, but i guess that means i would then need to prioritize this interrupt incase i am in another interrupt... hehe the joys are never ending!!!
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 21 05:45:48 MST 2012
Didn't measure that, since I'm losing the same time next rising edge :rolleyes:
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 05:25:22 MST 2012

Quote: Zero

http://knowledgebase.nxp.com/showthread.php?t=2815


read that post (i tried searching the forum before my first post!). he had the wrong interrupt routine being called, mine doesn't have that issue (the correct one is called). But thanks anyways.

i saw your post in that thread:
//read frequency
void TIMER16_0_IRQHandler(void)
{
 if(LPC_TMR16B0->IR & (1<<4))            //capture interrupt?    
 {
  LPC_TMR16B0->TC = 0;                    //reset timer
  period_time = LPC_TMR16B0->CR0;        //read time
  LPC_TMR16B0->IR |= (1<<4);            //reset capture interrupt
 }                                         //end capture interrupt
}

my code is nearly identical, except for timer32.
so my question is, how many clock cycles did you lose from the time the capture event occured, and this line:
LPC_TMR16B0->TC = 0;                    //reset timer
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 05:18:56 MST 2012

Quote: Zero
You could find a sample here:

http://knowledgebase.nxp.com/showthread.php?t=2815

or post your Code. Without it no one knows what you are talking about :rolleyes:


That was a quick response! Thank you. I will post my code when i get a chance. Maybe this helps summarize my post: I need to measure frequency accurately, how to do it?!

ps: ill try post code soon
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Wed Mar 21 05:15:11 MST 2012

Quote: elef
Hi,
did i miss something in the manual?


just to add, in the manual section 16.4 of UM10398, it says:
[I]Pulse Width Demodulator via capture input[/I]

Does anyone have any examples of how to do this accurately? from everything i can read in the manual (section 16.7.8), the only way for it to be "accurate" is to keep the timer running freely without resetting it. It's a real pain and it requires so much more software/cycles to calculate the time between the last timer value.
0 Kudos
Reply

529 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 21 05:12:46 MST 2012
You could find a sample here:

http://knowledgebase.nxp.com/showthread.php?t=2815

or post your Code. Without it no one knows what you are talking about :rolleyes:
0 Kudos
Reply