ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Timer on the microcontroller. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Clocks, timers, relays, load switches The timer in question has two countdown modes for time intervals ranging from 1 to 999 minutes or the same number of seconds. The diagram of the device is shown in the figure. It has a switch SA1, with which you can choose in which units, minutes or seconds the count will be kept, control buttons SB1-SB3, a three-digit LED indicator HG1 (hundreds digit) - HG3 (unit digit). After the timer is powered on, the RC circuit R2C3 generates a pulse that sets the DD1 microcontroller (AT90S2313-10PI) to its initial state. When setting the duration of the generated shutter speed, each press of the SB1 (L) button increases the indicator readings by one. If you keep this button pressed for more than 3 seconds, the value on the indicator will increase by 5 units (minutes or seconds) every second. The SB2 (V) button acts similarly to the SB1 button, but the value on the indicator does not increase, but decreases. Upon reaching the values of 999 or 0, further change in the readings in the corresponding direction is automatically blocked. Selecting the SA1 switch, the time will be counted in minutes or seconds and setting the required exposure time with the SB1 and SB2 buttons, you should press the SB3 (C) button. From this moment, the timer starts - the high level at the PD6 output of the microcontroller is replaced by a low one, voltage is applied to the actuator connected to connector X2, which is signaled by the neon lamp HL1 (with a built-in ballast resistor), and the countdown of the set time begins. The number displayed on the indicator decreases by one every minute or second. The decimal point in the units digit flashes with a period of 1 s. As soon as the indicator reaches zero, the low level at the PD6 output will again become high, which will turn off the actuator. In addition, in the minutes counting mode, at this moment, a pulse sequence with a duration of 4 s will be generated at the PD60 output - an audible signal will sound. The device will then return to its original state. To end the shutter speed ahead of time, press the SB3 button again - the actuator will be turned off. To generate a new shutter speed, you must set its duration again. The actuator control unit is assembled on a solid-state relay U1, the emitting diode of which is connected to the output PD6 of the microcontroller. Thanks to this, the relay circuits connected to the 220 V network are isolated from the rest of the timer circuits. Piezoelectric emitter HA1, which gives a sound signal for the end of exposure, is connected to the output PD4. At the outputs of port B, the DD1 microcontroller generates signals that come through the current-limiting resistors R4-R11 to the cathodes of the elements of the LED indicators HG1-HG3, and the signals used to determine the state of the buttons SB1-SB3. The second pins of all buttons are connected together and connected to the PD3 input of the microcontroller. Diodes VD1-VD3 prevent short circuits between the lines of port B when several buttons are pressed at the same time. Transistors VT1-VT3, controlled by signals from the PDO-PD2 outputs, alternately connect the common anodes of the HG1-HG3 indicators to the power source, which is required for organizing dynamic indication. The clock frequency of the microcontroller DD1 is set by a quartz resonator ZQ1 equal to 10 MHz. The program loaded into the timer microcontroller, the source code of which is available in the appendix to the article, consists of three main parts: the initialization module (INIT label), the main infinite loop (SE1 label) and the T/C1 timer interrupt handler (TIM0 label). It starts its work by initializing registers, counters, stack, T/C1 timer, watchdog timer, I/O ports. Upon completion of the initialization, the number 001 is displayed on the indicator, all decimal points are off, the PD6 output is set to a high level, so the circuit of the actuator is open. The countdown has been stopped. The task of forming accurate time intervals with a duration of 1 s is solved using interrupts from the timer T / C1, requests for which follow every 3,9 ms (1/256 s). They are counted by a counter in register r25. Using the counter organized in the register r21, an interval of 1 minute is formed. In the process of processing interrupts, the bit displayed on the indicator is also changed and the binary value of the digit output in this bit is converted into a "seven-segment" code. In addition, the state of the buttons is polled, control signals are generated for the optoelectronic relay and the audible signaling device. In the data memory of the microcontroller from address $060 to $062, a buffer is organized that stores the value of the time interval remaining until the end of the exposure. It is from it that the interrupt handler takes the numbers for dynamic output to the indicator. When you press the SB1 button, the value stored in the buffer is increased by one. At the same time, the seconds counter in register r1 is started. If the button is held down for more than 3 seconds, the value in the buffer starts to increase by one five times every second. The count of the time interval during which this increase occurs is organized in the rg register. After releasing the SB1 button, the counters in the registers r1 and rO are reset to zero. The processing of pressing the SB2 button, which reduces the number in the buffer, is organized in a completely similar way. The time counters for this button are in the registers r2 and rXNUMX. In the process of counting the specified shutter speed, the number in the buffer is decremented (decreased by one) every minute or second, depending on the position of the SA1 switch. Please note that if you move it to another position before the end of the specified delay, the decrementing period will change accordingly. Register r22 stores a binary code with a unit in the bit corresponding to the currently enabled bit of the indicator. During initialization, 00000001 is written to it (the HG3 indicator is on), and the starting address of the buffer ($060) is written to the Y register. Each time the interrupt routine is called, the contents of register r22 are shifted one bit to the left, and register Y is incremented. It is clear that as soon as the unit in the r22 register is shifted to the third digit (all indicators are passed), the r22 and Y registers should be reloaded, restoring their original values. At the time of polling the state of the buttons SB1-SB3, all indicators turn off, and a "running zero" code is generated at the outputs PB0-РВ2 of the microcontroller. Having detected a low level at the input PD3 and knowing which of the outputs PB0-PB2 is currently low, the interrupt routine decides which button is pressed. The entire program occupies about 670 bytes of microcontroller program memory. The timer is assembled on a breadboard placed in a plastic case, on the front panel of which indicators HG1-HG3, buttons SB1-SB3, switch SA1 and neon lamp HL1 are displayed. The current consumed from a voltage source of 5 V does not exceed 100 mA.
The microcontroller program can be downloaded hence. Author: S. Shishkin, Sarov, Nizhny Novgorod Region; Publication: radioradar.net See other articles Section Clocks, timers, relays, load switches. Read and write useful comments on this article. Latest news of science and technology, new electronics: Machine for thinning flowers in gardens
02.05.2024 Advanced Infrared Microscope
02.05.2024 Air trap for insects
01.05.2024
Other interesting news: ▪ Electric explosion of aluminum foil will effectively bond the metal ▪ Low Dropout Voltage Regulators (0,4V) ▪ Tesla will clatter its hooves ▪ American robot walked 23 km 335 m News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site Home workshop. Article selection ▪ article by Natalie Clifford Barney. Famous aphorisms ▪ article What direction of the mental number line is innate? Detailed answer ▪ article Self-tightening knot with a half bayonet. Tourist tips ▪ article Sound indicator of ultrasound. Encyclopedia of radio electronics and electrical engineering
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |