Design of flow control system based on microcontroller

Publisher:数字冲浪Latest update time:2023-06-20 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Process control in industrial production is a major field of flow measurement and instrumentation applications. Flow, temperature, pressure and level are collectively referred to as the four major parameters in process control. People use these parameters to monitor and control the production process. Correct measurement and adjustment of fluid flow is the basis for ensuring safe and economical operation of the production process, improving product quality, reducing material consumption, improving economic benefits, and achieving scientific management. Flow detection and control are widely used in chemical industry, energy and power, metallurgy, petroleum and other fields.


System working principle

The working principle of the system is that the flow sensor collects the flow information and converts it into an electrical signal through the converter. The AD converter converts the analog electrical signal into a discrete signal and transmits it to the microcontroller. The microcontroller software system processes the collected information according to the preset values ​​and outputs discrete control signals. DA converters convert discrete control signals into analog electrical power. The action of the valve is controlled by simulating electricity to adjust the flow and achieve precise control of the flow.


Hardware composition

This system is mainly composed of water pumps, flow sensors, electric valves and MCS-51 microcontroller control systems, as well as liquid pipelines, control lines, and monitoring lines.

The system structure block diagram is as follows:

Design of flow control system based on microcontroller

Flow refers to the amount of material passing through a certain section of the pipeline per unit time. The task of this control system is to control the amount of material passing through a certain pipeline section, that is, the flow rate of the viscosity reducer. This system is controlled by a single-chip microcomputer and collects flow information through a flow meter and transmits it to the single-chip microcomputer. The single-chip microcomputer analyzes the preset values ​​and system software, sends out corresponding control signals, and drives the regulating valve to act, thereby determining the ratio and consumption of the viscosity reducing agent and realizing the automation of the production process.

The system hardware structure diagram is shown in the figure:

Design of flow control system based on microcontroller

Among them, the electromagnetic flowmeter is used as a flow sensor to collect flow information, which is amplified by an amplifier and sent to the AD converter. The AD converter converts continuous analog quantities into discrete digital quantities that the microcontroller can accept. After the microcontroller receives the flow signal, under the action of the control system software, it issues corresponding execution commands to the actuator - the stepper motor. The stepper motor drives the valve action to control the fluid flow. software design


Software design ideas

The software design of this control system can be divided into three parts:

1. Main program part: This part completes memory partitioning, data definition, system initialization, etc., and calls each subroutine to complete the main control functions.

2. Flow control program: Use the PID control algorithm to write the corresponding flow control subroutine to control the flow and meet the expected control requirements;

3. Each subroutine: Each subroutine completes the specific implementation method, mainly including: set value input, digital tube display, stepper motor control, AD conversion interrupt, T0 timer interrupt, sampling interrupt, etc. The software flow chart is as follows

Design of flow control system based on microcontroller

Main program design

The main program part mainly completes memory allocation, system initialization and overall system control, etc., and realizes the overall design function of the software by calling each subprogram segment.

Initialization: The function of the system initialization program is to initialize the 8155 and 89C51, so that the D/A output is 0, the stepper motor is in a stopped state, the flag bits and working units in the RAM are set to the initial state, and the prompt CPUREADY is written to the buffer. device. The function of the update display subroutine is to convert the contents of the display buffer into segment data and output them to 8155. The display data buffers of displays 0 to 12 are units 73H to 7FH respectively. When the system is in shutdown state, displays 0 to 4 display parameters, and displays 5 to 7 display parameter addresses, so 73H to 77H are used as data buffers, and 78H to 7AH are used as address buffers. In the running state, 73H to 77H are used as instantaneous traffic. Buffer, 78H~7FH are used as accumulated flow buffer. The flow of the initialization program is shown in the figure:

Design of flow control system based on microcontroller



flow control subroutine

On the basis of the flow test, the flow set value is compared with the instantaneous flow obtained by the actual test to calculate the error. The digital PID adjustment algorithm is used to calculate the variable Uio output to AD0809. The calculation formula of the incremental PID control algorithm is:

Design of flow control system based on microcontroller

In the formula: ei is the difference between the actual measured flow rate and the set value;

Design of flow control system based on microcontroller

P is the proportional coefficient; I is the integral coefficient; D is the differential coefficient; the expression of the output control variable is:

Design of flow control system based on microcontroller

The entry parameters of the program: deviation ek, ek-1, ek-2, measured value y, given value r. These five parameters are all 3-byte floating point numbers, and they are stored in RAM units respectively. The low byte stores the order and sign of the floating point number, where the sign is stored in the highest bit, and the order is stored in the other 7 bits in complement form. The mantissa is stored in the other 2 bytes in the form of the original code.

interrupt service routine

Set value input program

This program stores the 4-digit BCD code in the 30H~33H units of the 89C51 on-chip RAM in order of thousands, hundreds, and tens. The high 4 bits of each address unit are 0, and the low 4 bits are the BCD code. The program code is as follows:

RDS: MOV R0, #30H; initialization, storing the first address of the unit

MOV R2, #7FH; P1 port high 4 position control word and low 4 position input method

MOV R3, #04H; read 4 BCD codes MOV A, R2

LOOP: MOV P1, A; P1 port sends control word and low 4 position input mode

MOV A, P1; read as BCD code ANL A,

#0FH; shield the high 4 bits

MOV @R0,A; send to storage unit

INC R0; points to the next storage unit

MOV A, R2; prepare the control of the next dial and set it to 0

RR A;

MOV R2,A;

DJNZ R3, LOOP; return if not finished

RET; end of reading


A/D interrupt subroutine

The A/D interrupt subroutine flow chart is as follows:

Design of flow control system based on microcontroller

The program code is as follows:

INT0: PUSH ACC; protect the scene

PUSH DPH

PUSH DPL

PUSH PSW

SETB PSW.3; Select working register area 1

MOV DPTR, #0DF01H; read 8155A port data

MOVX A, @DPTR MOV R2, A

ANL A, #0F0H; Shield the lower 4 bits JNZ ND5;

MOV A, R2

JNB 02H, D51; determine whether to sample zero signal

MOV C, ACC.0;

MOV 30H, C MOV C, ACC.7

MOV 37H, C AJMP D14

D51: MOV C, ACC.0; Ten thousand digits and flag bits → load signal buffer

MOV 48H, C

MOV C,ACC.7

MOV 4FH, C

AJMP D14

ND5: MOV A, R2; determine whether to read the thousands digit

JNB ACC.7, ND4

JNB 02H, D41; determine whether to sample zero signal

ANL A, #0FH; thousands bit → zero signal buffer

SWAP A

MOV 25H,A

AJMP D14

D41: ANL A, #0FH

SWAP A

MOV 28H, A

AJMP D14

ND4: JNB ACC.6, ND3; determine whether to read out the hundreds digit

JNB 02H, D31; determine whether to sample zero signal

MOV R1, #25H; Hundreds bit→zero signal buffer

ANL A, #0FH

XCHP A,@R1

AJMP D14

D31: MOV R1, #28H

ANL A, #0FH

XCHD A,@R1

AJMP D14

ND3: JNB ACC.5, ND2; determine whether to read the tens digit

JNB 02H, D21; determine whether to sample the signal

ANL A, #0FH; tens bit → zero signal buffer

SWAP A

MOV 24H,A

AJMP D14

D21: ANL A, #0FH

SWAP A MOV 24H, A

AJMP D14

ND2: JNB 02H, D11; determine whether to sample zero signal

ANL A, #0FH; ones digit → zero signal buffer

MOV R, #24H

XCHD A, @R1 CLR 02H

MOV DPTR, #0DFF3H; Start A/D conversion

MOV A, #30H

MOVX @DPTR,

A ADS1: SETB P1.6

NOP

NOP

CLR P1.6

AJMP D14

D11: ANL A, #0FH

MOV R1, #27H

XCHD A,@R1

MOV 2AH, 24H; Sampling data is sent to the processing buffer

MOV 2BH, 25H

MOV 2CH, 26H

MOV 2DH, 27H

MOV 2EH, 28H

MOV 2FH, 29H

SETB 03H; Set the A/D sampling end flag once

D14: POP PSW; restore the scene

POP DPL

POP DPH

POP ACC

RETI


timer interrupt subroutine

The timer T0 interrupt program flow chart is shown in the figure below.

Design of flow control system based on microcontroller

The program code is as follows

PIT0: PUSH PSW; protect the scene

PUSHACC

PUSH DPH

PUSH DPL

JNB 00H, T01; Is sampling allowed?

DJNZ 10H, T02; the sampling period counter decreases by 1, if it is not 1, turn to T02

DJNZ 11H, T02

MOV 10H, #0A0H; restore the initial value of the sampling period counter

MOV 11H, #0FH

SETB 0FH

CLR 0DH

CLR P3.4

MOV DPTR, #0DFF3H; Sample zero point

MOV A, #00H

MOVX @DPTR, A

SETB 04H

SETB 04H

T02: JB 01H, T05

T01 SETB P1.7

NOP

CLR P1.7

T05: CLR P1.6

DJNZ 16H, T06; Decrement the pulse period counter by 1 for debugging

CPL P1.4; Make P1.4 generate square wave

MOV 16H, 17H

T06: POP DPL; restore the scene

POP DPH

POP ACC

POP PSW

ERTI


Digital tube display subroutine

The program flow chart is as follows:

15

There are four hexadecimal digits in units 20H and 21H of the internal RAM of the microcontroller (the two high digits in 20H). The following is a program to display them from left to right. The program code is as follows:

ORG 2000H

SDIAPLAY: MOV A, 20H; 20H will give you A for free

ANL A, #0F0H; intercept the high 4 bits

MOV P1, A; send 1#MC14495

MOV A, 20H; get A if you hit the 20H number

SWAP A; the lower 4 bits are sent to the higher 4 bits

ANL A, #0F0H; remove the lower 4 bits

INC A;A1A0 points to 2#MC14495

MOV P1, A; send 2#MC14495

MOV A, 21H; 21H will give you A if you hit the number

ANL A, #0F0H; intercept the high 4 bits

ADD A, #02H; A1A0 points to 3#MC14495

MOV P1, A; send 3#MC14495

MOV A, 21H; 21H will give you A if you hit the number

SWAP A; the lower 4 bits are sent to the higher 4 bits

ANL A, #0F0H; remove the lower 4 bits

ADD A, #03; A1A0 points to 4#MC14495

[1] [2]
Reference address:Design of flow control system based on microcontroller

Previous article:Using microcontroller and FPGA to realize the design of delay-adjustable module in the system
Next article:Running on P89V51RD2 microcontroller based on μC/OS-II operating system

Latest Microcontroller 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号