Return to index
Warning!
Rebuilding this project might cause LIFE THREATHENING situations! Do not rebuild if you do not have the appropriate education in electronics and electrical enginering! Never leave this device unatended and use proper fireproofed and insulated housing! Rebuilding is completely at your own risk!
I have been building a few different versions of the dimmer switch so far, choose the version you want to have a look at
Although version 1 works flawlessly, there is still a lot of room for improvements. Instead of using an AT89S2051 microcontroller we can also use a RISC (reduced instruction set) controller called ATtiny2313 which is made by the same company. The ATtiny2313 uses the AVR instruction set and is very powerful. The processor is pin compatible and has lots of advantages over the 80x31 based processor. Here are most of them:
And of course with so many advantages there must be certainly also be disadvantages, yes but only one.
The other improvement that can be done is using a transformerless design. That gets rids of the bulky transformer but also creates a few new problems.
The triac TIC206D (BT136-600D) needs only a small current flowing through the gate to start conducting and turn a light on. This is the reason why they can be directly connected to the microprocessor, which can sink at least 10mA. Most digital circuits can sink much more current then they can source, that is why the whole dimmer works with -5 Volts. The resistors R1 to R8, limits the current to -5 mA. That it enough to get the triacs conducting in 3 out of the 4 quadrants. In the 4th quadrant the triacs need 10 mA to start conducting, but that is when the gate current is positive. That is another reason why we are using a negative voltage.
R9 in combination with C1, function as a low pass filter. They remove high frequencies caused by the fase cutting of the triacs. L1 prevents them from going back into the power grid where they spoil your radio reception.
Version 1 used a transformer to generate the -5Volt for the electronics circuitry. Although this is the standard way of making a certain voltage, it is not really necessary. We can use a capacitor too, which is 100 times smaller then a transformer. This has of course a few drawbacks too. First the voltage generated is not galvanically isolated from the power grid, so it is dangerous to touch bare wires. The capacitor is the opposite of a transformer, instead of supplying a fixed voltage, the capacitor supplies a fixed current. Also, the capacitor can only supply small currents, which are in the order of milli Amps. The capacitor works most efficiently if the current supplied is also used. The current needs to be discharged if the circuitry doesn't use it, else the voltage will go up and distroy other parts of the circuitry.
I don't want to make a real long story with lots of calculations, but the dimmer needs less than 20mA to function. C2 is calculated with the formula Xc=U/I=230V/0.02mA= 1/(2πfC). f is the net frequency and is in Europe 50 Hz. Fill in the values and you find C to be 276nF. To be sure that we get at least 20mA we use 330nF for C2. For the Americas C2 needs to be C=0.02/(2*3.14*60Hz*120V)=440nF. So use E12 value 560nF. R11 limits the maximum current though C2. Imagine you plug in just when the power is at it's highest voltage, namely 230V~*√2 = 325V top. Using Ohm's law R11 limits the current to 325V/100Ω=3,25 Amps, whichs is still high but should not destroy the capacitor and the diodes. During the negative cycle, D2 lets the charge in C2 pass and stores it into capacitor C3. This is a small buffer that temperarily stores the charge if more power is needed then is available. At the positive cycle, D1 is needed to charge the capacitor again with a negative charge (confused lol?). D3 is a zener diode that breacks down when the tension reaches 18 Volts. This is to protects IC1 which does not like any tensions over 20 Volts. From the input voltage (which is somewhere between -7 and -18 Volts depending on the total current used) IC1 stabilises the output voltage to -5 Volts. C4 prevents oscillations and is placed close to the microprocessor.
The purpose of the zero voltage detector (sometimes named the zero crossing detector) is to signal to the microcontroller that the triacs need to be fired up again. Depending on the required intensity of the lights, this will happen immediately, or when the lowest intensity is wanted, never. The zero crossing detection circuit is build around R11, R12, D4 and D5 . R11 is choosen so high because P=U2/R=2302/1MΩ=53mW. Any lower value would increase the power wasted. We can use such a high value because the ATtiny2313 datasheet tells us that the maximum leak current Iih is 1µAmps at 5 Volts. We can now calculate the worst Ri resistance. Ri=U/I=5 Volts/1 µAmps= 5 MΩ. The ATtiny generates an interrupt when the voltage rises above 0.6Vcc and when it drops below 0.3Vcc. Knowing that we can calculate R12. 30% of 5Volt is 1.5Volt. 60% of 5Volt=3Volt. At 1.5V and R12 is 820k I=1.5/820k=1.8µA. U=1.8µA*(1MΩ+820kΩ)=3.3V. Compared to the NULL voltage that is -5-3.3=-1.7 Volts. Another interrupt is generated at 3V/820kΩ=3,6µA =3.6*1.820MΩ=6.65Volts=+1.65 Volt compared to the NULL voltage. So with these values Ugrid will cause an interrupt at roughly +1.65Volts and -1.7Volts, this is close enough for our purpose.
The infrared receiver is build around standard highly integrated components. TSOP1736 is a receiver that responds best to signals transmitted on a carrier frequency of 36 kHZ like RC5 etc. Some other remote controls use different carrier frequencies, in that case use the appropiate ir receiver module.
The last part of the dimmer is the circuit around OK1 and OK2. These make sure that the serial interface is galvanically isolated from the power grid so that you can savely hook up your dimmer to your computer as long as it has a serial port. Through the serial port we can send or receive commands to or from the dimmer. Don't expect speeds to be much higher then 9600 baud, but this is more then sufficient.
The microcontroller used in this dimmer is very powerful and is easily adapted to decode both DMX and X10 signals. The software for decoding the DMX512 signal is ready, but you must design your own hardware. For the X10 interface I still need to design some hardware and software. Getting the dimmer ready for decoding X10 signals will still take some time. Not that the software is the problem but the hardware is.
The two fuses used in the dimmer provide some safety against short circuits and malfunction of the dimmer. Although malfunction of one of the triacs could blow up the microcontroller. There are a few reasons I choose this configuration instead of using opto-diacs. The reasons are size, price and reliability. Nowadays electronics are hardly repeared anymore, but are instead just thrown away and more parts just means lower MTTF (Mean Time To Failure).
The software for the dimmer is written in C and partly in assembler because of critical timing. To edit and recompile the firmware download both the integrated development environment (IDE) AVR Studio 4 and the GCC compiler and C-library WinAVR. First install WinAVR and then AVR Studio 4. Double click the Avrdimmer.aps file to open the project in AVR studio 4.
Some of the software features I will explain here.
The triacs are controlled by phase cutting. The software detects the null (zero) voltage and then starts to count from 0 to 255 (next zero voltage). When the counter reaches a certain (set) value the triacs are triggered by pulling the output pins low for 1/(256*2*grid_frequency)=about 40 µS. The shape of the mains voltage (sinus) is not a very linear way of controlling the average voltage. With some mathematics we can create a table that can correct this nonlinearity. We can make a table for the average power or for the average voltage depending on what we want to control.
The mains voltage can be described with the formula u(t)=utop·sin(π·t/T)| T ∫ ts |
u(t) dt = [-Tûcos(π·t/T)/π]tsT= -Tûcos(π·T/T)/π - -Tûcos(π·ts/T)/π = Tû(1+cos(π·ts/T))/π |
We can create a table with this formula, but have to keep in mind that very low and high values shouldn't be used. This will give problems with inductive loads (current will not be low enough to shut down the triac) and with small loads (when U is low, so is I and the Ihold of the triac is 10mA) this will cause flickering of the light. In the Avrdimmer 0% is used just to turn all power off and then jumps to a higher value.
When the dimmer gets booted it reads the 8 presets values from the EEPROM. The 0 button on the remote control turns all lights off. 9 reads the preset values from the EEPROM. Mute programmes the current values into the EEPROM. With buttons 1 to 8 individual light can be selected and be switched between off and preset value. Volume + and - can be used to change the intensitie of a single light or after 0 or 9 is pressed all lights.
The latest software supports control over the serial port. Connect the dimmer to a serial port with a cable that is 1 on 1. So pin 1 on the female connector is connected to pin 1 on the male connector. Download the SampleDosBatchFile for testing the functions that the dimmer supports.
The information send to the dimmer is build out of a "command"+"dimmer number"+"channel number"+"value of channel". For instance "DIM 000150" means dimmer 00, channel 01, value 50. If the dimmer does not understand the command it will give an "Err" message. The decoder is fault tolerant, so a command like "dIm00015fblabla" will also work, it will set channel 1 to value 0x5F. Check out the SampleDosBatchFile. Standard it will use com2 at 9600 baud.
The last way to control the dimmer is the PC_Dimmer program. This software runs on a Windows 98/se/XP compatible platform and is very versatile. It can be used to create light effects, run synchronous with music and lots more. Download the plugin and copy it to plugin directory of the program.
Software last updated July 21, 2007 (compiled version upon request)
Log fileAll the settings for the dimmer can be found in Avrdimmer.h. This include file for the C compiler contains information about the CPU clock, grid frequency and which interface to use. Edit these settings before you compile the program.
Prototype of the dimmer, without the serial interface
To program the microcontroller we need to build a little programmer that hooks up to the parallel (printer) port and download the Ponyprog software. With the version I build I can program both the AT89S8252 and the ATtiny2313. Do not program the ATtiny2313 fuses with the PonyProg (I ended up with 3 unresponsive microcontrollers, which I got back working again with a Linux program UISP and an AT90S2313 on top of the ATtiny2313) . The default fuse settings are sufficient for the project.
The layout is made with the same program as the diagram. For this I am using the free version of Eagle.
Layout with components.
At first I was thinking of making a 4 port version of the dimmer with a smaller ATtiny. But this idea might not work because the smaller ATtiny has only 1kb of flash memory. The other thing I wanted to do is to use a Zigbee (Xbee) module to make the dimmers communicate with each other. One problem with this module is that it is not possible to change the way the Xbee module is working because the software in the Xbee module is not open source. So I decided that I would try an iDwaRF-168 which is a WirelessUSB module that will funtion in a network enviroment. More will follow soon.
Return to index
| |||||
| |||||