|
Post by Admin on Jul 15, 2019 15:02:21 GMT
This is a simple first-order tank simulator. The configuration input is the time the tank takes to fill or empty at 100% flow rate. The inlet and outlet are 0 to 100% of full flow rate. The actual flow rate and tank size is irrelevant to this model. This model is released to the public domain. Use it as you wish. No warranties expressed or implied. FUNCTION_BLOCK Tank_Sim VAR_INPUT InletFlow : REAL; // zero to 100% of full flow rate OutletFlow : REAL; // zero to 100% of full flow rate TimeToFill_CI : TIME := T#10S; //Time it takes to fill the tank at full flow rate END_VAR VAR_OUTPUT TankLevel : REAL :=0; //percentage full 0=empty, 100=full END_VAR VAR PreviousTime : LTIME := LTIME(); DeltaTime : LTIME; END_VAR
DeltaTime := LTIME() - PreviousTime; PreviousTime := LTIME(); //calc time since the last process cycle TankLevel := TankLevel + (InletFlow - OutletFlow) * TO_REAL(TO_LREAL(DeltaTime)/TO_LREAL(TimeToFill_CI)/1E6); //integrate the flows IF TankLevel > 100 THEN TankLevel := 100; ELSIF TankLevel < 0 THEN TankLevel := 0; END_IF //overflow and underflow
|
|