Do-it-yourself construction and repairs

Circuit diagram of an electronic clock on pic16f628a - devices based on MK - radio-bes - electronics for the home. Clock on PIC16F84A Simple peak clock

I offer two very simple circuits for self-assembly, namely a clock on a PIC and AVR microcontroller. The basis of one circuit is the AVR Attiny2313 microcontroller, and the other is PIC16F628A

These clock circuits on a microcontroller will greatly help novice radio amateurs understand the issues of operation and programming of microcontrollers.

Let's take a closer look at this simple circuit: Power can be supplied either from three AA batteries or from


The Attiny2313 microcontroller is clocked by 16 MHz quartz. As a time counter, the internal circuit of the microcontroller uses a 16-bit timer with a divider by 256. As soon as the internal counter counts to 625, an interrupt occurs. Therefore, we will have interruptions 100 times per second.

The time interval is taken into account in global variables, and each interrupt requires the millisecond value to be increased by one. As soon as the number of milliseconds reaches 100, you need to increase the value of seconds by one and reset the milliseconds to zero. And so on in accordance with the same algorithm up to tens of hours, which are reset only when the value reaches 24 and without increasing the next digit.

In accordance with this principle, we create the current time value recorded in global variables. Now we need to visually display this data. Since the microcontroller has a limited number of ports, we will use such a feature as the inertia of the sa15-11gwa digital segment indicator. The cathodes of its indicators are connected in parallel, and the anodes have separate control, which allows you to display a number on any of the four indicators at any time.

By quickly switching the microcontroller port to which all the cathodes are connected and quickly switching the anodes, it creates the illusion that all four digits are displayed in the segment indicator, although in fact only one of the segments is working. If the current time is 11:57, then first we display number one on the first clock indicator, after 1 ms we display number 1 on the second indicator, after another 1 ms we display 5 on the 3rd indicator, after 1 ms we display 7 on the 4th indicator and so on cyclically, updating each indicator after 1 ms.

The state of the clock control buttons is polled at the end of each display cycle about 40 times per second.

Download the PCB drawing made in the program and the firmware for the microcontroller from the link above. and directly about the intricacies of the firmware, read here.

This design, although based on a different type of microcontroller, is no less complex than the previous circuit.


The operating algorithm of the firmware is also simple; the archive contains very detailed comments on the program code. Two toggle switches kn1 and kn2 are designed to correct the time - hours and minutes. The accuracy of the watch depends on the frequency of the quartz used.

Structurally, the clock is made on two printed circuit boards located side by side at an angle of 90 degrees. The indicator is located on the first board, and all the other electronics are on the second. Backup power is provided by three batteries placed in a holder made from an old Chinese lighter with an LED. For power supply from an AC mains, any 5V and 150mA current is suitable.


The archive, which you can download from the green link, contains the layout of both printed circuit boards in the Sprint Layout program and the firmware for the PIC microcontroller with the source code of the program for MP_LAB IDE, with detailed comments.

And the program itself can also be found here

This design has digital correction of the accuracy of the stroke, as well as a built-in thermometer, which alternately displays temperature readings on the LED display with the exact time. The clock design uses a non-volatile microcontroller memory that saves settings and settings even when the external power is lost.


To control the anodes of LED indicators, transistor switches are used according to a standard switching circuit.

When you turn it on for the first time, an advertising screen appears on the display for one second. Then the time is displayed. Pressing the SET_TIME button switches the indicator in a circle from the main clock mode:

Absolutely, in all cells, holding down the PLUS/MINUS buttons performs accelerated installation. If the settings were changed by the user, then after 10 seconds the new values ​​will be stored in the non-volatile memory of the microcontroller and will be read. When flashing the MK firmware, set it as follows:


You can evaluate the external design of the device from the photographs below; the stitching and additional files for the design can be downloaded from the link just above.


Shift schedules are implemented in the alarm clock firmware: 4/5 (four on the fifth) – 4 days in 1 shift, 1 day off, 4 days in 2 shifts, 1 day off, 4 days at night, 1 day off; – day, night, 2 days off; On weekdays – Mon-Fri - working days, Sat-Sun - Closed; (Holidays are not taken into account); Daily.

The user himself selects the type of alarm schedule and sets any alarm time. In the 4/5 and day, night, 2 weekend options, you must additionally select the current shift.

In addition, the following functions are implemented in the MK firmware: Transition to the summer-winter period; Time adjustment; Accelerating alarm signal; Displaying zero in the hour and date digits

The clock circuit is based on the DS1307 clock chip and the MEGA8 microcontroller. The circuit (placed in the archive with MK firmware and printed circuit board drawings) is designed for the use of seven-segment digital indicators with a common anode for a voltage of 5V. (ATTENTION! For simplicity, ballast resistors are not shown in the diagram. They need to be installed on each segment of indicators. There are 112 pieces in total. The nominal value is calculated according to the documentation. I used segment indicators like fys15011 and fyd-5622. If you use more powerful ones, then most likely without Additional transistor switches are not needed.

The printed circuit board drawing was developed for an existing box from an old broken watch. You can connect a low-power load to the Alarm connector, say a musical card, and use jumper JP1 to disconnect the internal beepper. The microcontroller can be flashed directly on the board, which greatly facilitates setup in case of modification of the design.

Setting the clock
To do this, you need to enter the parameter setting mode:
Parameter-Value-Save in memory
P.01 - CLOCK [-]
P.02 - MINUTES [-]
P.03 - DAY [-]
P.04 - MONTH [-]
P.05 - YEAR [-]
R.06 - Alarm type [+] (1-4/5; 2-5/8; 3-railway schedule; 4-daily)
P.07 - CHANGE [+]
P.08 - Bud.1.HH [+]
P.09 - Bud.1.MM [+]
P.10 - Bud.2.CHH [+]
P.11 - Bud.2.MM [+]
P.12 - Bud.3.CHH [+]
P.13 - Bud.3.MM [+]
P.14 - Adjustment (D.H) [+]
P.15 - Summer/winter period [+]
P.16 - Accelerating beeper [+]
P.17 - Display leading zero in hour digit [+]
P.18 - Display leading zero in date digit [+]

Alarm Setting: Button On/On Alarm. - On/On is carried out, in this case: With alarm type 1: Alarm 1 - 1st shift; Bud.2 - shift; Bud.3 - 3rd shift;
Shift schedule: 1,2,3,4 - first shift; 5 - day off; 6,7,8,9 - second shift; 10 - day off; 11,12,13,14 - 3rd shift; 15.16 - day off; Then the days repeat.
With the first type of alarm 2: Alarm 1 - sets the alarm time; Bud.2, Bud.3 - does not work; Shift schedule: Weekdays.
With the third type of alarm: Alarm 1 - the time of day is set; Bud.2 - sets the time at night; Bud.3 - does not work;
Shift schedule: – day, night, 2 days off;. When the alarm type is 4 Alarm 1, Alarm 2, Alarm 3, the time is set; If you plan to use only one alarm clock, set the times of three to the same time.
With shift schedule: Daily. If you press the Alarm Off buttons. in parameter setting mode, the settings will be exited without saving.
Adjustment: When making adjustments, the following method is used: +/- Ch.D, where: Ch is the number of seconds adjusted per hour (max 9). D - seconds adjusted per day. ATTENTION! No adjustments are made when the power is turned off. When you turn it on, check that the time is correct.

Table and wall clocks with thermometers are made in cases from analog clocks. The clock and thermometer are manufactured as separate, independent devices.

I won’t describe the thermometer, it is posted on the same website, a thermometer for PIC16F628A and FYD5622FS-11. The circuit, printed circuit board and firmware are there, everything is unchanged.

The temperature sensor DS18B20 of the table clock is located outside the window. Insulated wires 0.35mm, approximately 10 meters long

The clock is assembled on single 7-segment green LED indicators. The size of the numbers is 14x25.4mm - clearly visible from any corner of the room. Please note that the indicator is connected without quenching resistors. This is because each segment consists of two LEDs connected in series and has a nominal voltage of 3.8 volts. With dynamic indication, currents do not exceed permissible values.

The voltage stabilizer is located in the plug adapter. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer LM2575T-5.0 according to a standard circuit. The microcircuit without a heatsink practically does not heat up. Connector for 3.5mm power supply. Quartz 4 MHz.

Any low-power n-p-n transistors. Buttons 6×6 H=14/10mm soldered on the conductor side . The length of the button pusher is selected based on the design requirements. Each time you press the button, a unit is added. When held, the count speeds up to a reasonable speed.

Resistors MLT – 0.25. R3 – R6 1-3 kOhm.

Batteries: 4 pieces of GP-170, or similar. When the mains voltage is turned off, they only supply power to the microcontroller. It is advisable to select diodes with the lowest voltage drop in the forward direction.

The boards are made of one-sided foil fiberglass.

HEX file, diagram, seals in folder No. 1.

Option 2: on one board

This case did not fit two boards: a clock and a thermometer. I didn't want to reduce the size of the clock indicator.

I don’t like displaying time and temperature with one indicator in turn on a table clock.

I had to take another smaller indicator for the thermometer and draw a new printed circuit board. Therefore, the circuit and firmware for the thermometer are different.

HEX file and thermometer diagram in folder No. 2. Printed circuit board in the same place.

The clock diagram without any changes is taken from the first section.

Clock with a small 4-digit indicator. The dot between hours and minutes flashes at a frequency of 0.5 seconds. Can be built into any object: a desk calendar, a radio, a car. Estimated error – 0.00002%. In practice, for six months there was never a need for correction.

Power supply 4.5 - 5 volts, current up to 70mA. The voltage stabilizer is located in the adapter plug. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer according to a standard circuit. For a car, of course, a transformer is not needed. The microcircuit without a heatsink practically does not heat up. Connector for 3.5mm power supply. Quartz 4 MHz. Any low-power n-p-n transistors.

Any buttons . The length of the button pusher is selected based on the design requirements. You can also solder buttons on the conductor side. Each time you press the button, a unit is added. When held, the count speeds up to a reasonable speed.

Resistors MLT – 0.25. R7 – R14 300 – 360 Ohm. R3 – R6 1-3 kOhm.
Batteries: 4 pieces of GP-170, or similar. When the mains voltage is turned off, they only supply power to the microcontroller. They hold up for 8 days exactly, I checked.
Diodes with the lowest voltage drop in the forward direction.

The boards are made of one-sided foil fiberglass.

Before installing the microcontroller into the panel of the manufactured board, turn on the power and measure the voltage on the 14th leg of the socket. It should be 4.5 - 4.8 volts. On the 5th leg 0 volts. If you are not sure about the quality of the manufactured board or the serviceability of the parts, check the device without a microcontroller. This is done very simply:

  • Insert a jumper from the bare wire into the socket, terminals 1 and 14. This means that +4.5 volts from the first leg will open transistor VT 2 through a resistor and the cathode of the clock unit indicator will be connected to zero.
  • Connect any wire with one end to +, and with the other end alternately touch terminals 6,7,8,9,10,11,12,13 of the socket.
  • At the same time, observe the lighting segments and their correspondence to the diagram: + on the 6th leg – segment “g” is lit and so on.
  • Move the jumper to terminals 2 and 14 of the socket. Check all segments of the minutes unit indicator.
  • Jumpers 18 and 14 – tens of hours are checked, 17 and 14 – tens of minutes.

If something doesn't work correctly, fix it. If everything is correct, program the microcontroller and insert it into the socket with the power off.
HEX file is attached.
Turn on the power and get a ready-made watch.

If you buy all the parts, including resistors, then according to my diagram the device will cost about 400 rubles:

  • PIC16F628A – 22.8 UAH
  • LM2575T-5.0 – 10 UAH
  • FYQ 3641AS21 - 9.3 UAH
  • Panel – 3 UAH
  • Quartz – 1.5 UAH

Literature:

  • Pic microcontrollers. Everything you need to know. Sid Katzen.2008
  • PIC microcontrollers. Architecture and programming. Michael Predko. 2010
  • Pic microcontrollers. Application practice. Christian Tavernier.2004
  • Development of embedded systems using PIC microcontrollers. Tim Wilmshurst. 2008
  • Data sheet: PIC16F628A, FYQ 3641, LM2575.
  • Tutorial on programming PIC controllers for beginners. Evgeny Korabelnikov. 2008

Below you can download the firmware and PCB in LAY format

List of radioelements

Designation Type Denomination

Shop

MK PIC 8-bit

PIC16F628A

1
Search in store
VR2 DC/DC pulse converter

LM2575

1 5VSearch in store
VT1-VT4 Bipolar transistor

KT315A

4
Search in store
VD1, VD3, VD4 Diode

D310

3
Search in store
VD2 Schottky diode

1N5819

1
Search in store
VD5 Diode bridge

DB157

1
Search in store
C1, C2 Capacitor20 pF2
Search in store
C3 Capacitor0.1 µF1
Search in store
C4 330 µF 16 V1
Search in store
C5 Electrolytic capacitor100 µF 35 V1
Search in store
R1, R2 Resistor

10 kOhm

2
Search in store
R3-R6 Resistor

1.5 kOhm

4
Search in store
R7-R9, R11-R14 Resistor

300 Ohm

7
Search in store
R10 Resistor

360 Ohm

1

Clock with a small 4-digit indicator. The dot between hours and minutes flashes at a frequency of 0.5 seconds. Can be built into any object: a desk calendar, a radio, a car. Estimated error - 0.00002%. In practice, for six months there was never a need for correction.

Power supply 4.5 - 5 volts, current up to 70mA. The voltage stabilizer is located in the adapter plug. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer according to a standard circuit. For a car, of course, a transformer is not needed. The microcircuit does not heat up without a heatsink. Connector for 3.5mm power supply. Quartz 4 MHz. Any low-power n-p-n transistors.

Any buttons. The length of the button pusher is selected based on the design requirements. You can also solder buttons on the conductor side. Each time you press the button, a unit is added. When held, the counting speeds up to a reasonable speed.

Resistors MLT - 0.25. R7 - R14 300 - 360 Ohm. R3 - R6 1-3 kOhm. Batteries: 4 pieces of GP-170, or similar. When the mains voltage is turned off, they only supply power to the microcontroller. They hold up for 8 days exactly, I checked. Diodes with the lowest voltage drop in the forward direction. The boards are made of one-sided foil fiberglass.

Before installing the microcontroller into the panel of the manufactured board, turn on the power and measure the voltage on the 14th leg of the socket. It should be 4.5 - 4.8 volts. On the 5th leg 0 volts. If you are not sure about the quality of the manufactured board or the serviceability of the parts, check the device without a microcontroller.

This is done very simply:

  • Insert a jumper from the bare wire into the socket, terminals 1 and 14. This means that +4.5 volts from the first leg will open transistor VT 2 through a resistor and the cathode of the clock unit indicator will be connected to zero.
  • Connect any wire with one end to +, and with the other end alternately touch terminals 6,7,8,9,10,11,12,13 of the socket.
  • At the same time, observe the lighting segments and their correspondence to the diagram: + on the 6th leg - segment “g” is lit and so on.
  • Move the jumper to terminals 2 and 14 of the socket. Check all segments of the minutes unit indicator.
  • Jumper 18 and 14 - tens of hours are checked, 17 and 14 - tens of minutes.

If something doesn't work correctly, fix it. If everything is correct, program the microcontroller and insert it into the socket with the power off. HEX file is attached. Turn on the power and get a ready-made watch.

If you buy all the parts, including resistors, then according to my diagram the device will cost about 400 rubles:

  • - 22.8 UAH
  • - 10 UAH
  • FYQ 3641AS21 - 9.3 UAH
  • Panel - 3 UAH
  • Quartz - 1.5 UAH

Source: www.cxem.net


This diagram is also often viewed:

These electronic watches are the simplest. They were assembled in a few hours. The basis is a PIC16F628A microcontroller; in addition to it, the clock contains several simple and cheap elements; the information is displayed on a 4-digit (clock) LED indicator. The circuit is powered from the mains and also has a backup power supply. This design can be recommended for beginners; I specifically provided the original program with detailed comments to make it easier to understand what and how it works.

The circuit is very simple, simple and the algorithm of their work (see comments in the source). Buttons kn1 and kn2 are used to correct the time - hours and minutes, respectively. The clock has a 24 hour display format. In the 1st digit of the clock, an insignificant zero has been suppressed. The accuracy of the clock depends entirely on the frequency of the quartz resonator. But even without special selections of quartz and capacitors in the clock generator, the clock runs very accurately.

The clock is assembled on 2 printed circuit boards, docked one to the other at an angle of 90 degrees. The entire indicator is placed on one board, and everything else is on the other. The backup battery was broken from a Chinese lighter with an LED flashlight. We remove the LED and install the battery holder on the board. The photo shows that cut-off resistor leads are connected to the batteries - they hold this entire structure. Of course, the capacity of such batteries is small, but when the watch is powered from the mains, no current is consumed from the batteries. They power the circuit only if there is no mains power. In this case, only the microcontroller is powered, the indicator is not powered by batteries, so it goes out, and the clock continues to tick. The control buttons are located on the board in any convenient place on the case. The design of the buttons can be any. To supply power from the network, a Chinese power supply adapter was used, which added a board with a 7805 chip (5-volt stabilizer). In general, any power supply with an output voltage of 5V and a current of 150mA will do.

The program is written in such a way that it can be used for initial study of the PIC microcontroller; the action of almost every command is commented on. If desired, you can easily add additional functions to it, such as a calendar, timer, stopwatch, etc.



File:
Size:
Content: