I recently fought a few hardware/software battles and actually won! Don't ask me how... But I learned a few things (that I KNOW most of you 1000+ post counters already know!) that I want to share. First, a simple description of the project:
1) ATmega328 controller for my aquarium.
2) Drives 3 external high voltage (62V) LED drivers via PWM. 180W of LED power!
3) DS1307 RTC onboard and communicating via I2C
4) External 20x4 LCD display that communicates via I2C
5) Several Dallas 1-wire DS18B20 temperature sensors (water, free air, hood air, pump temperature, etc)
6) LED drivers on the back on the left, controller on the back on the right and the LCD display on the front on the left.
The first problem was found because of the second problem:
Watchdog time was NOT resetting the AVR even though it had "locked up".
Cause of problem: watchdog reset was inside an interrupt, not the main loop (or other critical) loop! Moving the watchdog reset to the inside of a fast and critical function caused the AVR to actually reset when the second issue occurred!
Watchdogs are nice, but know what you are doing with them. I didn't and it definitely could have been a problem on the fully implemented controller (heater anyone?).
The root cause of the "lockup" took way longer to figure out than I want to admit to. Especially because all the hardware worked PERFECTLY on the bench for over a month before I mounted the lighting system. Which was when these lockups started.
Cause of the problem: The cable carrying the I2C signal to the LCD had to transverse the length and width of the hood. To minimize the flexure on the cable when the hood was opened an closed, I ran cable right along the hinge joint nearly the width of the hood. Which put the cable nearly running the length the LED arrays right between two of the arrays.
When the LEDs approached 90% or more PWM (used a sine wave for dusk to dark lighting), they arrays generated enough noise on the I2C line to cause the RTC (same I2C bus as the LCD) to lockup. The RTC generated a 1 second square waver output that was used to set several different flags that told the main loop when to do things... No flags, nothing for the AVR to do, so it just sat there doing, well, nothing. Which looks a whole lot like a "lockup"!
Solution: Reroute the LCD cable to keep it as far from the LCD arrays as possible. My attempt to keep the LCD cable from being a long term problem (breaking wires) lead to a huge short term problem.
This does lead to one question I have: Does anyone have any recommendations for how to filter the signal and power lines on something like this to minimize noise issues? Would a simple RC filter were everything comes into the board work in "most/many" cases? Better ideas?
Does anyone have an recommended online resources for dealing with these types of noise issues?
Thanks for listening! I really had to get that off my chest for some reason!