![]() ![]() Low Cost and Accurate Incubator for DIY Biology: 8 Steps. In the next step we discuss how to control this circuit with the Arduino code. You can simply download and run our code. The rest of this step goes into the gory details of how the code works. Please note that some parts of our code are based on Arduino’s AC phase controlling tutorial and we re- used some part of that code as it is. The Arduino UNO board contains a ATmega. P 1. 6MHz microprocessor. DIYbio, (Do It Yourself) biology is a growing movement that aims to make biology accessible outside of professional contexts. Over the past few years, platforms such. Electronic Circuit Schematics. Note that all these links are external and we cannot provide support on the circuits or offer any guarantees to their accuracy. ![]() Searching for an electronic component? Simultaneously query distributors, and returns the responses in real time. To trigger the AC phase control circuit at precisely timed intervals we utilized the hardware timer interrupt functions of ATmega. So, if you are not familiar with concepts like timers, registry overflows and prescaling, this article explains them better. Before we go into coding we have to do some basic calculations. The AC signal is 6. Hz. (Don’t worry if you have 5. Hz in your country, you can re- calculate it easily) This means, the AC signal crosses zero, reaches peak positive voltage, crosses zero again, reaches peak negative voltage and returns to zero 6. The period (length of time this takes) is 1/6. Thus, a half cycle or the time between two zero- crossing pulses occurs in 8. From here onwards, we will determine time intervals in the code from clock counts, not by seconds. The Arduino clock runs at 1. MHz, which is 1. 6,0. A single half cycle of the 6. Hz AC signal contains 1. The 1. 6- bit timer (timer. Arduino Uno can only count to 6. So we need to configure that with a prescaler. In this code we used a 2. With the 2. 56 prescaler, half a cycle means about 5. For practical reasons (slight changes in supply frequency and triac operational delays) we considered it as 4. This assures that the triac driver has time to switch off before the next half cycle. So we controlled the waiting time before switching ON the triac within the range 1- 4. We used comparator match interrupts for this. We used timer overflow interrupts to control the signal to triac gate and set the pulse width to 4 timer counts. Here, when the pulse is sent to the GATE of the triac, it will turn the AC supply ON and will remain ON even after the pulse is removed until the next time the AC wave reaches zero. If you are not familiar with Triac’s operation this is a good article.) Because of this we don’t need to worry about switching OFF the triac. Following code snippet shows the AC phase controlling logic.#define DETECT 2 //zero cross detect #define GATE 9 //triac gate #define PULSE 4 //trigger pulse width (counts)// set up Timer. OCR1. A = 1. 00; //initialize the comparator TIMSK1 = 0x. A and overflow interrupts TCCR1. A = 0x. 00; //timer control registers set for TCCR1. B = 0x. 00; //normal operation, timer disabled// set up zero crossing interrupt attach. Interrupt(0,zero. Crossing. Interrupt, RISING); //zero cross detectedvoid zero. Crossing. Interrupt(){ TCCR1. B=0x. 04; //start timer with divide by 2. TCNT1 = 0; //reset timer - count from zero - counts until it matches the comparator value }//comparator match - reached the expected delay. ISR(TIMER1_COMPA_vect){ digital. Write(GATE,HIGH); //set triac gate to high - turn ON the supply TCNT1 = 6. PULSE; //trigger pulse width }//timer. ISR(TIMER1_OVF_vect){ digital. Write(GATE,LOW); //turn off triac gate TCCR1. B = 0x. 00; //disable timer to stop unintended triggers}Temperature controlling Now we are done with the trickiest part of our code. Next is to control power (or the delay time) according to the current temperature value and the desired target temperature. To read the temperature value we used the Adafruit_MAX3. To implement the control mechanism we used PID control logic. Don’t worry if it sounds a bit complex. Luckily we have an Arduino library for that. The following snippet shows the code for that.#define DO 3 #define CS 4 #define CLK 5 Adafruit_MAX3. CLK, CS, DO); double set. Point, Input, Output; //Define Variables we'll be connecting todouble Kp=2, Ki=6, Kd=1; //Specify the links and initial tuning parameters. PID my. PID(& Input, & Output, & set. Point, Kp, Ki, Kd, DIRECT); my. PID. Set. Mode(AUTOMATIC); my. PID. Set. Output. Limits(0, 4. 49); // set the range// inside the loop method double c = thermocouple. Celsius(); if (isnan(c)) { i=4. Go to minimum power if something went wrong } else { Input = c; my. PID. Compute(); i = 4. Output; // lower the delay, higher the power } OCR1. A = i; //set comparator value to i delay(4. User interface To programme the user interface we used olimex lcd shield library together with Arduino wire library. You can download the olimex library from Olimex website.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2017
Categories |