Categories: all aviation Building a Biplane bicycle gadgets misc motorcycle theater

Tue, 26 Jul 2011

Hitting the Limits

I've been idly working on the ADI project when I've had a few moments, but I ran into something strange in the last few days.

I'd make a change to the code (at the time, trying to make the metric VSI display more useful), and all of a sudden, the ADI would start rebooting at random times, or get all wacky on me. Then I recalled a discussion I'd had with my friend Clint about the practical limits of an Arduino.

One of those limits (and one I hadn't considered before this conversation) is RAM. The ATmega328, the processor inside the Arduino Uno, has 2k of it. 2048 little bytes. And every string you load up, and every static or global variable, takes up some of that space, before you can even start running.

I didn't even need to do the math (although once I did, it was pretty silly): I have a splash screen with 17 characters times 5 lines. I have a menu with 7 items, each of which has a 17 character title. I have at least two data-smoothing buffers (and was adding a third when I realized what was going on), of 32 entries at 4 bytes per entry. I haven't bothered to count the global and static variables, but there are probably a dozen or two. Some of them are big, complex structs taking up many dozens of bytes each. The data buffers alone account for 384 bytes. The strings take up around 200 bytes. I'm well over a quarter through my RAM, and I haven't even started to run yet.

So, I pushed some of the strings out to flash (of which there's 32 kB), and shrunk the data-smoothing buffers down to 16 entries each. Suddenly, everything Just Works. It is a lovely and delightful thing when that happens. Interesting side-effect: the smoothed displays are still stable enough to be useful, and now they react faster. Woot!

Posted at 14:24 permanent link category: /gadgets


Categories: all aviation Building a Biplane bicycle gadgets misc motorcycle theater