A method for judging timed on/off based on table lookup

Publisher:码农闲散人Latest update time:2010-09-24 Source: 单片机与嵌入式系统应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

Timed on/off is a common problem in daily, weekly, monthly, etc. timed on/off. For example, in the booster pump room of a residential area, when the water consumption is low (such as late at night to early morning), the booster system is turned off on time, and water is only supplied by the pipe network; when the water consumption is high, the booster system is turned on on time to supply water at a constant pressure. In order to realize timed on/off, the system needs to be connected to a real-time clock chip (such as DSl302) to obtain real-time time.

For scheduled power on and off within a certain period (such as every day), it is necessary to solve the carry problem in real time. Taking hours and minutes as an example, tomorrow's 1:00 is farther away from the current time than today's 23:59, because the former is actually equivalent to 25:00. Therefore, if you want to judge the size of hours and minutes, you need to compare the date at the same time, which increases the difficulty of judgment. This article mainly takes the scheduled power on and off within 24 hours as an example to explain the method of solving the problem of scheduled power on and off judgment by looking up the table. This method only needs to compare hours and minutes.

1 Scheduled power on and off once within 24 hours

There are two cases for analysis. One case is that the power-on time (i.e., the time when the power-on starts) is greater than the power-off time (i.e., the time when the power-off starts). For example, the power-on time is 05:00 and the power-off time is 02:00, as shown in Figure 1(a). The other case is that the power-on time is less than the power-off time. For example, the power-on time is 04:00 and the power-off time is 23:00, as shown in Figure 1(b). The shaded parts in the figure are all the power-off time periods.

As can be seen from Figure 1(a), if the real-time time is greater than or less than both the power-on time and the power-off time, the system is powered on; if the real-time time is greater than the power-off time and less than the power-on time, the system is powered off.

As can be seen from Figure 1(b), if the real-time time is greater than or less than both the startup time and shutdown time, the system will be shut down; if the real-time time is greater than the shutdown time and less than the startup time, the system will be turned on. The result is exactly the opposite of Figure 1(a).

In fact, whether the system needs to be powered on is determined by the comparison results of the following three times: real time and power-on time, real time and power-off time, power-on time and power-off time. There are 8 possible combinations of these three comparison results. Based on the above analysis, Table 1 can be obtained, and 0 and 1 are used to represent the logical relationship between them.

After analysis, Table 1 has irrelevant items (x), and the comparison results corresponding to serial numbers 2 and 5 will not appear. According to Table 1, a program table suitable for different single-chip microcomputers can be compiled (such as MCS51, Table 1: db O, 1, 55h, O, 1, 55h, 0, 1). The results corresponding to the irrelevant items can be represented by specific values ​​(such as 55h) to indicate errors, which are handled by the upper-level application. When compiling a program, you only need to combine the results of comparing the three times to get the results by looking up the table. The comparison results of the power-on time and the power-off time can be determined and saved in advance when setting. In actual operation, you only need to compare the real-time time with the power-on time, and the real-time time with the power-off time.

2 Multiple scheduled power on/off and other situations within 24 hours

As shown in Figure 2, 4 groups of power on and off times are set within 24 hours. The shaded part in the figure is the shutdown time period. According to different power on and off time groups, the table is looked up according to Table 1 according to the above method, and all the results are ANDed to determine whether to start or shut down. The system can only be turned on when the real time meets all the power on time conditions.

When the computer is turned on within a non-cyclic fixed time period (such as 2009-10-1 06:00 to 2009-10-8 23:00), it is actually only necessary to determine whether the real time is within the time period. In this case, the shutdown time is assumed to be greater than the startup time. The application in the reference is of this kind.

When a fixed period is used as a cycle (such as weekly, monthly, etc.), it is only necessary to change the algorithm when the three times are compared with each other. The system output can still be obtained by looking up the table based on the comparison results of the three.

Conclusion

This paper proposes a method to solve the problem of timing on/off judgment within a certain cycle in a single-chip microcomputer application system by using a table lookup method. The real-time, on-time, and off-time are compared with each other, and the table is looked up based on the comparison results to determine the control result. This method is simple and practical, and can also be used in other embedded systems or control systems.

Reference address:A method for judging timed on/off based on table lookup

Previous article:Function of the output transformer of the full-bridge inverter UPS
Next article:Design and implementation of a simple infrared remote control password lock

Recommended ReadingLatest update time:2024-11-16 16:33

PIC16F877A microcontroller (interrupt and timer Timer0)
1 Basic principles 2 Implementation Code The code is mainly written based on FIGURE 5-1 and the logic block diagram of the interrupt, so that the code is highly readable and easy to understand. However, some registers may not be explained in the block diagram, so you also need to carefully read the official docu
[Microcontroller]
PIC16F877A microcontroller (interrupt and timer Timer0)
Issues to be aware of when using PIC microcontroller TIMER1
1. When TMR1H and TMR1L are initialized, the prescaler will be automatically cleared. 2. When the register is written to TMR1H and TMR1L, the prescaler will be cleared. When TMR1 is in operation, writing to TMR1H or TMR1L value may write undesired values. 3. When TMR1 works in asynchronous counting mode, it cannot b
[Microcontroller]
Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号