Pentru cazuri cand trebuie sa alimentam un montaj sau un consumator (radio portabil, beculet, etc) de la o sursa de tensiune continua fixa de 12V (chiar si acumulator masina), iar curentul maxim consumat este de 300..500mA (0,3..0,5A) putem realiza rapid un montaj cu integratul specializat LM317T fara radiator sau un mic radiator (daca este nevoie de un curent mai mare 1..1,5A trebuie folosit un radiator mare, eventual unui de racire procesor - cooler). Eu il folosesc frecvent si l-am prezentat in mai multe articole: - LM317 - Stabilizator tensiune cu LM317 - LM317 - crestere lenta a tensiunii de iesire - Sursa de tensiune tripla cu LM317 - Incarcator de acumulatori cu gel Pentru a afla cat mai multe despre acest integrat in capsula de tranzistor de medie putere, va recomand sa studiati fisa de catalog (datasheet). Am ales schema cu protectie cu diode (LM317 are si protectie termica si la supracurent), pe care am redesenat-o repede folosind EAGLE PCB Editor:
si am desenat o varianta de cablaj, respectiv montaj:
Deoarece nu aveam timp ca realizez cablajul prin metodele prezentate in alte articole (desenare cu smoala sau oja sau transfer de tonner) am folosit o bucata de cablaj de test cu gaurele:
am listat pe hartie autoadeziva pozitionarea pieselor:
si am plantat piesele:
Era sa uit... dimensionarea componentelor pentru acest modul de stabilizare am realizat-o conform observatiei din cartea dlui Ciugudean - Stabilizatoare de tensiune cu circuite integrate liniare (dimensionare). Este vorba de alegerea rezistentei R1 la valoarea de 120 ohmi nu de 240 ohmi cum este prezentat in fisele tehnice, deoarece LM317 necesita un curent minim de stabilizare pe zona de 1,25V de 10mA si doar aceasta valoare asgura acest curent (in carte se mentioneaza ca la unele exemplare pot apare cresteri de tensiune cand sursa e in gol si atunci nu ar mai fi stabilizator, nu?!)
Calcularea valorilor se poate face rapid cu un calculator on-line dupa formula Vout = 1,25*(1 + R2/R1):
Am asamblat si testat montajul:
Cu un semireglabil de 1Kohmi am o obtinut o tensiune stabilizata reglabila de la 1,19V pana la 12,25V:
La primele teste nu am obtinut rezultate, in sensul ca becul nu se aprinde, desi LED-ul se aprindea slab. Dupa ce am schimbat optocuplorul de comanda (MOC3040/MOC3041) cu MOC3020 si triacul (BT134/BT136) mi-am dat seama ca am omis un traseu. Dupa corectarea traseului de pe cablaj, am obtinut si rezultatele.
Schema este cea "clasica" cu precizarile ca eu am folosit la detectorul trecerii prin zero un optocuplor 4N35 si 2 rezistente de 91K (se pot folsit si de 100k) iar puntea redresoare am recuperat-o dintr-o sursa de calculator, iar optocuplorul de comanda este MOC3020 MOC3040, dar merge foarte bine si MOC3041 (care are in plus partea de trecere prin zero). Semnalul de trecere prin zero l-am conectat la terminalul digital D2, iar comanda LED-ului si a MOC-ului la terminalul digital D3 de la Arduino.
Am constatat ca dupa finalizarea buclei de numarare catre aprindere la intensitate maxima si trecere la scadere apare un "gol" (se stinge scurt becul), asa ca am mai cautat documentatie is am ajuns la DXARTS - AC DIMMER CIRCUIT unde se foloseste biblioteca TomerOne.h, pe care trebuie descarcata de la http://playground.arduino.cc/Code/Timer1. Sketch-ul adaptat si folosit este:
In articolul de la DXARTS este si o varianta in care controlul intensitatii luminoase se face cu un potentiometru, dar nu am reusit sa-l testez, deoarece am avut probleme cu cablurile. mufele sau chiar cu.. Arduino... se facuse tarziu si nu am avut rabdare sa verific... dar o sa revin cu rezultatele, pana atunci postez schema de conecate necesara si sketch-ul despre care vorbeam:
/*
AC Light Control
Updated by Robert Twomey <rtwomey@u.washington.edu>
Changed zero-crossing detection to look for RISING edge rather than falling. (originally it was only chopping the negative half of the AC wave form).
Also changed the dim_check() to turn on the Triac, leaving it on until the zero_cross_detect() turn's it off.
Ryan McLaughlin <ryanjmclaughlin@gmail.com>
The hardware consists of an Triac to act as an A/C switch and an opto-isolator to give us a zero-crossing reference. The software uses two interrupts to control dimming of the light. The first is a hardware interrupt to detect the zero-cross of the AC sine wave, the second is software based and always running at 1/128 of the AC wave speed. After the zero-cross is detected the function check to make sure the proper dimming level has been reached and the light is turned on mid-wave, only providing partial current and therefore dimming our AC load.
Thanks to http://www.andrewkilpatrick.org/blog/?page_id=445 and http://www.hoelscher-hi.de/hendrik/english/dimmer.htm
*/ #include <TimerOne.h> // Avaiable from http://www.arduino.cc/playground/Code/Timer1 volatile int i=0; // Variable to use as a counter volatile boolean zero_cross=0; // Boolean to store a "switch" to tell us if we have crossed zero int AC_pin = 3; // Output to Opto Triac int POT_pin = A3; // Pot for testing the dimming int LED = 11; // LED for testing int dim = 0; // Dimming level (0-128) 0 = on, 128 = 0ff int freqStep = 75; // This is the delay-per-brightness step in microseconds. // It is calculated based on the frequency of your voltage supply (50Hz or 60Hz) // and the number of brightness steps you want. // // The only tricky part is that the chopper circuit chops the AC wave twice per // cycle, once on the positive half and once at the negative half. This meeans // the chopping happens at 120Hz for a 60Hz supply or 100Hz for a 50Hz supply. // To calculate freqStep you divide the length of one full half-wave of the power // cycle (in microseconds) by the number of brightness steps. // // (1000000 uS / 120 Hz) / 128 brightness steps = 65 uS / brightness step // // 1000000 us / 120 Hz = 8333 uS, length of one half-wave. void setup() { // Begin setup pinMode(AC_pin, OUTPUT); // Set the Triac pin as output pinMode(LED, OUTPUT); // Set the LED pin as output attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need Timer1.attachInterrupt(dim_check, freqStep); // Use the TimerOne Library to attach an interrupt // to the function we use to check to see if it is // the right time to fire the triac. This function // will now run every freqStep in microseconds. } void zero_cross_detect() { zero_cross = true; // set the boolean to true to tell our dimming function that a zero cross has occured i=0; digitalWrite(AC_pin, LOW); } // Turn on the TRIAC at the appropriate time void dim_check() { if(zero_cross == true) { if(i>=dim) { digitalWrite(AC_pin, HIGH); // turn on light i=0; // reset time step counter zero_cross=false; // reset zero cross detection } else { i++; // increment time step counter } } } void loop() { dim = analogRead(POT_pin) / 8; // read dimmer value from potentiometer analogWrite(LED, dim); // write dimmer value to the LED, for debugging }
25.03.2013 Din testele preliminare, Arduino are defecta partea de intrari analogine, inca nu stiu de ce, dar... am pus un buton pe intrarea digitala 4, cu care voi creste si scadea intensitatea luminoasa, folosindu-ma de sketch-ul cu potentiometru de la DXARTS.
Am adaptat sketch-ul incat sa pot folosi butonasul meu fara retinere sa realizez 8 trepte de regaj (LED-ul rosu se aprinde la intensitate luminoasa invers decat becul):
/* AC Light Control
Updated by Robert Twomey <rtwomey@u.washington.edu>
Changed zero-crossing detection to look for RISING edge rather than falling. (originally it was only chopping the negative half of the AC wave form).
Also changed the dim_check() to turn on the Triac, leaving it on until the zero_cross_detect() turn's it off.
Ryan McLaughlin <ryanjmclaughlin@gmail.com>
The hardware consists of an Triac to act as an A/C switch and an opto-isolator to give us a zero-crossing reference. The software uses two interrupts to control dimming of the light. The first is a hardware interrupt to detect the zero-cross of the AC sine wave, the second is software based and always running at 1/128 of the AC wave speed. After the zero-cross is detected the function check to make sure the proper dimming level has been reached and the light is turned on mid-wave, only providing partial current and therefore dimming our AC load.
adapted skech by niq_ro from http://www.nicuflorica.blogspot.com & http://www.tehnic.go.ro */ #include <TimerOne.h> // Avaiable from http://www.arduino.cc/playground/Code/Timer1 volatile int i=0; // Variable to use as a counter volatile boolean zero_cross=0; // Boolean to store a "switch" to tell us if we have crossed zero int AC_pin = 3; // Output to Opto Triac int buton1 = 4; // first button at pin 4 int LED = 11; // LED for testing int dim = 128; // Dimming level (0-128) 0 = on, 128 = 0ff int pas = 16; // step for count; int freqStep = 75; // This is the delay-per-brightness step in microseconds. // It is calculated based on the frequency of your voltage supply (50Hz or 60Hz) // and the number of brightness steps you want. // // The only tricky part is that the chopper circuit chops the AC wave twice per // cycle, once on the positive half and once at the negative half. This meeans // the chopping happens at 120Hz for a 60Hz supply or 100Hz for a 50Hz supply. // To calculate freqStep you divide the length of one full half-wave of the power // cycle (in microseconds) by the number of brightness steps. // // (1000000 uS / 120 Hz) / 128 brightness steps = 65 uS / brightness step // // 1000000 us / 120 Hz = 8333 uS, length of one half-wave. void setup() { // Begin setup pinMode(buton1, INPUT); // set buton1 pin as input pinMode(AC_pin, OUTPUT); // Set the Triac pin as output pinMode(LED, OUTPUT); // Set the LED pin as output attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need Timer1.attachInterrupt(dim_check, freqStep); // Use the TimerOne Library to attach an interrupt // to the function we use to check to see if it is // the right time to fire the triac. This function // will now run every freqStep in microseconds. } void zero_cross_detect() { zero_cross = true; // set the boolean to true to tell our dimming function that a zero cross has occured i=0; digitalWrite(AC_pin, LOW); } // Turn on the TRIAC at the appropriate time void dim_check() { if(zero_cross == true) { if(i>=dim) { digitalWrite(AC_pin, HIGH); // turn on light i=0; // reset time step counter zero_cross=false; // reset zero cross detection } else { i++; // increment time step counter } } } void loop() { if (digitalRead(buton1) == LOW) { if (dim>125 || dim<15) { pas = - pas; } dim = dim + pas; while (digitalRead(buton1) == LOW) { } delay(10); // waiting little bit... } analogWrite(LED, dim); // write dimmer value to the LED, for debugging delay (100); }
Daca se doresc mai putine trepte de variatie, de la 8 se pot reduce la 4 (0-25%-50%-75%-100%-75%-50%-25%-0-25%...), modificarea consta in valoarea variabilei "pas":
Pentru 3 trepte de iluminare (0-33%-67%-100%-67%-33%-0-33%...), se modifica putin sketch-ul modificand linia: int pas = 42; // step for count; iar pentru 2 trepte de iluminare (0-50%-100%-50%-0-...) int pas = 64; // step for count; Pentru varianta cu 3 trepte de reglaj al intensitatii becului, an facut poze cu cele 4 stari: - bec stins: