views:

116

answers:

2

I'm looking to write some very timing sensitive code on an LPC1343 where I need to count exact clock cycles. There are two issues :-

  1. I've read that code executing from the internal flash memory isn't always able to run at the full 72Mhz and wait states might be introduced. But I can't find any "official" document about this. I saw one place recommending to copy time sensitive functions into ram... I'm looking for either to be be told definitively that this doesn't happen, or for information on how it affects the timing.

  2. How long do branch instructions take? I read this core has branch prediction so timings might vary.. Is this correct, and if so is there any way to predict how it will behave, or disable that (as exact timing is more important than saving a few clock cycles for me).

+1  A: 

The instruction timing for Cortex-M3 is available from arm.com:

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337g/BABBCJII.html

There are also pipeline operations, so instruction counting is a bit fiddly.

Luther Blissett
A: 

Here's some real world investigation for LPC11xx and LPC13xx: http://knowledgebase.nxp.com/showthread.php?t=460

In short, there is no "right" answer, the results might depends on flash accelerator settings, memory alignment, bus architecture (neumann vs. harvard), 32-bit vs. 16-bit instructions and so on.

Igor Skochinsky