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*

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.

Hi Marcelino, you might try looking up some of the math here: https://en.wikipedia.org/wiki/Solar_azimuth_angle

There are lots of other resources that show examples and calculation steps. Adapting them within an AVR program should be straightforward. You might also wish to investigate the Solarlib project: https://github.com/millerlp/Solarlib