mikroElektronika
what is new on site
novi broj
old issues
advertizing
download
club mikroElektronika
flash news - MIP
development tools
moduls from magazine
links
about us
services
contact



Light Dimming Regulation

Prepared by:
Nikola Toncev, B.Sc.EE


Purpose

This device regulates the light dimming. It regulates the light intensity of standard bulbs. This is an illustration how we can use microcontrollers in applications such as controlling the intensity of light dimming. In this article, you also can find out how to connect a microcontroller to an AC power line, and to a triac. We can design the same function in a simpler way though, using (triac, diac, couple of resistors and capacitors). There are numbers of electrical schematics available on the net, describing how to do this. My unit is powered directly from an AC line. Powering from AC line enables the microcontroller to directly trigger a triac (for example - triggering without optotriac and similar things, which usually characterize microcontroller and triac connection.)

Why to use a microcontroller?

 This unit tracks for zerocrossing moment of AC line. Using this information, we avoid error triggering at point of maximum voltage AC (while the bulb fiber still being cold). This is very important! Cold bulb fiber has a couple of times less resistance than the hot one. Turning on the cold bulb at maximum voltage AC (220/sqr(2) ) high current will flow and the possibility of damaging the fiber is high. Regulation with microcontroller gives us dimmed light without flickering. Regulation from full dimming (no triggering at all) to minimal dimming (triggering at start of AC period).
At this point, I would like to indicate the use of this device in applications such as: heaters, with minor modifications of course. Adding temperature sensors, gives regulated heating power. More other applications can be obtained performing time delay, internal logic and others.

How does the device work?

Let's get back to our example. I designed it based on existing sensor regulators. The turning on and off is produced with short touch of sensor. Touching the sensor a bit longer, makes the light power change continually.
I used PIC 16F84-4MHz for this application. You can also use other PIC controllers. Probably, the best and cheapest solutions are some of those PICs in 8 pin DIP.
In Yugoslavia, the AC line is 220V 50Hz. If this is not always the case, the light regulator will still be working properly. In case of 60Hz AC line, you should make some corrections. Frequency of 50Hz makes the amplitude of AC line to have zero value hundred times per second. Thus, zero crossing comes every 10ms.
To control the power of lighting I decided to control the phase shift. Triac should be triggered after phase shift (time after zero crossing). If we turn on the triac just after zero crossing time, the light will be maximally strong. In addition, effective voltage on light bulb will be 220V. In that case, current will flow for half-period almost completely. On the other hand, if we turn the triac on later, for example at the end of half-period, the current will flow only for a little bit of period. The result is dimmed light. This practically means that delay regulation of triggering regulates light dimming.

Calculation

Comfortable programming supposes we use 1 byte for delay. In best case, 256 different dimming levels will be available. Processor's clock is 4MHz. It is internally divided by 4. What is the value of prescalling coefficient? 64. If we adopt 64 we can get maximal dimming for nmax=(10ms/64ms)@157 (157 different dimming levels). In case of prescalling with 32, we get nmax@312, (we need two bytes for representing 312 different values of dimming). Finally, it remains the case of prescalling with 128 nmax@79. The best resolution we can get with one byte is 157 and prescalling coefficient is 64.
For estimated value of prescalling coefficient, we must find the time minimum of triggering time delay. Triggering the triac when amplitude of AC voltage is too low, makes triggering insecure. Value for secure nmin=(1/(2pi*50))*(arcsin(20/311V))/(64us) ~ 4
triggering is taken as 20V.
Dimming is minimal for 4*64ms delay time and dimming is maximal for 157*64ms.

Software & hardware

The program consists of 4 parts.
1. Initialization
2. The main part tracks the amplitude of AC line. In this part, we measure the time after last zero-crossing. After certain time needed for dimming, program turns the triac on.
3. Turning the triac on
4. Switching control. This part includes switch debouncing. All changes such as turning on/off the light, changing the size of dimming are evaluated in this part of program.
Initialization (1) consists of setting the initial prescalling factor (64), setting initial values of variables, and defining input/output ports. We need to turn off manually the WDT while programming, turn on XT oscillator and turn on Power up timer (PWRT)
Turning the triac on (2) has to be done in sub program Ukljuci. Pin RB0 has to be initialized as input pin. In data latch of that pin sub-program puts 1. This value will not be at the pin lead because this pin is defined as input pin. At the time of turning on, this part of program sets the pin RB0 as output pin for 8ms. After that RB0 is defined again as input pin. 8ms is enough for secure triggering the triac. If we want that kind of triggering in both half-periods, it is necessary for triac to be able to work in 4 quadrants, for example (TIC206 Texas Instruments, Motorola's MAC15A,...). If we try to put the triac that can not work in 4 quadrants, it will be turned on just in one half-period. The main trick in whole project is this triggering.
Main program (2) tracks zero-crossing and consists of two parts. One part tracks the positive half-period of AC line, and the other tracks the negative half-period. One pin is enough for this function realisation. Pins of port A have built in protection diodes. The purpose of these diodes is to protect the chip from extreme input voltage. The AC line and port A pin are connected with high resistance. If the input voltage is higher or lower than nominal input range, this will turn one of protection diodes on. While one half-period is one, a capacity of PN connection will charge. That capacity will be discharged slowly with the start of alternative half-period when the AC voltage is still low. In this case at the end of the positive half-period: the controller will get the information that positive half-period is still going, but the negative half-period has already started. In addition, in reality instead of maximal dim we get minimal dim. There is an another problem. Input pin senses everything below +2,5V as logic zeroes. However, 2,0V is still in a positive half-period. Additional compensatory resistors connected to the ground and VCC can solve the problem. Naturally, software also can give us a solution. The software solution is given in 4 lines in listing and can be deleted when using a compensatory resistor (these four lines are noted in listing). The software solution gives better results when using a quartz oscillator. In this example, this is a better solution. In case of using smaller controller with RC oscillator makes the software solution a little bit more complicated. The values of additional compensatory resistors are estimated experimentally. There is another diode (LED diode) connected to port B (pin RB1). On this diode, we get the PWM signal from this pin. In contrast to triggering triac that lasts only 8ms, PWM signal turns on the diode and lasts through the rest of the half-period. This LED diode is for testing only.
The most complicated part of the program is sub-program for taster switch control (3). Used variables are:
Smer=1 (light dimming or turning on)
Smer=0 (light up or turning off)
Vrednost is a variable. It shows a value of dimming. Minimal dim is set up as 4 and a maximal is set as 200 (not 157 but 200 to be sure the triac will not turn on accidentally.
Stisak measures the time to pass keeping taster switch pressed. If there is enough time passed, the power of lighting will change gradually. Short time pressing changes minimal and maximal lighting (turning on/off).
Speedcontrol is slow down speed of dimming/lighting.
The rest of variables track the previous states of taster switch between two subprogram calls (every 10ms). In addition, debounce taster switch.

Possible future improvements

- software solution in case of RC oscillator
- triggering the triac which can not work in 4 quadrants
- realization with serial connection to bulb
- adding varistor
- adding filter
- current measuring and overload protection
- better reset circuit

Something for the end

I wish to warn those who may try to assamble this device. The whole circuit is under HIGH VOLTAGE and you must be very careful when working. The safety measures must be taken as well as keeping the whole device in a grounded box. I suggest to test the whole thing with small alternative voltage (about 25V, resistors R7, R8 =100K in this case). You can also power the microcontroller with battery or increase capacity of C1. First, check if there are 5V for controller supply, and see if lighting of diode can be changed. If all this is O.K. then try with an AC line (220V).

This article is published by mikroElektronika. 
Reprinting is granted as long as the entire document package stays unchanged. (view Readme.txt) The author and mikroElektronika assume no responsibility for the use of this application.

Literature

1. Microchip, PIC 16F8X data sheet, 1996
2. Microchip, AN521 - "Interfacing to AC Power Lines"
3. Motorola, Motorola thyristor device data - MAC15A series, rev 1
For all information, suggestion and help you can email or call:
(mailto:ntoncev@hemo.net)
Tel: ++381 13 812 932, ++381 63 790 556

Electrical schematics


The entire project is available in one ZIP file (size 49KB )
 (including DOC, .SCH,.ASM, HEX,  TXT)

Download ZIP file: Light Dimming Regulation


Articles of interest:

Internet links:

 

 

www.microchip.com


©


| Index | What's new | New issue | Old issues | Advertising  | Download | Club mikroElektronika | News | Development tools | Modules | Link page | About us | Newsletter | Contact
 mikroElektronika  -  For any comments contact webmaster.

 

1