Wednesday, May 25, 2011

Processing Speed

It turns out I was wrong about not being able to output floating numbers from the microcontroller to the computer. Its just that there was a simple command that I was familar with that would conveniently string together outputs and put them together on one line for you. That function couldn't handle floating point numbers. I've figured out a simple way to do it so that it is in a format I like. I guess this just shows how little I know about programming.

With that thought in mind, I decided this would be a good time to test out how quickly the microcontroller can run through programming, particularly math intensive programming. How quickly it would be able to run some of the geometry functions (like arctan) will go a long way towards determining how frequently the controller will be able to cycle through its programming, as well as how tolerant it will be of the ineficient programming I will be feeding it. Doing a check on this would also give me the chance to learn the syntax of some useful functions like a for loop and commands for measuring time.

To do this I simply put a loop around a big chunk of my compass code forced the controller to do that loop 10,000 times, and checked the time immediately before and after. The loop consisted of:
- offsetting and scaling the three raw magnetometer readings (these were already stored in memory)
- going through 4 conditional checks to determine the proper way to calculate heading
- calculating the heading using and arctangent function
- converting from radians to degrees and then offsetting for declination

Doing all that 10,000 times takes approximately 2.3 seconds, which means it runs through that loop in less than 1/4300th of a second. Not bad for a cheap 16MHz processor. Kinda makes you wonder why your laptop is so slow, doesn't it? A modern laptop processor should be able to run instructions a couple thousand times faster than this microcontroller.

No comments:

Post a Comment