Lighting - Software

The light module software is entirely interrupt based.  After startup the there are three main functions: reading and processing the ADC, UART communications and the timers.  Of the three functions the most time critical is the current reading from the current sensor.  While the light is being dimmed the software has a limited amount of time to detect a zero crossing of the mains voltage, start a countdown timer and fire the TRIAC before the user is inconvenienced by flickering.  The TRIAC fires for approx 100us before being released.  The TRIAC will continue to remain on until the next zero crossing.  The light board is controlled by the remote which passes functions to it based on the function list file.  All communication is interrupt based as no function can block the processor for more then 800 clock cycles from the last ADC reading.  This could cause significant delay in the next zero crossing detection and thus flicker.  The dimmer function is programmed to allow full power on to off in 10% intervals.

Main Flow Diagram:

ADC:

 

Timers:

 

UART: