Programming problems

Post date: Mar 05, 2015 4:7:11 PM

Programming went very smoothly until I tried to implement a frame rate. The idea was to flash a frame to the cube and wait until it is time to flash the next frame. This way the time between frames is constant even when the time it takes to run the animation code may vary when doing intensive dynamic animations. If it takes too much time to execute the animation code for that frame, an indicator light would turn on, telling me that the cube can't keep up; it is overloaded. In which case I would either optimize the code, or lessen the frame rate. Unfortunately, I couldn't get it to work. I spent a few hours trying to figure out why, but my logic and syntax were correct, so I took a different approach: instead of going into a while loop and breaking out at the right time, I tried calculating and waiting the amount of time until the next frame, but I couldn't get that to work either. After a few more hours, I gave up, concluding that something was funky.

A while later, when programming animations, I ran into another problem where the code didn't run as expected. After some debugging, I noticed a peculiar side effect whenever I called the function to dim all the lights: the value of a variable, completely unrelated and isolated, changed. This was a very strange effect, and again, after hours of trying to figure out why, I gave up, confident that my code was correct with something else going on.

When programming a complicated animation, I wanted to use debug statements printed out to the serial monitor. But when I set it up, It didn't work. Instead, it was behaving very strangely and outputting random data or repeating previous outputs, which is not what I told it to do. It is difficult to debug when your debug tool needs to be debugged. I tried it on a different microcontroller and had the same problem, but when I tried it in a blank sketch, it worked. There was something in my sketch messing with the serial communication, but I had purposefully avoided those pins so there wouldn't be conflicts. After a bunch of research, I began to become more confident that I was doing everything right, but there was something funky going on.

I learned that serial communication takes a relatively large amount of RAM, then I realized that the microcontroller I was using only had 2K of RAM. To compare, this post is already over 2k- one byte per character, and there are well over 2000 characters. I probably ran out of memory early on and funky things were happening because data was being overwritten. That would explain all the mysterious problems I've been having.

To fix this, I could add external RAM, but that would significantly slow everything down because it takes time to access the data. I could also try to optimize to fit within the ATmega328P's 2k RAM limit, but that would greatly limit me and what I can do when programming animations. The point of this project was to set up a platform that I could use for creative programming, and I don't like my creativity to be limited. So I did some research and found a microcontroller that has 16k RAM, the ATmega1284P, which comes in a forty pin DIP package so that I can use it on a breadboard. I ordered it and await its arrival.

-Jeremy