This article demonstrates the use of a MIAC (Matrix Industrial Automotive Controller), programmed using Flowcode, to control a multi-channel, low voltage, dimmable, LED lighting system.
These notes detail the development of a multi-channel MIAC lighting control system.
The example program accompanying these notes is written and illustrated using Flowcode. The program includes a software controlled PWM signal generator for efficient multi-channel brightness control and LED brightness characteristic correction.
Recent developments in technology have allowed LEDs to become a realistic alternative to incandescent bulbs in many lighting applications. The high efficiency and long operating life of LEDs have important environmental implications.
The efficiency of LED bulbs makes them suitable as direct replacements for incandescent bulbs in low voltage lighting systems. Many are commercially available in packages that are compatible with standard light fittings. The bulbs are relatively easy to control and can be built into flexible lighting systems using safe, low voltage, electronic circuits.
A MIAC can provide fully programmable control of up to 8 lighting circuits. Four controlled by transistor outputs (all with PWM control), and four controlled by relays. In addition, there are eight inputs that can be used to read switches, potentiometers, and a variety of sensors.
Each MIAC transistor output is capable of supplying approximately 6Watts at 12V. This means that each channel can control a single bright-white 4W bulb, or several 1W coloured bulbs.
The Relay outputs are not suitable for PWM control, but are capable of supplying 96Watts each at 12V and can be used for low frequency switching of large banks of lamps.
The example program is a four channel analog to PWM light controller. Each channel (A, B, C, D) can be independently controlled by connecting a suitable analog signal source to the corresponding input (I1 = A, I2 = B, I3 = C, I4 = D)
Main program loop
The main program:
• Initialises all the variables
• Configures and enables the TMR0 interrupt
• Executes a continuous loop
In each cycle of the main loop, the program:
• Samples the voltages present on 4 independent inputs.
• Calculates the required output value for each channel and updates the control variables
• Waits for 50ms
The calculated brightness value for each channel is stored in an array variable, PWM_DUTY. The array is read automatically each time the TMR0 interrupt occurs, and the stored values are used to control the signal at each output terminal.
PWM (Pulse Width Modulation) is an efficient method for simulating analogue levels by rapidly switching a signal on and off at specific time intervals.
The PWM signals used to control the brightness of the lamps in this example are generated in software and controlled by a timer interrupt. This allows PWM control to be available on all four transistor outputs. The resolution of the PWM has been set to 6 bits, which is adequate for this application, and results in a good trade-off between interrupt frequency and PWM cycle period.
The timer interrupt occurs every 85.3μs and increments a byte variable, PWM_COUNTER, by 4, causing a cycle repeat every 64 interrupts (5.46ms - 183Hz).
The duty cycle (brightness) value of each channel is calculated in the main program loop and stored in a four byte array, PWM_DUTY.
Each time the timer interrupt occurs, the handler macro reads the channel values fro the array and performs the following operations:
IF PWM_COUNTER = 0 (start of a PWM cycle)
Turn ON the output of any channel with a non-zero duty value.
Turn OFF the output of any channel with a duty value that matches the current value of PWM_COUNTER.
Example of an interrupt handler for software PWM
The lamps used to develop this application are listed as being 'not dimmable'. It would appear that they are dimmable, but the variation in brightness is not linear. The programmability of the MIAC allows a profile to be created that improves the linearity of the brightness control. The example uses an array to convert eight brightness levels (including OFF) to the appropriate PWM duty cycle values.
Suggestions for further development
The example program is a basic introduction to the MIAC capabilities. The program can be modified or expanded to include some of these suggested features:
Light sequencing can be controlled by audio signals (amplified microphone, audio equipment, etc.) applied to the input terminals.
By combining this application with the MIAC RC-5 application, lighting levels, colours, and sequences, can be controlled with a domestic, infra-red, remote handset.
Note: Both of these applications use TMR0. Therefore one will need to be modified to work with an alternative timer peripheral.
Automatic brightness adjustment
Channel brightness can be controlled by light sensors (LDRs, Photodiodes, etc.) connected to the input terminals.
A light sensor can be used as a twilight switch, automatically activating the system at dusk. Individual channels, allocated to separate rooms, can then be switched independently under timer control to give the impression that a building is occupied.
Note: The relay outputs would be suitable for this application, and could control several bulbs on each channel.
The CAN bus can be used to connect multiple MIACs in a network, increasing the number of channels and potential combinations.
Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.
2 posts • Page 1 of 1