Friday, June 30, 2017

A curious bug

Here's a bug I haven't had before: my code broke because something else was improved. I had some Arduino code that needed to display text on a two-line LCD. Everything worked a couple of months ago. Today I made some changes irrelevant to the screen display code, and the screen display started omitting characters. I got worried it was a hardware issue of some sort, but my best guess what happened was this: The Arduino IDE was reinstalled, and the new version must have optimized something. As a result, the code ran faster than before, and the LCD couldn't keep up with it. To fix, I had to add about five microseconds extra delay per byte being sent to the LCD.

If this wasn't microcontroller code, one would use a timer rather than a hardcoded delay, and the problem wouldn't occur. But using a timer would likely be less efficient, and I wanted maximum efficiency in this part of the code. I'm not used to dealing with hardware at this low level, and so I'm not used to "too fast" being a problem (except with user interaction).

No comments: