290 likes | 404 Views
Control Programming By Peter Woolf University of Michigan Michigan Chemical Process Dynamics and Controls Open Textbook version 1.0. Creative commons. Process from previous class. What more do we need?. • How do these controllers influence the valves and motors?
E N D
Control Programming By Peter WoolfUniversity of MichiganMichigan Chemical Process Dynamics and Controls Open Textbook version 1.0 Creative commons
Process from previous class.. What more do we need? • How do these controllers influence the valves and motors? • What is the sequence of actions? • What happens in an emergency? Specify with a control program! TC1: V5 PC1: V6, V7, V8 LC3: V1, V2, V3, SV1, M3, M4 FC3: V3, M3 FC4: SV1 FC1: V1, V2, M1 FC2: V1, V2, M2 LC1: V1, V8, V2, M1 LC2: V1, V2, M2 TC2: V7
What is a control program? • A detailed procedure identifying what every valve should be doing under each possible condition. • A computing language for expressing control relationships • Can be discrete (on/off or high/medium/low) or continuous (open % from 0% to 100%)
Control Program Languages? Control specific languages: Ladder logic, Structured text, + many proprietary versions General computing languages: Basic, C, Pascal, and less commonly C++, Java, and Python Here we will use a composite pseudo code that has most of the features without the syntax issues.
Control Programming Syntax • IF.. THEN .. ELSE • CASE • WHILE • GOTO • ALARM
open closed : starts a sub block indent defines a sub block Tset+2 ELSE IF allows a series of conditionals Tset Tset-2 time time Control Programming Syntax IF T>Tset+2: open v1 ELSE IF T<Tset-2: close v1 • IF.. THEN .. ELSE IF T>Tset+2: open v1 ELSE: close v1
Problem: Equals implies exactly equal to a controller. Thus temp=90°C is interpreted as temp=90.0000000°C at one of the sampled times which won’t happen! Solution: Use >, <, ≥, or ≤ instead of =
indent note nested indents Tset+2 Tset Tset-2 time time IF T>Tset+1: IF T>Tset+2: v2=v2+0.1 ELSE: v2=v2+0.05 ELSE IF T<Tset-1: IF T<Tset-2: v2=v2-0.1 ELSE: v2=v2-0.05 • CASE: alternate syntax that can be cleaner than many IF.. THEN statements CASE: T>Tset+2: v2=v2+0.1 T>Tset +1: v2=v2+0.05 T<Tset-1: v2=v2-0.05 T<Tset-2: v2=v2-0.1
WHILE: Creates loops for things that take an unknown number of iterations. WHILE LC1<LC1set: open v1 close v1 WHILE TC1<TC1set: heater on heater off
FUNCTION: defines a function #: defines a comment • GOTO: Breaks out of current run to go to a different configuration. WHILE time<RxnTime: IF T>Trxn: close v1 ELSE: open v1 IF OR(T>Talarm, P>Palarm): GOTO FAILSAFE FUNCTION FAILSAFE: # an emergency condition to shut down the process close v1, open v2
ALARM: Alerts the operators of a problem. Alarms may not be sufficient danger to shut down the process, but requires outside attention. Examples: • If storage tank of a reactant is low, then ALARM • If a reactor does not heat up in a normal time window, then ALARM • If no flow is detected even when the valve is open, then ALARM (might be cause for FAILSAFE if the valve is critical) • If redundant sensors disagree, then ALARM
Common functions accessed using GOTO FUNCTION INITIALIZE: # runs at the start of a process to make sure all # valves and motors are in correct position. FUNCTION PROGRAM: # main run FUNCTION FAILSAFE: # emergency mode FUNCTION SHUTDOWN: # normal shutdown procedure FUNCTION IDLE: # power down process
Common functions accessed using GOTO FUNCTION INITIALIZE: # runs at the start of a process to make sure all valves # and motors are in correct position. • Example operations: • Close all valves • Reset counters and timers • Turn off all motors • Turn off heaters
Common functions accessed using GOTO FUNCTION FAILSAFE: # emergency mode • Example operations: • Open or close valves to stop the system • Quench reactions via cooling, dilution, mixing, or other method.
What is the procedure for this process? TC1: V5 PC1: V6, V7, V8 LC3: V1, V2, V3, SV1, M3, M4 FC3: V3, M3 FC4: SV1 FC1: V1, V2, M1 FC2: V1, V2, M2 LC1: V1, V8, V2, M1 LC2: V1, V2, M2 TC2: V7
A measured amount, QS, of solvent is added to the reactor A measured amount of solid B, QB, is added to the S and blended in for 5 minutes. A total quantity of A, QA is slowly added to the reactor. The A and B react quickly producing the product polymer in an endothermic reaction. The temperature must be maintained below TR+5 degrees to prevent forming a hard polymer. The pressure of the reaction is somewhat elevated due to the partial vaporization of S. However, the tank pressure must not exceed 3 atm. The product is held in the reactor for 30 minutes after the reaction has stopped to ensure complete conversion. 5. The S is then boiled off and recovered in an overhead condenser. This recycled S is then sent to storage for reuse. 6. The product is then cooled to ambient temperature and pumped to blending. Tamb<TR<TS<TA<Tprod<TB Procedures to write: FUNCTION INITALIZE FUNCTION FAILSAFE FUNCTION PROGRAM
Counters used for measurement Note v4 is manual, so not controlled by program FUNCTION INITALIZE: turn off M1, M2, M3, M4 close v1,v2,v3,v5,v6,v7,v8, SV1 set all timers to zero set all totalizers to zero
Keep agitator going if sufficient level in tank to avoid hot spots, otherwise turn off agitator Prevent pressure increase in reactor FUNCTION FAILSAFE: turn off M1, M2, M3 IF LC3>LC3min: turn on M4 ELSE: turn off M4 close v1, v2, v3, v5, SV1 open v6, v7, v8
A measured amount, QS, of solvent is added to the reactor Open v1 to some control set point until charged FUNCTION PROGRAM # step 1 turn on M1 open v6, v7,v8 WHILE FC1tot<Qs: adjust v1 to FC1set IF LC1<LC1min: ALARM close v1 turn off M1
A measured amount, QS, of solvent is added to the reactor A measured amount of solid B, QB, is added to the S and blended in for 5 minutes. FUNCTION PROGRAM (continued) # step 2 WHILE FC4tot<QB: adjust SV1 to FC4set IF FC4<FC4min: ALARM IF LC3>LC3min: Turn on M4 close SV1 WAIT 5 minutes
3. A total quantity of A, QA is slowly added to the reactor. The A and B react quickly producing the product polymer in an endothermic reaction. The temperature must be maintained below TR+5 degrees to prevent forming a hard polymer. The pressure of the reaction is somewhat elevated due to the partial vaporization of S. However, the tank pressure must not exceed 3 atm. FUNCTION PROGRAM (continued) # step 3 WHILE TC1<TR: adjust v5 to TR turn on M2 WHILE FC2tot<QA: adjust v2 to FC2set IF LC2<LC2min: ALARM adjust v5 to TR IF OR(TC1>TR+5, PC1>3 atm): GOTO FAILSAFE
FUNCTION PROGRAM (continued) # step 3 WHILE TC1<TR: adjust v5 to TR turn on M2 WHILE FC2tot<QA: adjust v2 to FC2set IF LC2<LC2min: ALARM adjust v5 to TR IF OR(TC1>TR+5, PC1>3 atm): GOTO FAILSAFE IF PC1<PC1min: close v6, v7 ELSE: adjust v6 to PC1set adjust v7 to TC2set IF LC3>LC3max: close v2 FC2tot=QA ALARM close v2, turn off M2
4. The product is held in the reactor for 30 minutes after the reaction has stopped to ensure complete conversion. FUNCTION PROGRAM (continued) # step 4 WHILE timer<30 minutes: adjust v5 to TR IF OR(TC1>TR+5, PC1>3 atm): GOTO FAILSAFE IF PC1<PC1min: close v6, v7 ELSE: adjust v6 to PC1set adjust v7 to TC2set
5. The S is then boiled off and recovered in an overhead condenser. This recycled S is then sent to storage for reuse. • FUNCTION PROGRAM (continued) • # step 5 • open v5 • WHILE TC1<TS+1: • IF PC1>3 atm: • GOTO FAILSAFE • IF PC1<PC1min: • close v6, v7 • ELSE: • adjust v6 to PC1set • adjust v7 to TC2set
FUNCTION PROGRAM (continued) • # step 6 • close v5 • WHILE TC1>Tamb+1: • IF PC1>3 atm: • GOTO FAILSAFE • IF PC1<PC1min: • close v6, v7 • ELSE: • adjust v6 to PC1set • adjust v7 to TC2set 6. The product is then cooled to ambient temperature and pumped to blending.
FUNCTION PROGRAM (continued) • # step 6 • close v5 • WHILE TC1>Tamb+1: • IF PC1>3 atm: • GOTO FAILSAFE • IF PC1<PC1min: • close v6, v7 • ELSE: • adjust v6 to PC1set • adjust v7 to TC2set • close v7 • open v6 • turn M3 on • WHILE LC3>0: • adjust v3 to FC3set • IF LC3<LC3min: • turn M4 off • turn off M3 • close v3, v7, v8
Programming Tips • Programs can quickly get very complicated, thus it helps to write out the program in words first, then syntax later • Remember that valves and motors stay in the state you left them • Beware of conflicts between objectives and infinite loops
Take Home Messages • Control programs provide a detailed description of how a process behaves • Writing control programs requires a deep understanding of the process • Write out the program in words first, syntax second. • Break up the program into smaller steps, modules, and objects • Comment your code!