EmbeddedRelated.com
Forums

Timing measurement in LPC2138?

Started by bachkhoa85 May 9, 2008
Dear all,

I am trying to setup the 32-bit timer to measure the execution time of
the program. The setting is according to the "Initialization code_hints
for the LPC2000 family" and the manual. However, the timer gives a
erratic result >_<

I setup a simple measurement as follow
tStart = T0TC;
for (i=0;i tEnd = T0TC;
t = tEnd - tStart;

I expect the for execution time to increase somewhat proportionally
with n, but the result is
n=3 -> t= 58
n=4 -> t= 79 (+21)
n=5 -> t= 78 (-1 ???)
n=6 -> t= 101(+23)
n=7 -> t= 120(+19)
n=8 -> t= 147(+27)
n=9 -> t= 130(-17 ???)
n-> t= 161(+31)

Have anyone tried to measure the execution time on LPC2xxx? Please give
me some advices

Thank you very much,
Richard

PS:
This is the chip initialization code as taken from the "Initialization
code_hints for the LPC2000 family" and the manual.

//set CCLK = 60Mhz
PLLCFG=0x25;
feed();
PLLCON=0x1;// Enabling the PLL
feed();
while(!(PLLSTAT & PLOCK)){}// Wait for the PLL to lock to set frequency

// Connect the PLL as the clock source
PLLCON=0x3;
feed();

//set PCLK = CCLK
VPBDIV = 0x1;

//Reset timer
T0TCR = (unsigned long)0x2; //reset timer
T0CTCR = (unsigned long)0x00000000; //set control reg to timer mode,
increase every rising PCLK edge
T0PR = (unsigned long)0x00000000;//Timer0 prescale = 0
T0TCR = (unsigned long)0x00000001; //enable timer 01

An Engineer's Guide to the LPC2100 Series

Hi,

what is the width of t? If it is not 32 bits wide and unsigned, then you
need to handle timer overflows.

Foltos

bachkhoa85 wrote:
> Dear all,
>
> I am trying to setup the 32-bit timer to measure the execution time of
> the program. The setting is according to the "Initialization code_hints
> for the LPC2000 family" and the manual. However, the timer gives a
> erratic result >_<
>
> I setup a simple measurement as follow
> tStart = T0TC;
> for (i=0;i > tEnd = T0TC;
> t = tEnd - tStart;
>
> I expect the for execution time to increase somewhat proportionally
> with n, but the result is
> n=3 -> t= 58
> n=4 -> t= 79 (+21)
> n=5 -> t= 78 (-1 ???)
> n=6 -> t= 101(+23)
> n=7 -> t= 120(+19)
> n=8 -> t= 147(+27)
> n=9 -> t= 130(-17 ???)
> n-> t= 161(+31)
>
> Have anyone tried to measure the execution time on LPC2xxx? Please give
> me some advices
>
> Thank you very much,
> Richard
>
> PS:
> This is the chip initialization code as taken from the "Initialization
> code_hints for the LPC2000 family" and the manual.
>
> //set CCLK = 60Mhz
> PLLCFG=0x25;
> feed();
> PLLCON=0x1;// Enabling the PLL
> feed();
> while(!(PLLSTAT & PLOCK)){}// Wait for the PLL to lock to set frequency
>
> // Connect the PLL as the clock source
> PLLCON=0x3;
> feed();
>
> //set PCLK = CCLK
> VPBDIV = 0x1;
>
> //Reset timer
> T0TCR = (unsigned long)0x2; //reset timer
> T0CTCR = (unsigned long)0x00000000; //set control reg to timer mode,
> increase every rising PCLK edge
> T0PR = (unsigned long)0x00000000;//Timer0 prescale = 0
> T0TCR = (unsigned long)0x00000001; //enable timer 01
>
>
On Fri, 09 May 2008 12:09:33 +0200, you wrote:

>Hi,
>
>what is the width of t? If it is not 32 bits wide and unsigned, then you
>need to handle timer overflows.
>
>Foltos
>
>bachkhoa85 wrote:
>> Dear all,
>>
>> I am trying to setup the 32-bit timer to measure the execution time of
>> the program. The setting is according to the "Initialization code_hints
>> for the LPC2000 family" and the manual. However, the timer gives a
>> erratic result >_<
>>
>> I setup a simple measurement as follow
>> tStart = T0TC;
>> for (i=0;i >> tEnd = T0TC;
>> t = tEnd - tStart;
>>
>> I expect the for execution time to increase somewhat proportionally
>> with n, but the result is
>> n=3 -> t= 58
>> n=4 -> t= 79 (+21)
>> n=5 -> t= 78 (-1 ???)
>> n=6 -> t= 101(+23)
>> n=7 -> t= 120(+19)
>> n=8 -> t= 147(+27)
>> n=9 -> t= 130(-17 ???)
>> n-> t= 161(+31)

This method should work.
is n a constant or a variable?
If the former, it's possible that the compiler may be generating different code - look at the
assembler output, or check the interval on a scope.
The MAM may also be influencing things.
>> Have anyone tried to measure the execution time on LPC2xxx? Please give
>> me some advices
>>
>> Thank you very much,
>> Richard
>>
>> PS:
>> This is the chip initialization code as taken from the "Initialization
>> code_hints for the LPC2000 family" and the manual.
>>
>> //set CCLK = 60Mhz
>> PLLCFG=0x25;
>> feed();
>> PLLCON=0x1;// Enabling the PLL
>> feed();
>> while(!(PLLSTAT & PLOCK)){}// Wait for the PLL to lock to set frequency
>>
>> // Connect the PLL as the clock source
>> PLLCON=0x3;
>> feed();
>>
>> //set PCLK = CCLK
>> VPBDIV = 0x1;
>>
>> //Reset timer
>> T0TCR = (unsigned long)0x2; //reset timer
>> T0CTCR = (unsigned long)0x00000000; //set control reg to timer mode,
>> increase every rising PCLK edge
>> T0PR = (unsigned long)0x00000000;//Timer0 prescale = 0
>> T0TCR = (unsigned long)0x00000001; //enable timer 01
>>
>>
Thank a lot for reply, I have checked everything

The method works well for MAM mode 0. When enable the MAM, the
problem happens.

I tried to measure time for each individual loop like this

Tstart = T0CT;
for (i=0;i Tend = T0CT;
t[i] = Tend - Tstart;
Tstart = T0CT;
}

And I tried to measure them combined
Tstart = T0CT;
for (i=0;i Tend = T0CT;
Total = Tend - Tstart;

I find that Total >> sumAll(t[i]).

In example
Mode 1: n = 10 --> Total = 200, sumAll(t[i]) = 172

Can anyone please give me some suggests why there is such a
difference?

Thank you very much
--- In l..., Mike Harrison wrote:
>
> On Fri, 09 May 2008 12:09:33 +0200, you wrote:
>
> >Hi,
> >
> >what is the width of t? If it is not 32 bits wide and unsigned,
then you
> >need to handle timer overflows.
> >
> >Foltos
> >
> >bachkhoa85 wrote:
> >> Dear all,
> >>
> >> I am trying to setup the 32-bit timer to measure the execution
time of
> >> the program. The setting is according to the "Initialization
code_hints
> >> for the LPC2000 family" and the manual. However, the timer gives
a
> >> erratic result >_<
> >>
> >> I setup a simple measurement as follow
> >> tStart = T0TC;
> >> for (i=0;i > >> tEnd = T0TC;
> >> t = tEnd - tStart;
> >>
> >> I expect the for execution time to increase somewhat
proportionally
> >> with n, but the result is
> >> n=3 -> t= 58
> >> n=4 -> t= 79 (+21)
> >> n=5 -> t= 78 (-1 ???)
> >> n=6 -> t= 101(+23)
> >> n=7 -> t= 120(+19)
> >> n=8 -> t= 147(+27)
> >> n=9 -> t= 130(-17 ???)
> >> n-> t= 161(+31)
>
> This method should work.
> is n a constant or a variable?
> If the former, it's possible that the compiler may be generating
different code - look at the
> assembler output, or check the interval on a scope.
> The MAM may also be influencing things.
> >> Have anyone tried to measure the execution time on LPC2xxx?
Please give
> >> me some advices
> >>
> >> Thank you very much,
> >> Richard
> >>
> >> PS:
> >> This is the chip initialization code as taken from
the "Initialization
> >> code_hints for the LPC2000 family" and the manual.
> >>
> >> //set CCLK = 60Mhz
> >> PLLCFG=0x25;
> >> feed();
> >> PLLCON=0x1;// Enabling the PLL
> >> feed();
> >> while(!(PLLSTAT & PLOCK)){}// Wait for the PLL to lock to set
frequency
> >>
> >> // Connect the PLL as the clock source
> >> PLLCON=0x3;
> >> feed();
> >>
> >> //set PCLK = CCLK
> >> VPBDIV = 0x1;
> >>
> >> //Reset timer
> >> T0TCR = (unsigned long)0x2; //reset timer
> >> T0CTCR = (unsigned long)0x00000000; //set control reg to timer
mode,
> >> increase every rising PCLK edge
> >> T0PR = (unsigned long)0x00000000;//Timer0 prescale = 0
> >> T0TCR = (unsigned long)0x00000001; //enable timer 01
> >>
> >>
> >>
> >>
> >>
> >>