AVR performance monitoring using the Open Bench Logic Sniffer

Posted on Wednesday, June 13th, 2012 in AVR, Logic Sniffer by DP

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 on Wednesday, June 13th, 2012 at 11:00 am and is filed under AVR, Logic Sniffer. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “AVR performance monitoring using the Open Bench Logic Sniffer”

  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 Reply to John U

Click here to cancel reply.

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

Recent Comments

  • Joe Desbonnet: Ya, I can recommend the low melting point solder. I used brand 'ChipQuik' and it's amazingly easy to use.
  • Jerome: I need a new BusPirate for the Fablab ;) Many thanks!
  • Max: Seems like an unexpectedly violent way to remove the chip indeed. A hot air station should of course do the job just fine, but in...
  • jose: Part removal described here is pure butchery, the cheapest hot air station will do a fast and clean job removing the QFP, heat air to...
  • Cody: Yes please