The AT89C55WD with watchdog function introduced by ATMEL Company has 20K program memory, which is an advanced product in 805 1 series. Its watchdog function can greatly improve the stability of the product, and the large-capacity internal program memory can accommodate software with rich functions. This paper briefly introduces the design and implementation method of developing a flow integral controller with A5 1 as the development tool and AT89C55WD as the core.
I. Overall Layout of Flow Integrated Controller
The flow totalizer has five input channels: flow L, pressure compensation P, thermocouple TC, thermal resistance Pt 100 and frequency F. Controlled by the channel switch. The basic working principle of the flow totalizer is that all kinds of analog signals are sent to the A/D converter through the input signal circuit, and converted into digital signals (frequency signals are directly counted by the microprocessor). The microprocessor displays and controls the output after calculation and comparison according to the sampling results and digital settings.
(Figure 1) Principle block diagram
(Figure 2) Overall functional diagram
Second, the system circuit composition
The circuit of flow integration controller is composed of single chip microcomputer AT89C55WD, 5+8 LED display circuit, channel switch TC4052 circuit, A/D acquisition circuit, data storage circuit AT24C04, power management circuit IMP708, transmission output circuit TLC465, AD694, switch output circuit, keyboard, power supply and feed output circuit, etc. Let's briefly introduce each component.
1.AT89C55WD single chip microcomputer and its circuit composition
AT89C55WD drives the 3D 1 display driver chip HD7279 through P0.0~P0.3, and then drives the 5-bit digital tube to display the instantaneous flow PV value; Drive 5 buttons and 8 LED indicators at the same time. Drive the 3D2 display driver chip HD7279 through P0.4~P0.7, and then drive the 8-bit digital tube to display the cumulative flow value SV. The CS5523 A/D converter is controlled by P 1.0~P 1.3 to collect data. The collected data is processed by a series of operations, as shown in Figure 3. The instantaneous value and accumulated value are displayed through the display window respectively, and the corresponding indicator lights up. Due to sudden power failure, data will be lost. In order to avoid data loss, we use IMP708 chip for power failure protection. When the voltage drops to the threshold of 708 (for example, 4.6 volts), we will store the relevant data in AT24C04, and then reload the data after the power is restored. In addition, keyboard data, flow integral values and the like are also stored in AT24C04.
2. Display and keyboard circuit
The totalizer is displayed by LED digital tube. Two four-way LG 364 1ag * * negative digital tubes are used to display instantaneous flow values, 1 four-way LG564 1AG and one lg561* *+0 * * negative digital tubes are used to display cumulative flow values. Its driver chip is 2 HD7279, which not only solves the drive of 13 digital tube, but also solves the drive of 5 buttons and 8 indicator lights. HD7279 is an LED digital tube and keyboard interface chip: it can drive 8-bit LED digital tube and 64-key keyboard, SPI interface, and a few peripheral components. It is convenient and practical to interface with single chip microcomputer through SPI serial interface.
3. Analog-digital acquisition circuit
A/D acquisition circuit is mainly composed of 16-bit CS5523. The chip is SPI serial interface with chip selection terminal. The input of four channels is controlled by TC4052.
4. Watchdog circuit
AT89C55WD is compatible with MCS-5 1 and can electrically erase the kernel 1000 times. Its voltage, current and power consumption are relatively small, 20K erasable flash memory and hardware watchdog timer.
Watchdog timer is a method to recover from system software crash. WDT consists of a 13 bit counter and a watchdog reset special function register (WDT RSSFR), which is closed by default when the system is reset. To make WDT effective, users must write 0 1EH and 0E 1H into WDT RSSFR of 0A6H unit in turn. When WDT is active, the counter is increased by 1 every machine cycle. There is no other way to disable WDT except hardware or WDT overflow reset. When the counter overflows, WDT generates a reset high-level pulse at RST pin.
In order to keep WDT valid, it is necessary to write 0 1EH and 0E 1H to WDTRST at regular intervals to avoid WDT overflow. When the 13-bit counter of WDT counts to 8191(1fffh), the counter overflows, causing the device to reset. This means that the user must reset the WDT at least once every 8 19 1 machine cycle. To reset WDT, 0 1EH and 0E 1H must be written into the write-only register WDTRST. When the WDT overflows, a reset high-level pulse is generated at the RST pin, the duration is 98×TOSC, and TOSC= 1/FOSC. In order to make full use of WDT, WDTRST should be written once every certain period when it needs to be reset to prevent WDT overflow.
Here's a routine:
Put the watchdog timer in T 1, and it takes 50ms to interrupt each time. When used as a counter, 1 is added to r 1 9 after counting1sec. When the main program or subroutine does not clear R 19 within 10 seconds, it means that the program may be "off-track". At this time, the watchdog is enabled, and AT89C55WD is reset, starting from address 0000h.
R 19 data13h;
R23 data17h; Ms counter
t 1 int:; Timer (timer)
MOV TH 1,#4CH
MOV TL 1, # 00H Calculate the initial value of full reloading (about 50ms).
INC R23(20 times * 50ms) =1000ms =1s.
MOV A,R23
CJNE A,#20,t 1 int _ 0 1; 1 above downward
INC r 19; Used for watchdog timing
MOV A,R 19
CLR C
SUBB A,# 10
JC t 1 int _ 0 1; 10 seconds to stop and reset.
CLR EA
MOV WDTRST,# 0 1EH; WDT enabled, 13 bits
MOV WDTRST,# 0e 1H; TOSC= 1/FOSC。
JMP element
T 1int_0 1: RETI
Third, the system software part
The system software is written in A5 1 assembly language.
1. programming language
This system adopts C5 1 compiler V7.0 A5 1 of Keil company, which is a repositioning macro assembler with general feature machine usage, and is well compatible with MASM5 1 macro assembler of INTEL company, which supports modular programming and can easily interface with high-level languages.
2. Mathematical model and program design
The mathematical model of the flow totalizer is very complicated, involving dozens of formulas, but the basic formula is:
(1) mass flow (2) standard volume flow
(3) density operation formula
Where: ρ-working condition density, ρ20- standard temperature and pressure density, t0-273. 15℃, t- temperature compensation input signal (unit:℃), p- pressure compensation input signal, P0- design pressure (standard temperature and pressure = 0.1kloc-0
(Figure 3) Basic mathematical model and program branch structure
3. Working process
Because of the complexity of the whole system, it is difficult to express the running process of the whole software clearly with several flowcharts. Here is a rough flow chart to express the simple workflow of the flow totalizer. See Figure 4 for details.
(Figure 4) Program Flow Chart
Four. procedure
The whole source program (including comments) is 265KB, and the tables of saturated steam, superheated steam, Pt 100, K-scale and E-scale thermocouples, which occupy a large space, are also placed in the program memory. The compiled hexadecimal file is about 16KB, which only uses four-fifths of 20KB program memory, and the remaining 4K can be reserved for adding new functions in the future. Conclusion In the process of developing the flow totalizer, A5 1 was used to develop the software, AT24C04 was used as the memory of control parameters and totalizer values, and watchdog was set up, so the phenomenon of program "deviation" almost did not exist. Coupled with the power management chip IMP807, there is no data loss caused by power failure.
The flow integrated controller we developed is highly intelligent, such as:
When the temperature t or pressure p compensation is abnormal (except without temperature pressure compensation) and the pressure difference Δ p is greater than 0, the temperature or pressure indicator lamp flashes, indicating that the temperature or pressure compensation is abnormal. The density ρ takes the latest value. If the density value is not maintained after the power failure, the density value is ρ= 1 when the power is re-energized, and there will be a flow L if there is a pressure difference Δ p, but the flow value is approximate at this time. After troubleshooting, the flow integral value returned to normal.
/Article/mcuzh/200604/4 105 . html