Timing Resolution

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Timing Resolution

1,356件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tgalluzzo on Mon Dec 26 16:43:22 MST 2011
Is there a way of measuring time that has higher resolution than systick? What if I need to measure time very accurately but I don't want to run the systick timer very fast? Is there another way to do this?

Thanks!
0 件の賞賛
返信
6 返答(返信)

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 27 16:10:04 MST 2011
The simplest way of measuring a time is just start a timer, let it count and stop it

Every 32bit timer at 100MHz (= resolution 10E-9 sec) is able to measure a time up to 42.9 seconds:

int main(void)
{
 volatile static int i = 0 ;

//set timer
 LPC_SC->PCONP |=     (1<<1);            //power on timer0
 LPC_SC->PCLKSEL0 &=~(3<<2);          //reset clock sel bits
 LPC_SC->PCLKSEL0 |= (1<<2);        //set clock sel bits:full speed = 100MHz
 LPC_TIM0->TCR = 1;                    //start timer

 while(1)
 {
  i++ ;
  if(i >= 1000)
  {
   LPC_TIM0->TCR = 0;                //stop timer
   i=0;
//use debugger to read timer register LPC_TIM0->TC here
   LPC_TIM0->TC =0;                  //reset timer register
   LPC_TIM0->TCR = 1;                //start timer again
  }
 }
 return 0 ;
}
0 件の賞賛
返信

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tgalluzzo on Tue Dec 27 15:27:45 MST 2011
Thanks I was just curious. I'm trying to measure the time between subsequent motor control iterations. I have a 1769. I understand what you mean about this being a timer job. I will look into them more.
0 件の賞賛
返信

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 27 15:22:45 MST 2011
As mentioned before, every timer can be clocked by main clock :eek:
Don't know what you are trying to do (measure a time or capture a signal), what chip you are using and what times you are trying to measure; but the answer is still: that's a timer job. And therefore timer0-x or RIT timer (LPC17xx) offer a lot of options.
0 件の賞賛
返信

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tgalluzzo on Tue Dec 27 14:34:41 MST 2011
Thanks Rob,

The SysTick->VAL technique is what I was looking for. That will work great. I'm just curious, is there a way to measure the CPU clock CCLK directly?

Thanks
Tom
0 件の賞賛
返信

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Dec 27 09:38:24 MST 2011
I guess tgalluzzo is using the systick timer to generate a system tick of 1 or 10 msec. But he want to measure a more accurate time.
Then just taking the systick time ticks as stored by the OS + the current counter value of systick will give wat you want.

The SysTick->VAL register in the systick timer gives you the current count of the systick timer. SysTick->LOAD tells you what value is used to reload the timer.
Don't forget: the systick timer counts down from it's reload value to 0, the period equals SysTick->LOAD [B][COLOR=Red]+ 1[/COLOR][/B].

Another option is to program one of the general purpose timers. Set the PCLK to CCLK and start/stop/reset the timer in your own program. I did something like this some years ago for the  lpc2106 (link to that page).

Regards,
[INDENT]Rob
[/INDENT]
0 件の賞賛
返信

1,346件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 26 17:04:36 MST 2011

Quote:
Is there a way of measuring time that has higher resolution than systick?

No :eek:

If SysTick is clocked by main clock, nothing can be faster :mad:

Don't know which chip you are using and which time you are trying to measure, but measuring a simple time is usually done by a timer  :rolleyes:
0 件の賞賛
返信