AVR math optimization

Following up on our previous post on understanding floating point math and speed of operations on 8-bit AVRs, we ran across an excellent article today on Arduino math optimization. Alan walks through his implementation of an exponential moving average algorithm. An exponential moving average normally requires floating point arithmetic, but due to the lack of native support on 8-bit AVRs, Alan worked out a way to do it with fixed point math.

After some experimentation, he was able to get his version running quite a bit faster than the floating point version, and offers a detailed writeup and tips along the way. Just as we found in our brief testing, the easiest AVR math optimization is to avoid division, since these processors don’t have a native divide instruction. If you’re looking to squeeze every last drop of performance out of your 8-bit chip and can’t (or won’t) upgrade to something more powerful, check this out for some good ideas.

Link: Sensor smoothing and optimised maths on the arduino

Original source: Hackaday

2 thoughts on “AVR math optimization

  1. I am a beginner on avr studio, and I would like to be able to calculate solar time, Eq of time, declination and solar zenith and finally calculate the position of the sun.

    I will be glad if you guys can help me on this.

Leave a Reply

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