AVR performance monitoring using the Open Bench Logic Sniffer

in AVR, Logic Sniffer by DP | 1 comment

Alan wanted to check out just how much performance he could squeeze out of the ATMega328P. He needed was a way to measure the amount of time the CPU actually uses while executing various tasks. Using the Logic Sniffer to read a pin, that he toggles ON when the CPU is executing a task, and OFF when it is not. His testing is well documented, and he added some very good tips to speed up your code:

  • Wherever possible, use the hardware facilities of the AVR to offload work and help keep your application responsive.
  • Wherever possible, use interrupts to respond to external events. Also use them to handle output where there is a significant delay between each step of the output.
  • As far as possible, move anything other than trivial processing out of your ISRs into tasks which are prioritised relative to the other processing in your application.
  • Any kind of polling or spin-waiting is to be avoided as far as possible, the CPU cycles that such approaches consume can better be used for ‘real’ work.
  • Avoid using the standard Arduino libraries, because they are focused on simplicity and ease of use rather than performance.
  • Watch out for ‘hidden’ costs creeping into your code, such as the use of floating-point arithmetic when you don’t absolutely need to use it – examining the symbol table of your application is a good way of figuring out if you’ve inadvertently triggered its use.
  • A better algorithm will always outperform micro-optimisation approaches such as hand-coded assembler – I’ll discuss this further in a later post where I describe how I implemented the RGB LED handling

Via the forum.

This entry was posted in AVR, Logic Sniffer and tagged , , .

Comments

  1. John U says:

    Having been through this myself with MCF52259 it is a useful method and pretty easy to scatter things round which can be switched on/off with #defines to monitor different areas of code.

    One thing I found was a significant difference in the time taken to set/clear pins by direct writes to the set/clear registers instead of the read-modify-write type (PORTn |= BITn) which actually added a big error to measurements on a high-frequency ISR. Using PSET = BITn or PCLR = BITn was so much faster.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.