1. Project Background
The switch light system using latitude and longitude automatic control is a research topic proposed based on the market demand for multifunctional intelligent lighting energy-saving products. With the help of GigaDevice GD32F350 Innovation Design Competition, the excellent power of Cortex-M4 high-performance core is brought into play, the technology that has been reserved is upgraded and transformed, and the project is perfected and developed.
According to statistics, my country's lighting electricity consumption accounts for about 10% of the country's total power generation, and urban public lighting accounts for about 30% of my country's lighting power consumption, with an annual expenditure of hundreds of billions of yuan.
Some of the street light switch controls currently in use are manually controlled according to the daylight and nighttime conditions. The switch of the street light control cabinet is closed when it is dark, and the switch of the street light control cabinet is disconnected when it is light. This manual operation sometimes causes the street light to be turned on and off in a delayed manner, resulting in unnecessary waste of electricity.
There are also controllers that automatically control the switch of lights according to the set time, but sometimes the lights are turned on and off too early or too late, resulting in delayed switch on and off, and unnecessary waste of electricity. For example: At 17:12 on March 12 this year, I saw that all the lights were on in a park. At this time, the sun was still high, so I took a photo at random, as shown in Figure 1 below. According to the convenient inquiry website, the sunrise and sunset times in Nanjing on that day were sunrise 06:18:49, noon 12:14:36, sunset 18:10:22, dawn 05:54:31, and dark 18:34:41 (see Appendix 1). According to the daily calendar, the sunrise and sunset times in Nanjing on that day were 06:19:23, 18:10:20, 05:55, and 18:35 (see Appendix 2). It can be seen that the lights were turned on more than 80 minutes before dark.
Figure 1: Park lights on 20180312_1712
There are also methods to determine the time to turn on and off the lights based on longitude and latitude, but they use a simple calculation of mean solar time, which has a large error, sometimes up to 20 minutes, because the length of the true solar day varies with the seasons, and its changes are mainly affected by two factors: First, due to the existence of the obliquity of the ecliptic (23°26′), that is, the inclination of the ecliptic plane to the equatorial plane, the sun moves back and forth relative to the celestial equator during its annual motion, causing annual changes in the length of the true solar day; second, due to the elliptical orbit of the earth, the changes in the distance between the sun and the earth, and the different speeds of the earth's revolution, causing annual changes in the sun's daily ecliptic longitude difference itself. These two factors act simultaneously and interfere with each other, causing changes in the length of the true solar day. Some programs give a timetable for switching lights on and off, which changes once or twice a month; some use simple approximate calculations, which have large errors, sometimes with an error difference of more than ten minutes; there are also technical solutions that use single-chip microcomputers and are used to store the daily switching light timetable calculated according to natural astronomical time, and control the daily switching light time through programs, but the limitations are very large. The memory can only store the switching light timetable of a single location, which cannot meet the actual needs of switching lights at different locations (different longitudes and latitudes). Different locations must write different timetables in the memory, which brings inconvenience to product production and poor product mobility.
In addition, there are also switch light controllers that use light control alone on the market. The disadvantages are large errors, poor repeatability, and easy interference and malfunction, and they do not meet the requirements for intelligent monitoring of street lights.
Therefore, automatically and accurately controlling the switching lights is conducive to saving energy while ensuring lighting. If it is further coordinated with relevant intelligent lighting energy-saving products to achieve intelligent dimming, its energy-saving effect will be more significant. 2. Product Introduction This is a switch light system that uses automatic control based on longitude and latitude. It uses GD32F350 as the intelligent control unit (controller for short). It has multiple switch light functions such as longitude and latitude time control, light control, manual control, PC control, etc. It can control the lights in an area (a section of road or a road, a town, a park, etc.) and can be widely used in street light control, urban lighting projects, and neon light control. This product uses a high-precision astronomical algorithm to calculate the local sunrise, sunset, and transit time based on the local longitude and latitude of each place. It is suitable for use anywhere in the country. Its built-in astronomical algorithm can calculate the time of daybreak and sunset at any location very accurately. According to data sampling test, compared with the calculated value of the Sunshine Perpetual Calendar (V5.2beta), the maximum error measured within 100 years is no more than 3 seconds. Compared with the internationally renowned astronomical software SkyMap Pro (V10.0.4), its calculation error is within one minute (the software is only accurate to the minute). Compared with the Chinese astronomical calendar compiled by the Purple Mountain Observatory of the Chinese Academy of Sciences, the maximum error of the sunrise and sunset time and the daybreak and nightfall time calculated by it is within 1 minute (in fact, the calculation results of the astronomical calendars of different countries can also differ by one minute).
3. Technical features of the product
3.1 Automatic light switch control. According to the longitude and latitude of different locations, according to the changing laws of the earth's rotation and revolution, the astronomical algorithm is used to automatically and accurately calculate the local daybreak and nightfall time, and automatically correct the daily light on and off time, avoiding the trouble of manual correction and light switch control.
3.2 Flexible setting of various control parameters. The relevant working parameters can be set flexibly and conveniently according to the actual needs of each location or road contrast. 3.3 It integrates functions such as manual forced light on, light-controlled light on/off, and light on/off control through PC.
3.4 The set working parameters are saved in Flash and will not be lost in the event of a power outage.
3.5 If combined with a wireless module or other communication interface module, it can be easily remotely controlled or centrally controlled, and the relevant working parameters can be intuitively viewed or configured through the supporting application software.
3.6 It can set the artificially defined solar altitude angle for daybreak and nightfall, and can also set the standard daybreak and nightfall to advance or postpone the light on/off time.
3.7 It can output the light on/off time or sunrise and sunset time for several days to the computer, so that the management personnel can know the light on/off time.
3.8 It has a complete indication and alarm function, with a variety of light on/off status indications, clock failure indications, etc. 4. Innovation and advancement of the product The light switch system is automatically controlled by longitude and latitude, and the light switch is calculated and controlled according to astronomical algorithms. The innovation lies in the fact that the astronomical algorithm for calculating the time of daybreak and nightbreak is a high-precision algorithm based on Kepler's three laws of planetary motion and Newton's law of universal gravitation. When calculating the time of sunrise and sunset and the time of daybreak and nightbreak, the precession of the earth's axis (the conical motion of the earth's axis around the ecliptic axis, the radius of the cone is 23°26′, the precession speed is 50.29″ per year, and the period is about 25,800 years), atmospheric refraction (most obvious near the ground, its value is about 34′), morning and evening shadows and other factors are also considered. The time of daybreak and nightbreak calculated by this algorithm is very accurate at any location. According to data sampling test, compared with the calculated value of the daily shuttle perpetual calendar, the maximum error measured within 100 years does not exceed 3 seconds (see the calculation data test section). Various working parameters can be conveniently viewed or changed by users through the supporting computer software, and the set working parameters will not be lost in the event of a power outage. 5. Circuit Schematic Diagram 5.1 Principle block diagram
The principle block diagram of the longitude and latitude automatic control switch light device designed with GD32F350 is shown in Figure 2.
Figure 2 Principle block diagram of the longitude and latitude automatic control switch light device
5.2 Circuit principle diagram
The circuit principle diagram of the longitude and latitude automatic control switch light device designed with GD32F350 is shown in Figure 3.
Figure 3 Circuit principle diagram of the longitude and latitude automatic control switch light device
6. Usage of MCU internal modules
The schematic diagram of the longitude and latitude switch light controller is shown in Figure 4. It uses the RTC, DMA, interrupt, USART, ADC, GPIO, timer and other modules in GD32F350.
Figure 4 Schematic diagram of the longitude and latitude switch light controller
7. MCU pin allocation and software flow
7.1 Main pin function allocation
This controller uses GD32F350R8T6, and the main pin function allocation is as follows:
l PA0 pin: external switch S1, manual priority control of LED lights, used for inspection or maintenance;
l PA2 pin: serial port USART1-TX, 115200bps, 8N1;
l PA3 pin: serial port USART1-RX, 115200bps, 8N1; PB7 pin: external button B3, press the button before outputting the switch time, the calculated date is incremented by year, otherwise it is incremented by day; PB8 pin: LED1, lights up when the light is turned on; PB9 pin: LED2, lights up when the light is turned on by light control; PB10 pin: LED3, lights up when the light is turned on manually; PB13 pin: light-on signal output, high level turns on the light, and the LED light is lit by relay drive; PC0 pin: (ADC channel 10) detects VDD voltage; PC1 pin: (ADC channel 11) detects the photoresistor signal as the illumination value to assist in controlling the switch light; 7.2 Keil MDK software interface The firmware library used by this controller is firmware for GD32F3x0 V1.0.0. The software interface during debugging is shown in Figure 5 below: 380289 Figure 5 Software interface during debugging 7.3 MCU software flow The main program flow of the MCU software is: l Initialization rcu_config();/* system clocksconfiguration */ systick_config(); /* systick configuration */ gpio_config();/* GPIO configuration*/ nvic_config();/* NVIC configuration*/ timer_config(); /* TIMER1 configuration *//* Initialize LED, USART1 and buttons*/ gd_eval_led_init(LED1);//Lights up when the light is turned on;
gd_eval_led_init(LED2);//Lights up when the light is turned on by light control;
gd_eval_led_init(LED3);//Lights up when the light is turned on manually;
gd_eval_led_init(KD_OUT);//Light-on signal output, 1 means turning on the light, 0 means turning off the light,
nvic_irq_enable(USART1_IRQn, 0,0); gd_eval_com_init(EVAL_COM1,115200);//USART1 usart_interrupt_flag_clear(USART1,USART_INT_FLAG_IDLE);
gd_eval_key_init(KEY_WAKEUP,KEY_MODE_GPIO);//PA0 pin, manual priority control LED light, used for inspection or maintenance;
EvbKeyConfigPoll();//External button B3;
/* ADC configuration */
adc_config();
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
rcu_ckout_config(RCU_CKOUTSRC_CKSYS,RCU_CKOUT_DIV1);/* enable PMU clock */ rcu_periph_clock_enable(RCU_PMU);/* enable the access of the RTCregisters */ pmu_backup_write_enable(); rtc_pre_config();l Loop operation Detect artificial light-on signal Detect the status of button B3 ADC detects illuminance signal Convert the photoelectric sensor ADC measurement value into the actual illuminance value Determine the light-operated switch light sign and give an indication Read out the current date and time Find the sun's rising and falling position on the day based on the longitude and latitude Calculate the time to turn on and off the light Determine the time-controlled light switch signal based on the current time and the light switch time Determine the comprehensive light switch statusl DMA, USART1, Timer1 interrupt processing Timing delay processing If there is a command from the PC, process the command
8. Supporting computer software8.1 Description of the main software interfaceThe longitude and latitude automatic control light switch device (referred to as the controller) designed with GD32F350 has a supporting computer software interface as shown in Figure 6 below.
Figure 6 Main interface of PC software
The main options are as follows:
8.1.1 Serial port selection: Select the serial port connected to the GD32F350 controller. You can use the "Close/Open" button to control whether the serial port is open.
8.1.2 Communication rate: Select the communication rate of the serial port connected to the GD32F350 controller. You can choose 4800bps, 9600bps, 57600bps, 115200bps.
8.1.3 Communication network selection: You can choose serial port, network, GPRS wireless network.
8.1.4 Device selection: Select "Clock controller" when the computer is connected to the controller, and select "GPS receiver" when the computer is connected to the GPS receiver.
8.1.5 GPS date and time: When the GPS is working stably and receiving the correct signal, it will display the GPS time (Beijing time), the longitude and latitude of the receiver's location, and the current GPS status (available or unavailable).
8.1.6 Calibrate computer time: When GPS is available, you can click this button to calibrate the computer time with the GPS clock.
8.1.7 Computer date and time: Display the current date and time indicated by the computer. Double-clicking this icon will switch to entering the date and time, and you can manually enter the date and time.
8.1.8 Controller date and time: When the computer and controller are online, it will display the current date and time in the controller.
8.1.9 Calibrate controller time: When the computer and controller are online, you can click this button to calibrate the controller time with the computer clock or the manually entered date and time. 8.1.10 Calibrate the controller's longitude and latitude with GPS: When GPS is available, click this button to calibrate the longitude and latitude set in the controller with the longitude and latitude indicated by GPS. 8.1.11 View and set parameters l Set value: The value that the user needs to set l Actual value: When the computer is connected to the controller, read the actual storage value in the controller; when the software is not connected to the controller, it displays "unknown" l Longitude: The longitude of the controller's location, set in "degrees: minutes" l Latitude: The latitude of the controller's location, set in "degrees: minutes" l Daylight and nighttime solar altitude angle: Used to calculate the solar altitude value at daylight and nighttime, expressed in degrees. When this value is expressed as 0, the calculated daylight and nighttime times represent the sunrise and sunset times. When the sun is above the horizon, the altitude angle is positive; when the sun is below the horizon, the altitude angle is negative. It is usually set to -6.0 degrees. The detailed explanation is as follows:
For a period of time before sunrise (dawn) and after sunset (dusk), the sky is still bright and in a semi-bright state. During this period of time, it is neither true day nor true night, but a transitional period between day and night, called twilight. Modern astronomy calls it twilight, which is the combination of morning light and twilight. The causes of the two are the same, both of which are the result of the reflection and scattering of sunlight by the high-altitude atmosphere.
The morning light ends at sunrise, and there is a problem of the beginning of morning light; the twilight begins at sunset, and there is a problem of the end of twilight. The beginning of morning light and the end of twilight are both based on a certain "low degree" of the sun. According to different needs, twilight is divided into three levels: civil twilight, nautical twilight and astronomical twilight. Their standards for the "low degree" of the sun at the beginning of morning light and the end of twilight are 6°,12° and 18°.
——When the weather is clear, the center of the sun disk falls from the horizon to 6° below the horizon. The intensity of twilight is bright enough for normal outdoor activities, and no lighting is needed indoors. This period of time is called civil twilight. At any time, about 5% of the world is in this state.
——When the sun is between 6° and 12° below the horizon, it is too dark for outdoor activities, and indoor work requires lighting; the bright stars in the sky have already appeared, but the distant horizon is still clearly visible. This period of time is the most suitable time for navigation star measurement (determining the altitude of celestial bodies), so it is called navigation twilight.
——The real night begins (or ends) when the sun falls to 18° below the horizon. At this time, the dimmest stars visible to the naked eye begin to appear, the sky is completely dark, and the astronomical twilight ends.
l Light-on advance: the number of minutes before the controller calculates that the light should be turned on at dark.
l Light-off delay: the number of minutes before the controller calculates that the light should be turned off at dawn.
l Energy-saving delay: the number of minutes after the light is turned on to delay the energy-saving signal.
l Energy-saving advance: the number of minutes before the energy-saving signal is turned off at the time of light-off.
l Light-on time: the light-on time calculated according to the sun's altitude angle at dawn and dusk and the light-on advance. The time is different in different places and on different dates, and is expressed in "hours: minutes".
l Light-off time: the light-off time calculated according to the sun's altitude angle at dawn and dusk and the light-off delay. The time is different in different places and on different dates, and is expressed in "hours: minutes".
Write to controller: write the set value into the controller for permanent storage without fear of power failure. When you click this button, the following prompt appears: Select "Yes" to write all parameters, select "No" to not write longitude and latitude, and select "Cancel" to not write anything and cancel this operation. 8.1.12 Monitoring switch: When the computer is connected to the controller, click this button to connect the computer to the controller or to go offline. 8.1.13 Working status indication: The working status indication of the controller includes the following indications: l Online: This indicator light flashes when the computer is online with the GPS receiver or controller l Automatic: This light indicates the automatic working status l Time-controlled lighting: This light is on when the lighting time is calculated by the latitude and longitude and the set related parameters l Light-controlled lighting: This light is on when the lighting status is determined by the light-controlled signal l Fault: This light is on when the controller detects a fault
8.1.14 Window control:
When you click this button, a window control interface pops up. Then click the corresponding button (network parameter configuration, GPRS wireless network, calculate the time for switching lights on and off, read the time for switching lights on and off for each channel, read the administrator's mobile phone number, start the debugger, view working parameters, set product identification, and correct clock accuracy) to open the corresponding configuration interface. 8.2 Check the on/off time To calculate the on/off time, the controller is required to output the on/off time for a number of days. Please follow the steps below: 8.2.1 Click on the window control and the interface shown in Figure 7 will pop up: 380291 Figure 7 The window control interface of PC software 8.2.2 Click on the calculate on/off time again. In the pop-up window, fill in the number of days for which the on/off time needs to be read. Then click on the calculate and read out on/off time button to read out the relevant data. The controller will output the on/off time and the off time of each day from the current date. The results are rounded to the nearest minute, as shown in Figure 8: 380292 Figure 8a The output display interface of the on/off time 8.2.3 If you press the B3 button on the GD32F350 development board before clicking the Calculate and Read Out Light Time button, the daily sunrise time, sunset time, day length, and transit time will be outputted year by year starting from the current date, all accurate to seconds, as shown in Figure 9 below: 380294 Figure 9a Sunrise and Sunset Time Output Display Interface 380295 Figure 9b Sunrise and Sunset Time Output Display Interface 9. Calculation data test The switch light device designed by GD32F350 for automatic control of longitude and latitude is compared with the calculated value of the daily calendar V5.2. After data sampling test, the maximum error within 100 years is no more than 3 seconds, as shown in Table 1 and Table 2. Table 1: Comparison table of sunrise and sunset time and daily calendar V5.2 time Nanjing: Longitude: 118°46′ Latitude: 32°3′ Error A5pt]=日出-(日梭)日出 误差B=日落-(日梭)日落 误差C=上中天-(日梭)上中天