THINKING outside THE IDE TO MAKE A FAST-COUNTING ARDUINO

[Udo Klein] took on the difficulty of counting as quick as possible using an Arduino board. The quest involves a search for short-cuts that will let him drive a 20-bit counter as swiftly as possible using the stock hardware. however the catch is that the Arduino atmosphere has some overhead running in the background which will slow things down. He looks into each of these road bumps, then shows one way to get around them.

The code uses a command we don’t usually see in modern C embedded programming; the goto statement. He’s using this to bypass the additional cycles used by the Arduino’s in-built loop() function. The only command that is run within his hacked loop is a deeply nested set of macros. They’re toggling output pins using the hardware XOR built into the AVR chip. This is directly addressing the registers as well as thereby dumps the slowdown added by the digitalWrite() function.

The result is a software counter that toggles the output lights (see the clip after the break) at about 98.9% of the hardware clock speed. pretty impressive, however [Udo] figures he can make it just a bit faster yet.

Leave a Reply

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