MSP430 Timing Analysis

Howdy, everyone.

I have a C program written for the MSP430. The program is basically just an infinite loop, with different sections within the loop:

while(1) { /* section 1 */ /* section 2 */ ..etc.. }

The various sections have some 'if' and 'else' statements, so they take different amounts of time from iteration to iteration. Is there any convenient mechanism to determine how long these various sections take? Even an average/mean time would work (although a probability distribution function would be best).

Earlier, I resorted to using the actual MSP430 hardware to run a million iterations of each individual section, and used a handheld stopwatch to time it (I had it turn an LED off when it finished). This was a pain, and now I don't actually have the hardware anymore. So, I'm hoping for a software simulation tool.

Any help will be greatly appreciated.

-Chess

Reply to
Chess Saurus
Loading thread data ...

There are two basic approaches: simulation and realtime measurement.

You can use a simulator to get a very accurate measurement of the execution time, but this doesn't work well if you need to use realtime inputs for the code. It works well for situations where you can feed in a small set of typical data and time the processing.

For realtime measurement, I would drive an output once per cycle or during routine execution, then look at it on a digital scope. With the HP Megazoom, you can capture a wealth of information in a single snapshot, then blow it up and look at the timing.

The IAR package simulator will do this. If you program in assembly you can use the free kickstart version. You can use it determine the number of elapsed cycles up to the breakpoint that stops the execution.

Thad

Reply to
Thad Smith

You can always examine the code and figure out the cycle counts, although there are traps for the unwary with the MSP430 due to its emulated instrctions and constant generators.

The other simple method is to use the internal timers. Use the fastest stable clock frequency, for example I use 8MHz MCLK and run Timer B at

8MHz. Allocate a variable for counting timer overflows and a second for counting passes through the loop. before entering the loop Move TBR to START_TIME, and clear OVERFLOW_COUNT. Enable the Timer B overflow interrupt and count overflow events. At the start of each loop increment LOOP_COUNTER. When you've executed enough passes you can simply average the time. Alternatively you can start and stop the time at the beginning and end of the loop, and accumulate differences with a moving average filter.

Al

Chess Saurus wrote:

--
Please remove capitalised letters to reply
My apologies for the inconvenience
 Click to see the full signature
Reply to
onestone

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.