A practical astronomical clock controller is designed. The hardware consists of power supply unit, single chip computer unit, man-machine interface unit, real-time clock unit, illumination acquisition unit, relay output unit and communication unit. The controller takes STM32F103 as the core, calculates the sunrise and sunset time by setting longitude and latitude and current date, and combines with the illumination collected by analog-to-digital converter to control the output of relay. The controller can also receive GPRS control instructions to achieve special control. With the development of society and the requirement of energy saving and consumption reduction, the requirement of road traffic lighting is getting higher and higher. It is necessary to switch the power supply of lighting according to sunrise and sunset time and illumination, as well as remote temporary instructions, in order to realize the flexible control of lighting. Therefore, an astronomical clock controller is designed and applied in practice. An astronomical clock controller based on MCU is designed. The system block diagram is shown in Figure 1. The circuit consists of power supply unit, MCU unit, man-machine interface unit, real-time clock unit, illumination acquisition unit, relay output unit and communication unit.
The power supply unit supplies power to the other units. The keys of the human-machine interface unit are connected with the IO port of the single chip computer. The LCD of the human-machine interface unit is connected with the single chip computer through parallel level conversion chip. The illumination acquisition unit is connected with the AD acquisition channel of the single chip computer. The real-time clock unit is connected with the single chip computer through the I2C bus. The communication unit is connected with the single chip. The UART serial port of the machine is connected, and the relay output unit is connected with the IO port of the single chip computer.
The power supply unit uses TOP253 chip as the control chip. Through flyback pulse transformer, 220V AC is converted into voltage used by system chip, 5V, 3.3V, isolated 24V, etc. The single-chip computer unit, with STM32F103 as its core, belongs to ARM Cortex-M3 series with 72 MHz main frequency, 12-bit dual ADC, I2C, USART and other interfaces, built-in SRAM and large capacity FLASH, with high integration. The 3.3V, 8MHz active crystal oscillator is used, and the SWD interface is used as the debugging port. The external hardware watchdog MAX706S is used to reset the chip when the program runs and the software runs again after receiving external interference. Compared with the watchdog inside the chip, MAX706S makes the chip reset when the system voltage is not stable and avoids misoperation when the system is powered on or off. The man-machine interface unit consists of two parts: key press and LCD. The key press part is directly connected with IO of single chip computer. Because the working voltage of STM32F103 is 3.3V and the interface voltage of LCD is 5V, two level conversion chips 74LVC4245 APW are needed. See Figure 2. The main chip of the real-time clock unit is RX8025SA, which is connected to the I2C pin of STM32F103. When the system works normally, the 3.3V of the power supply unit provides power for RX8025SA. When the system is not powered on, the CR2032 battery provides power for the clock chip to keep the real-time clock data counting. The illumination acquisition unit converts the 4-20mA current signal of the illumination sensor into a voltage signal by analog photocoupler HCPL-788J. After low-pass filtering, the signal is sent to the pin of the AD sampling channel of STM32F103 single chip computer, which acts as isolation. The communication unit adopts GPRS communication and SIM900A module, which is connected with the serial port of STM32. The output unit of the relay is connected with two output pins of the single chip computer unit, and then connected to the coils of two 24V relays through the photocoupler TLP627. The two relays are the main control relay and the energy-saving relay, each providing a normal open-dry output. LCD is 128*64 dot matrix liquid crystal, which is divided into four lines, each line can display 16 characters or 8 Chinese characters. There are four keys in the key part, namely “MODE”, “SHIFT”, “DATA” and “ENTER”. Because it takes a long time to display a screen, when the key-reading program is placed in the main program, there is sometimes no response when the key is pressed. Therefore, the key-reading program and the key-shaking program are interrupted in the 1mS timer.
The display program adopts menu structure and can display various parameters and real-time status by turning pages with keys. Through keys and LCD display, date time, local longitude and latitude, on-light illumination and off-light illumination, and confirmation time can be set. STM32F103 obtains the data of specific year, month and day from real-time clock unit and local longitude and latitude from human-machine interface unit. Based on this, the precise days from January 1, 2000 to calculation day are calculated, and then local star time, solar ecliptic longitude and solar inclination, thermostatic element and solar circumference are calculated. Finally, the time of the sun in the south of the ecliptic can be obtained, and the time of sunrise and sunset can be obtained by distinguishing the eastern and Western hemispheres. In the DMA mode of dual ADC, one ADC is used for illumination acquisition and the other grounding is used to verify the validity of data. According to the requirement of 24 points per 20 mS sampling, the trigger timer of ADC is turned on, and the average value of 24 AD sampling times is taken for digital filtering to eliminate power frequency interference. The corresponding lumen number is converted by preset coefficients. Open the DMA interrupt for conversion completion. The response time required by communication software is not high, so it can be processed by DMA of STM32F103 chip instead of CPU time consumed by sending and receiving interrupts. DMA interrupt does not open, and serial data processing is carried out in timer interrupt. MCU communicates with GPRS module through AT instruction set to monitor the received short message. In order to prevent misoperation, the switch light instructions need different 32-bit passwords, and CRC checking of messages. The setting of interrupt priority requires that the interrupt priority of 1mS timer is higher than that of sampled DMA.
When no communication control instruction is received, if the current light is not turned on, the illumination is continuously less than the illumination of the light in the confirmation time (default 5 minutes), or the current time is greater than the sunset time, the software closes the main control relay. When turning off the lights, two conditions need to be satisfied simultaneously, that is, the illumination continuously exceeds the illumination of turning off the lights in the confirmation time, and the current time is greater than the sunrise time. The output of the energy-saving relay is related to the energy-saving time. The midpoint of the last sunset time and the next sunrise time is the midpoint, and half of the energy-saving time is offset. For example, if the energy-saving time is set to 4 hours, the energy-saving relay will be closed between 2 hours before and after the midpoint, and the rest of the time will be disconnected. The priority of communication command is higher than that of light control and astronomy control. After receiving the command, the switch lamp is executed immediately, and the main control relay is closed or disconnected. The parameters are set to 121.32 degrees longitude, 31.13 degrees latitude, 10 September 2017 real-time clock time, the sunrise time calculated by the controller is 05:44:15, and the sunset time is 18:12:23, which is the same as the time indicated by the calendar. The same data can be obtained by changing longitude, latitude and date many times. The accuracy of illumination measurement is also high. GPRS module can control the output of relay correctly after receiving instructions. The astronomical clock controller based on STM32F103 microcontroller can set parameters such as longitude, latitude, date and time through human-machine interface, collect illumination and calculate sunrise and sunset time. It can flexibly control according to the illumination and sunrise and sunset changes, and can carry out GPRS wireless control. The design has been tested in small batches and works normally in actual operation.