A while back I built a Christmas lights controller that used Vixen to create the light sequences. That project used mechanical relays and, while it worked fine, it didn't provide any real dimming capabilities. I've since moved on to version 2 of the controller using random-cross SSRs instead of the mechanical relays, the hardware is done, now and I'm working on the software. I'm trying to do full dimming of 32 channels of lights all controlled via the Vixen sequencing software.
I've already done most of what I can think of to speed it up, even before bothering to do real testing on it. (I've already tested the hardware side) My normal rule would be make it work then make it work fast. Unfortunately in this case if it isn't fast it just won't work.
I've put comments in the code explaining why I thought doing certain things would speed it up. I've also put in TODO: comments every place I'm curious about the method I used or think there is a better, faster way to do something.
What I would like is a little help or pointers in the right direction for squeezing every extra cycle possible out of the sketch. I've put the old (version 1) and new (version 2) code up here:https://code.google.com/p/arduino-christmas-lights-control-system-for-vixen/
The new code is the XmasLightControllerForVixenSSRs.ino download. I'm using 1.0.1 version of the Arduino IDE right now.
The basics of the sketch are:
1> reads 32 channels of data from Vixen via an FT232R breakout board on Serial1, Vixen sends me 32 channels (bytes) every 50ms but this is adjustable. I want to be able to handle the data at the fastest possible speed
2> uses an AC zero-cross detection circuit to trigger an interrupt so I can calculate when in the AC cycle to turn the digital pins on/off (this is the dimming, turn on later in the cycle makes the lights dimmer)
3> uses portions of the Faster Digital Write library to do port manipulations
4> has a random lights mode (you can ignore all the code related to this as it doesn't need to be fast)
5> uses Timer/Counter 1 in CTC mode to keep track of number of ticks (cycles) via an interrupt
6> The methods that have to execute as fast as possible are: loop(), readFromVixen(), ZeroCrossDetected(), ISR(TIMER1_COMPA_vect) - everything else can run slower.
7> uses an ArdunioMega 2560
Any insights you can give would be greatly appreciated. Thanks.