different run time durations for LPC1313

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

different run time durations for LPC1313

815 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by orhan.dirik on Tue Nov 13 01:55:50 MST 2012
We are using LPC1313FBD48 as the control MCU in our new medical design. For some safety reason we would like to measure the runtime duration of deterministic code piece. In the attached archive, at main.c a loop runs for 150000 times and a timer is used for measuring this duration.
The problem is we get different timer counts when changing the code BEFORE the timer starts. For example, when we use SysInit() function in main.c the timer counts 318753 each time we run the code. However, when we comment out the function and uncomment the part above it, the timer counts 312503. Please note that, the code piece above SysInit is the same as SysInit function itself. All in all, timer counts differ due to previous codes that do not even start the timer.
Can can we get rid of this problem?

Original Attachment has been moved to: lpc1313.rar

Labels (1)
0 Kudos
4 Replies

603 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Wed Nov 14 06:56:56 MST 2012
This could be the result of flash acceleration. Try running your code with 20 MHz maximum and FLASHTIM=0 in the FLASHCFG register. Any effect of the accelerator should then not be noticeable any more.

The benefit of the flash accelerator is on the *average* exceution speed. The position of instructions and literals in memory affects the efficiency of the acceleration, and compiler optimization is expected to have an effect on execution time when the same code is executed from different addresses.
0 Kudos

603 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Daniel Widyanto on Tue Nov 13 21:03:20 MST 2012
Well, the only way to check it is to disassemble your main() for both cases. My guess is that optimization level-0 never reuse register value to call the functions. Hence, it would generate longer assembly instructions.

Eg. For optimization lv 0<code>
ldr r0, #function1_addr
ldr r0, [r0]
bx  r0

ldr r0, #function2_addr
ldr r0, [r0]
bx  r0
function1_addr:
.word function1_addr_content
function2_addr:
.word function2_addr_content
</code>

Eg. For optimization higher than lv-0<code>
ldr r4, #function1_addr
ldr r0, [r4, #0]
bx r0

ldr r0, [r4, #4]
bx r0

function1_addr:
.word function1_addr_content
function2_addr:
.word function2_addr_content
</code>
0 Kudos

603 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by orhan.dirik on Tue Nov 13 07:15:04 MST 2012
the i checked, the timer starts from 0. StartTimer2() functions stops, resets, configures and starts the timer. I realized that the problem does not happen when I change the optimization to something different than level-0. Any comments?
0 Kudos

603 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Tue Nov 13 06:19:20 MST 2012
Have you used a debugger, to check, if your timer handling is correct, and timer2 REALY starts at 0 when you start it?
0 Kudos