Summary of the project "Automatic Control of Small Hydropower Stations"
[Copy link]
1. Project Background This project is implemented on the basis of the original "Remote Control of Small Hydropower Station" project. Remote control is to check the water level remotely through the Internet camera, and then use the mobile phone APP to control the opening or closing of the water inlet gate of the hydro-generator set through the network relay. The relevant electrical and mechanical parts have been completed long ago. This project adds a single-chip microcomputer control module to the original one, automatically adjusting the water inlet gate according to the water level, replacing the original manual operation. As long as the added single-chip microcomputer control module can output the electrical signal of opening or closing according to the water level, it can control the water inlet gate through the existing intermediate relay. The project consists of two parts, one is the water level monitoring device installed in the water inlet pool, and the other is the automatic control device installed in the machine room. The water level monitoring device installed in the water inlet pool has also been completed. It uses a 51 single-chip microcomputer to detect the water level changes in the water inlet pool through an ultrasonic module, and then transmits the relevant water level information to the machine room. The transmitted information content consists of two items: the instrument installation height and the current water level. The data format is "#X XX*YYYc", where XXX is the installation height of the instrument (unit: cm), YYY is the current water level (unit: cm), c is the checksum, and the transmission frequency is about once every 0.8 seconds, and the transmission method is wired or wireless. The focus of this project is the automatic control device installed in the machine room. 2. Project plan This project is mainly composed of basic setting module, display module, data receiving module, data processing module and output control module. The block diagram of the relationship between the modules is as follows:
1. Basic setting module This module is provided for users to set the standard water level and deviation range. It is connected to the standard water level and deviation range through eight-bit DIP switches (actually seven bits are used) respectively. PB0~PB6 pins, among which PB0~PB3 are for setting standard water level data, each 0.5 meter is a level, from 2.0 meters to 9.5 meters, a total of 16 levels. PB4~PB6 are the data for setting the positive and negative deviation of water level, with each 0.2 meter as one level, and there are eight levels from 0.2 meter to 1.6 meter. Compared with the standard water level, the actual water level is considered to be normal water level if it is within the positive and negative deviation range, and it is considered to be high (or low) water level if it exceeds the positive and negative deviation range, and it is considered to be super high (or super low) water level if it exceeds 2 times. The control output module outputs the gate opening or closing signal and the output signal duration according to different situations, so as to achieve the purpose of controlling the water inlet gate. The standard for water level determination is shown in the figure below:
2, display module The display screen uses LCD5110 font-free type. The screen has 84*8 dot matrix and can display simple graphics. The project uses soft font library to display ASC!! characters and 12*14 dot matrix Chinese character subset. The screen display content is arranged as shown in the figure below:
The left half of the screen is a simulated water level bar graph and height value. The water level bar graph is displayed through dot matrix simulation according to the current water level. In the height value display area, the top line displays the installation height of the water inlet pool detection instrument, and the bottom line is fixedly displayed as 0m. The actual water level data is displayed in lines 2~5. When the water level is extremely high, the value is displayed in line 2. When the water level is relatively high or slightly higher than the standard water level, the data is displayed in line 3. When the water level is slightly lower than the standard water level and relatively low, the value is displayed in line 4. When the water level is extremely low, the value is displayed in line 5. The upper right part of the screen displays "Water Level Meter", and the lower right part of the screen displays the standard water level set by the user "BZ=XX.X” and positive and negative deviations. The current status is displayed in the middle right of the screen. When the microcontroller is started, it will display “Waiting for Signal”. If the signal reception fails or the verification fails, it will display “Signal Error”. If the standard water level set by the user is higher than the installation height of the instrument, it will display “Setting Error”. In other cases, it will display “Extremely High Water Level”, “High Water Level”, “Normal Water Level”, “Low Water Level” and “Extremely Low Water Level”. 3. Data receiving module: The frequency of data receiving is about once per second, and each time it receives 9 bytes of data (SPI mode) or 8 bytes of data (serial port mode). In the long term, it is possible to consider adding wireless transceiver transmission function according to the needs, which can be realized by purchasing radio frequency modules. 4. Control output module This project outputs a low-level signal through the PB10 pin of PB8 (i.e., LED2 and LED3 on the development board) to drive the LEDs. bri]5V four-way micro relay module (two are currently used, and the rest are reserved for future expansion), and then the micro relay drives the 12V intermediate relay to control the gate motor action, so as to achieve the purpose of opening or closing the gate. As mentioned above, the part of the intermediate relay controlling the motor action has been realized in the "Remote Control of Small Hydropower Stations" project. This project only needs to purchase four-way micro relay modules, and the purpose of controlling the gate can be achieved by controlling the on and off of LED2 and LED3. 5. Data processing module Data processing does not involve direct contact with external devices. It mainly verifies the received data, then judges the current water level data, outputs the judgment results to the screen, and controls the relay action as needed. 3. Project implementation process 1, Establishing the development environment and lighting up the LED Since the beginning of August, when the competition had not yet started, I had been watching the STM32 teaching videos on "I Want to Self-study Network", downloaded and installed the IAR V7.20 version of the software, and established the project template according to the video. After receiving the development board on August 26, I downloaded the DEMO program and found that the version of IAR V7.2 was too low. I searched for several so-called high-version IARs online, but after downloading and installing them, I found that they were all fake. The required software was not available, but more than a dozen messy software were installed. I couldn't find a suitable version of IAR, so I had to turn to KEIL. My computer was originally installed with the KEIL C51 development platform. I tried to install KEIL MDK, but failed to install and uninstall it many times. The two versions conflicted, causing both software to be unable to work properly. During this period, I also posted a post "Can't I install Keil C51 and Keil MDK at the same time? " for help (link https://en.eeworld.com/bbs/forum.php?mod=viewthread&tid=852424&extra=). After struggling for a few days, I finally followed the instructions of forum friend anger0925 and downloaded and installed KEIL V5 version of MDK, and then I was able to coexist peacefully with KEIL V4 version of C51. After several days of study and analysis of the DEMO program, I finally downloaded the LED light control program that I rewrote based on the DEMO program on August 31 and successfully lit up the LED light. 2, LCD5110 driver and main screen design We started debugging the driver program for LCD5110 on September 1st. This program was ported from C51. The process was relatively smooth and it took only more than two days to light up the screen. Initially, the PB2~PB6 pins were used to drive the LCD5110, but later it was changed to the PC5~PC9 pins. By September 6, the design of the main screen and the writing and debugging of the ASCII code character library and the 12*14 dot matrix Chinese character library subset had been completed. The ASCII font is a complete set. When processing a character, you only need to subtract 32 from the character's internal code to get the row number of the font array. The character can be written directly in the program. The Chinese font is a subset and does not borrow the internal code. Therefore, it can only be referenced according to the row number of the font array, which is not intuitive in the program. 3, Debugging of the basic setting module From September7 to September10, the debugging of the DIP dip switch setting program was completed in four days. At first, the dip switch was connected to the PC0~PC6 pins. After repeated debugging, it was changed to the PB0~PB6 pins. The setting data of the dip switch still could not be read normally. The read-in value was unstable and would jump periodically. During this period, I also posted a post "Why can't I read the status of the pin?" for help (link https://en.eeworld.com/bbs/forum.php?mod=viewthread&tid=925982&extra=). Finally, through repeated measurement of the pin voltage, I found that although the pin was set to pull-up resistor input, it still could not get a high-level input signal. The measured pin high-level voltage was only between 0.8~1.2V, which obviously did not reach the 1.69~2.To achieve the 11V standard, we have to add pull-up resistors to the corresponding pins. 4. Debugging of data receiving module This is the module that I spent the most time and energy on. From September 11th to September 28th, it took more than half a month. During this period, I was almost exhausted and almost desperate. With the care and help of the competition leader nmg, I posted for help and received enthusiastic advice from many forum friends. Finally, I solved the problem of SPI and serial port receiving data. The reason is that I have not been in contact with single-chip microcomputers for a long time. I just started to contact 32-bit single-chip microcomputers this time, and I am still in the introductory stage. For example, at the beginning, I didn't even know MOSI, and I thought that this M refers to the current single-chip microcomputer. During this period, I searched for information online, sorted and printed information, analyzed and debugged programs according to the information, and watched the timing captured by the logic analyzer. In the process of debugging programs, I also learned a lot of knowledge and accumulated some experience. In order to eliminate the influence of the high-level pin pair of 51 single-chip microcomputer on 32 single-chip microcomputer, a signal conversion circuit was specially built. Through unremitting efforts and the enthusiastic help of everyone, I finally successfully received the data. The first problem encountered during the debugging process was that the serial port assistant could not correctly receive the data sent by the 51 microcontroller, and all it received was 0. For this reason, I posted on multiple forums "The microcontroller sends data, but the serial port assistant receives 0\" for help (link https://bbs.eeworld.co m.cn/forum.php?mod=viewthread&tid=903790&fromuid=709956), and finally checked the program thoroughly and found that I had mistakenly written TH0=0 as TH1=0 when clearing timer 0 in the ultrasonic detection program, causing a serious deviation in the baud rate of the serial port. Of course, the serial port assistant received all 0. After the 51 MCU could correctly send data to the serial port assistant, I started to debug the GD32 MCU serial port receiving program according to the example. I redirected the information received by the serial port to the serial port assistant through prints. Maybe my data format was incorrect, and the output was all numbers. After debugging for a few days without any results, I switched to the SPI receiving program. I searched, sorted, printed, and analyzed the program code again. A few days passed in a flash, and I still had no idea how to debug the program. In desperation, I had to use software to simulate reading SPI data. A few more days passed. During this period, the person in charge of the competition, Mr. nmg, took the initiative to ask about the progress of the project. After learning about the difficulties I encountered, he encouraged me to post for help and also called on everyone in the group to help. I posted a post on September 26th, "SPI cannot receive data, please help" (link https://en.eeworld.com/bbs/forum.php?mod=viewthread&tid=976860&extra=), with the enthusiastic help of everyone, through careful analysis of the program code and timing diagram, I found that I had written the read code in the loop waiting for the chip select signal. The dark clouds finally passed, and I saw the bright sunshine. The software simulation SPI was finally debugged. Finally, I checked the serial port receiving program and output the received information to the screen. I found that the serial port had actually received the correct information a long time ago, but it turned into numbers when redirected to print. So far, the serial port receiving data and the software simulation SPI receiving data have been debugged successfully, but the microcontroller SPI1 receiving has not been debugged yet, but this is not important and does not affect the basic functions of the project. During the debugging of the data receiving module, there was also a phenomenon that the single-chip microcomputer interfered with the laptop computer. The computer mouse and keyboard did not operate at all, but the open windows kept changing or switching between windows, as if the mouse was hijacked. I suspected that the transmission or reception of the wireless mouse was interfered by the single-chip microcomputer. Turning off the power of the mouse and unplugging the mouse receiving head did not help. Only by unplugging the USB cable connected to the single-chip microcomputer could the problem be solved. Finally, at the moment of connecting the USB cable to the single-chip microcomputer, while the computer was not interfered by the single-chip microcomputer, I immediately downloaded the program and overwrote it with the recompiled program to solve the problem. This situation has happened twice, and the reason is still unclear. 5. Debugging of data processing module The debugging process of data processing module was relatively smooth. Most of the code was written when debugging the data receiving module. In order to alleviate the dilemma of being at a loss and regulate emotions and brain thinking, this part of the code was written by the way. However, the debugging process was carried out after the completion of the data receiving module. The whole debugging process took only two days and was completed on September 30. The first problem encountered in this process is to convert the received character data into numerical variables. I first decomposed the received characters into two strings, the installation height and the current water level, for direct display on the screen, and then converted the two strings into numerical variables. I don't know why the actual value is very different from the character. Finally, I changed to directly extract the corresponding characters from the received string and then convert them into numerical values, so that it passed in one go. Since the code at that time was not saved, the cause of the error is still unknown. The second problem I encountered was unsigned integer arithmetic. When I was writing a simulated water level bar graph, I divided the current water level by the installation height of the instrument to get the percentage of the current water level displayed on the screen, and then multiplied it by 48 (the number of dots in the screen height). The result was always zero. Finally, I realized that because the intermediate variable I defined was an unsigned integer, all decimals less than 1 were considered zero. I changed it to multiply first and then divide to solve the problem. In order to ensure that the data was correct, I changed the intermediate variable to a 16-bit unsigned integer to ensure that there would be no overflow. 6. Debugging the output control module The debugging of the output control module is relatively simple. I used the LED2 and LED3 pins on the development board. The program can directly control the on and off of these two LEDs. At first, I followed the habit of using the Calibri 51 microcontroller and used a low-level trigger relay. However, during the debugging process, I found that the microcontroller would set these two pins to a low level when starting, causing the two relays to operate at the same time. This is absolutely prohibited in practical applications, because the same DC motor is used to open and close, and simultaneous triggering will cause a short circuit. Although interlocking logic has been done on the intermediate relay to ensure that the two relays cannot operate at the same time, the microcontroller should not send out control signals at the same time. After testing, changing it to a high-level trigger avoids this phenomenon. 7. Overall debugging of the project After the data receiving and data processing modules are completed, the whole project is basically completed. In order to facilitate the demonstration, I found a plastic box to temporarily set up a "home" for the development board. The LCD5110 display is fixed on the box cover, the development board and the auxiliary circuits welded on the universal board are placed in the box, and the data input and output control are led to the outside of the box through the DuPont line. When the project is officially put into actual use, it is necessary to design the circuit diagram and PCB board separately, and install a shielding box to prevent the microcontroller from being interfered by the strong electric signal in the machine room. IV. Project display 1、Project background——Remote control transformation was carried out on small hydropower stations before.
Figure4-1-1, the process of remote control transformation of small hydropower station
Figure4-1-2、Power distribution control cabinet of small hydropower station (remote control cabinet on the left)
Figure4-1-3、Electrical devices such as network relays, intermediate relays, etc. in the remote control cabinet
Figure4-1-4, Mechanical control device added to the panel of the power distribution control cabinet
Figure4-1-5, Ultrasonic water level detector made with51 single chip microcomputer 2. Project development environment and GD32F350 development board. Figure 4-2-1. Received GD32F350 development board. Figure 4-2-2. After the interface is welded on the development board, the power-on test is passed. Figure 4-2-3. KEIL V5 is installed.23 MDK Development Environment
Figure 4-2-4, DEMO program compiled by KEIL 3, Expansion board, display screen and relay module
Figure 4-3-1, Expansion board for project development and testing
Figure 4-3-2, LCD5110 display screen and soldered backlight circuit connection
Figure 4-3-3. Four-way relay module for output control 4. Project development and testing process [attach] 381261 [/attach] Figure 4-4-1. Project development and debugging (connecting modules with Dupont wires) [attach] 381259 [/attach] Figure 4-4-2. Debugging the LCD5110 display (through a logic analyzer) [attach] 381260 [/attach] Figure 4-4-3. The LCD5110 display is debugged and displayed normally [attach] 381262 [/attach] Figure 4-4-4. The user setting is debugged and the set data is read after installing an external pull-up resistor [attach] 381263 [/attach] Figure 4-4-5. Analysis and debugging of the SPI timing diagram output by the 51 microcontroller [attach] 381264 [/attach] Figure 4-4-6. Debugging the SPI reception of the GD32 MCU
Figure 4-4-7. The fourth line simulates the level of the MOSI pin, which is consistent with the waveform of the second line
Figure 4-4-8. The fourth line simulates the SPI reception time and finds that the reception time is shorter than the sending time of one byte, so the code can be analyzed in a targeted manner.
Figure 4-4-9. SPI data is correctly received after adjusting the code
Figure4-4-10, Debugging of the main control module code
Figure4-4-11, Debugging of the main control module is completed - displaying normal water level
Figure4-4-12、The main control module has been debugged - the water level is displayed to be high
Figure4-4-13、The main control module has been debugged - the water level is displayed to be super high
Figure4-4-14、The main control module has been debugged - the water level is displayed to be low
Figure4-4-15, Main control module debugging completed - display ultra-low water level
Figure 4-4-16, Development and test device is temporarily fixed with a plastic box
Figure 4-4-17. The development board is connected to the host computer via Dupont line for SPI transmission
Figure 4-4-18. Overall view of joint debugging
Figure 4-4-19. Output control module of joint debugging
Figure 4-4-20, joint debugging display output content V. Problems existing in the project and future development direction The test of this project has been completed and achieved the expected purpose, but it is still a certain distance from practical application. The next step is to design the circuit diagram and PCB board, and install a shielding box to prevent electromagnetic interference before it can be put into practical application. Secondly, it is necessary to select a suitable RF module and add wireless transmission function to meet the different needs of users, because wireless transmission can better adapt to the terrain environment of small hydropower stations and reduce the workload of daily maintenance. Automatically controlling the water inlet gate according to the water level is only a small part of the automatic control of a small hydropower station. This device still has a lot of room for expansion. The general directions are: 1. It must have the function of detecting the current size and position of the gate to prevent the microcontroller from continuing to send operating signals when the regulator is opened (or closed) to the end; 2. Add a flash storage chip to save more user setting data. In addition to the current standard water level and positive and negative deviations, it can also save the duration of each action, the signal information receiving method, etc.; 3. Add the function of detecting the output voltage, current and phase of the hydro-generator set, and provide the function of remote query by users through the Internet. By using the Internet of Things technology, managers can understand the operation status of the power station at any time; 4. Add functions such as fault detection, emergency shutdown, automatic startup and intelligent grid connection, improve the level of automation and intelligence, and develop in the direction of unmanned power stations; 4. Add the intelligent dispatching function of multiple units, make rational use of water resources, and maximize benefits. In addition to being applied to hydropower stations, this project can also be applied to reservoir management, automatic water supply of water tanks, etc. with slight changes.
|