Using microcomputers for lighting appliance control using a DALI bus

Article concerns the DALI bus theoretical and practical aspects. The DALI bus is a modern technology developed especially for illumination systems control. Authors are outlining communication basic principles related to the physical layer and going up to more complex data transactions among particular devices. The article main topic is aimed at two device models development based on microcontroller and exploiting that technology. The first of those two devices is a DALI slave unit enabling the light source or multi switch with light indication components control via DALI bus. The second device measures the ambient illumination intensity and it also detects errors in the load.


Introduction
The electric illumination is a common furnishing of every habitable building nowadays. Nevertheless, it is necessary to bear in mind that the classic concept of light with corresponding switch has been implemented practically in the same arrangement and design since the end of 19th century when it starts spreading in residential buildings. It is quite a peculiar phenomenon because other electro-technology or informatics based designs have gone through a tremendous development. In spite of that, we can witness a wide range of technologies development aimed at the area of illumination control in course of last two decades.
We are more and more often encountering the notion "smart building" recently. These buildings providing occupiers with optimal indoor environment are economy and energy effective, and the frequently offer a multipurpose use of. All of that is possible due to modern technologies related to informatics, automation and control, not excepting sophisticated illumination ways realisation.
We deal with devices and smart building control algorithms development in our research project. One of many possibilities is the whole smart building parameters to be controlled with a programmable automaton (PLC) [1][2]. Such solution is comprehensive, but it suffers from high costs. Providing we want to control only one segment from the wide range of controllable parameters, we can use a cheaper solution.
This article does not deal with smart building issues as such, but it only strives to describe one alternative related to illumination systems control.

DALI bus
The illumination control design is based on a device incorporating microcontroller and controlled components which mutually communicating via DALI bus.
The DALI bus (Digital Addressable Lighting Interface) corresponding with the international standard IEC 62386 is a digital bus designated for illumination framework control. It is an open protocol system what means that various manufacturers can use it for their products. The DALI bus offers a unified interface for all bus participants. The coordination scheme respects the master slave hierarchy.
The master usually acts as a controlling unit starting communication, and approaching individual slave devices. There must be at least one master unit in any DALI bus system. The slave device is a remote unite acting according to master unit commands. The slave can send data back, but only as a response for preceding inquiry [3][4][5][6].

Physical layer
The DALI bus data and commands transfer runs via two wires, and devices are parallel connected to that two wire link. One link segment can bear up to 64 unit connections in an arbitrary combination of masters and slaves. The communication rate is fixed to 1200 Bd. The DALI protocol has been developed with an idea that the data link is realized with same wires as for 230 VAC power supply distribution in one cable.

Manchester coding
The bus data transfer uses Manchester coding scheme which codes with transitions between levels. The leading edge codes the bit logic symbol 0, and the trailing edge codes the bit logic symbol 1. The signal voltage levels are typically 0-16 Volts [5].

Frames
There are composed frames from individual bits in DALI bus during transfer. The frame can be either the controlling one which serves for the master unit to approach slave devices, or the backward frame for the slave response.
The first bit in every frame is the start bit, and the frame ends with two stop bits. The time slot for one bit is constant what means 833.33 Ps at the data rate of 1200 Bd. The acceptable tolerance of bit duration is +/-10%.

Addresses, groups and commands
Any DALI bus slave device has its own address. If master device sends the control frame containing the particular slave device address in the frame address segment, the corresponding slave device responses. As a general rule, the slave device response procedure includes the frame data segment reading to check for a command to be performed. The frame data segment has 8 bits so that there could be in general one of 256 various commands to be performed [6].
Besides its own address, every device can be assigned to one or more groups. The total group number is 16. In case the master unit sends a frame with group identification code in address segment, the response comes from every member of that particular group. This is how there is possible to approach more than one device with only one inquiry unlike individual approach with corresponding number of message frames.

Topology
The DALI bus topology usually comprises a parallel interconnection of all devices in one network. The term network represents in our case the formation of no more than 64 units, the DALI bus power supply, DALI controller, and at least one device acting as a light source. That controller can be connected to another extensive system via a different bus. Providing we need to control more than 64 devices in our DALI bus, we have to extend it by means of other separate DALI bus interconnected via a gateway, or as the case may be, there can be more DALI bus systems unified using their master units that communicate mutually in another way.

The slave design concept
There is necessary to solve several problems in course of a new device for the DALI bus. Those problems are related both to the physical layer realisation aspect, and to the processing of packets in Manchester encoding.
In view of the fact that all devices are electrically isolated in the DALI bus system, it should be taken into account for circuit design. It is also necessary to ensure that the DALI bus signal conductors are independent on the polarity. The design of that can be inspired by some ready to use solutions. The DALI slave board OM13026 by NXP in Fig. 1can serve as an illustrative example.
The goal within our project was to utilize any DALI Master control unit that was able to communicate with DALI slave devices using standard commands, and that was meeting all above mentioned attributes. The project focus was to bring for being new DALI slave units.

Figure 1. The DALI bus physical layer realization using
OM13026 module circuit diagram [8].
As there is evident in the Fig. 1, the galvanic isolation is realized with optocouplers (OK1 a OK2) where each data transfer direction uses one of them. It is a cheap and efficient solution which enables voltage levels conversion to a required range at the same time like in this case to 0 -3.3 Volts.
For the sake of both master and slave unit realisation is requisite to use one of up-to-date microcontrollers. DALI_RX and DALI_TX signals in Fig. 1 can be connected to such controller. Nevertheless, the Manchester encoding could be a problem for realization because not any microcontroller is able to process it directly. The LPC1343 circuit which OM13026 module incorporates can communicate only in the standard UART mode. That is why there was necessary to employ our own solution. The data transmission with DALI1_TX signal has software solution without any sophisticated hardware peripheral. The data reception DALI1_RX signal is fetched to the LPC1343 timer input set to the periodical level sampling of that signal. The samples are software-evaluated afterwards.
The communication exclusively software solution has advantage for the case that microcontroller does not provide any hardware support for given serial protocol in. It is thus possible to apply that method for every microcontroller with regards to its memory size and to its computing power.
The remarkable disadvantage of such solution is the fact that each bit processing consumes an appreciable part of computing power. The communication protocol supporting software also reduces the memory space what can matter in some applications. Much better solution represents the selection of microcontroller with inbuilt hardware Manchester encoded data processing support.
The microcontroller market offers an acceptable assortment of microcontrollers with Manchester encoded data processing support. The model from AT90PWM family [9] by Atmel [10] can be one of them. That family has been particularly designed for illumination applications, and every member of that family provides the extended function of the UART module for 16/17 bit communication in the DALI bus. Even though it is an 8bit microcontroller which unlike the 32-bit LPC1343 does not provide such a computing power, the hardware level DALI communication handling compensates that disadvantage. The price of AT90PWM family circuits is comparable with LPC13 family members.

The DALI Slave I/O unit concept
The DALI Slave I/O unit has been designed in two variants with the same concept. One of those two variants has to provide the light source control via DALI bus, the other one has to provide the multi switch function with indicating elements. That is a user choice whether he decides to use that module either as a light source or as a multi switch.
The DALI Slave unit physical layer has been adopted from the OM13026 module. The other part of circuitry originates from the reference design by Atmel.
The DALI interface has been realized with regard to galvanic isolation with an optocoupler just as all I/O modules.
The I/O unit block diagram is illustrated in the following Fig. 2.

The DALI Slave sensor unit concept
The sensor unit originates both in hardware and software concept mostly from the I/O unit. However, it has brought the following modifications in comparison to it: • It does not incorporate the user entries (push-buttons). • It has no output galvanic isolation. • There is an output load current measurement resistor added. • There is a voltage divider with photoresistor for ambient illumination intensity measurement added. Besides the ambient illumination intensity measurement and load error detection indicated with load current out of expected value, the third DALI slave unit adding in the system offers one possibility more -the DALI group utilization. In case we decide to operate only two Slave units separately in two different groups, from the practical point of view, there is no difference between the access via a direct address or via the group address.
The sensor unit concept has been generated in a block diagram form similarly to the I/O unit concept one.

The ambient illumination value measurement
The DALI Slave sensor unit is equipped with a voltage divider composed from a photoresistor and a common resistor in series for ambient illumination intensity measurement.
The divider input was connected directly between the microcontroller supply voltage rail and the ground rail.
That arrangement is surely not a best one. However, it serves sufficiently when the simplicity and the only indicative ambient illumination measurement have main priority. The accuracy improvement would require either a voltage reference for voltage divider input or the specialized integrated circuit designed for such purpose with the digital output of measured values.
The VT93N2 photoresistor has been selected. Its nominal dark value is 500 kilo ohms [11].
The divider output voltage is the voltage of the two components in series common node. The output of that voltage divider was directly connected to the microcontroller AD converter input without any supplementary components for voltage level modification. There was necessary to take into account not only the AD input nominal voltage range, but also the working range of ambient illumination values for the second resistor value calculation.

Microcontroller
The DALI Slave units have as a core part ATMega88 (IC5) microcontroller with other components supporting its function. There are decoupling capacitors (C1, C6, C7 a C8) connected to microcontroller supply voltage pins. LED indication diodes (LED1 and LED2) are also directly connected to microcontroller. The 6-pin SPI connector has been added to the circuitry for firmware loading possibility. It provides not only SPI bus communication possibility, but also ensures a special DebugWire serial interface.
The microcontroller individual pin function overview brings the following table (Tab 1).

Final DALI Slave board
The following picture displays the final DALI Slave I/O assembled module after PCB manufacturing and component insertion and soldering.

DALI Slave unit firmware
From the architectural point of view, firmware is divided into three main segments: • Drivers -physical layer signals processing • DALI services -DALI frames processing • DALI application -DALI Slave unit functions realization The basic architecture as it was adopted from the reference design is illustrated in the following picture:

Physical layer signals processing (drivers)
As the employed ATMEGA88 microcontroller is not endowed with any hardware interface for a direct Manchester encoded serial communication processing, it was necessary to ensure it in a purely software way. Microcontroller uses the PCINT hardware peripheral and the timer 0.
PCINT is an interrupt that is activated at any value change on microcontroller input pin. In our case, it is PC2 pin which is DALI_RX signal brought to. That signal is a direct output from the DALI physical layer. The physical layer has been adopted from the OM13026 module.

Frames processing (DALI services)
The DALI frames processing is implemented as a finite state machine which functions realizing states evaluation and the transition between them has to be periodically activated from higher software layers.
The finite state machine for frames processing is in non active state most of time (Idle state) waiting for frame arrival. If a frame comes, it is processed, and the state machine transits in other possible states depending on coming data -reception repeat, answer sending, or back to idle state as the case may be.
IEC62386-100 standard requires the obligatory pause between individual states transition. Our design respects that requirement. Standard also sets down that arriving frame is only valid providing it is obtained two times in course of a 100 milliseconds period. The reason for that is the erroneous data reception exclusion. Provided that condition is fulfilled, the frame related command is executed, and state machine transits in idle state. If there is not possible to receive same frame within 100 milliseconds, the state machine transits in idle state directly.

Application layer (DALI application)
The term "application layer" in our project is to be understood as all what is on the highest level from the software architecture point of view, and what implements the functionality as such. The application layer term in our project is to be understood from the software point of view as a highest level implementing the Slave unit functionality as such from the user position. There has been created several smaller software modules which task is to mediate for application layer the microcontroller hardware components access.
The list of those software modules is as follows: LEDs.c, inputs.c, sensing.c.

Supported DALI commands
Any command captured during arriving DALI frames processing is transferred to the application layer for further processing.
Every command has its value within enumeration type (enum), and its particular implementation is located within a switch block where is to be jumped according to the "enum" value to.
Because of simplicity, there are only a few remarkable commands presented in the following table (Table 2). There were tested all commands individually and communication possibilities by means of this set.