Skip to content

Commit

Permalink
Merge pull request #99 from jyin999/IMG401
Browse files Browse the repository at this point in the history
Img401
  • Loading branch information
jyin999 authored Jun 30, 2022
2 parents b2cf585 + 7d7b7ce commit c9fae6c
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 45 deletions.
3 changes: 3 additions & 0 deletions L2SIVacuum/L2SIVacuum.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@
<Compile Include="POUs\Functions\Gauges\FB_CCM501.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Functions\Gauges\FB_IMG401.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Functions\Gauges\FB_MKS909.TcPOU">
<SubType>Code</SubType>
</Compile>
Expand Down
62 changes: 31 additions & 31 deletions L2SIVacuum/L2SIVacuum.tmc

Large diffs are not rendered by default.

Empty file removed L2SIVacuum/LineIDs.dbg
Empty file.
144 changes: 130 additions & 14 deletions L2SIVacuum/POUs/Functions/Gauges/FB_CCM501.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ VAR_IN_OUT
END_VAR
VAR_INPUT
PG : ST_VG;
// bEP : BOOL :=FALSE; // Set to True if This Gauge is connected to EP BOX and not EL Terminals
tRecoverDelay:TIME:=T#600S; (*Delay Time after the first cycle to start the device. Default is 600S*)
END_VAR
VAR_OUTPUT
{attribute 'pytmc' := '
Expand All @@ -20,53 +22,73 @@ END_VAR
VAR
rV : REAL;
GaugeTurnOnTmr : TON;
iTermBits: UINT := 32767 ; // The terminal's maximum value in bits
tStartupTimer:TON;
iTermBits: UINT := 30518 ; // The terminal's maximum value in bits
(*IOs to be linked*)
/// Controls and I/Os
i_iPRESS_R AT %I* :INT; // input Pressure // Link to analog Input
q_xHV_DIS AT %Q* : BOOL; // Enable High Voltage when True // 'TcLinkTo' (EP2624) ^Output
// only for EL and ES terminal
i_xHV_ON AT %I* : BOOL; // True when High Voltage is on // 'TcLinkTo' (EL1124) ^Input
i_xDisc_Active AT %I* : BOOL;// Discharge Current Active // 'TcLinkTo' (EL1124) ^Input
// i_xDisc_Active AT %I* : BOOL;// Discharge Current Active // 'TcLinkTo' (EL1124) ^Input
binit:BOOL:=TRUE;
END_VAR
VAR CONSTANT
// Ranges has to match the configurator software
// Ranges 1.8 to 8.7 Vdc, 0.8V/decade analog output - Torr
vBase : REAL := 1.25;
vDisconnected : REAL:= 1.8;
vTorr : REAL := 12.875;
vGaugeOff: REAL := 9.8;
vGaugeOff: REAL := 10.0;
//vNoDischarge: REAL := 9.3;
MinPressure: REAL := 1E-10;
rMinPressure: REAL := 1E-10;
cDefaultPressure : REAL := 0;
rDeadband : REAL :=0.3;
rDeadband : REAL := 1.0;
END_VAR
VAR PERSISTENT
bWasOn : BOOL;
bAutoRecover:BOOL;
bAutoRecoverWrite:BOOL;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[(* 500 Logarithmic Output Conversion, factory default configuration *)
If (iTermBits=0) THEN iTermBits := 32767;END_IF
<ST><![CDATA[
(*Startup time*)
IF (bInit) THEN
tStartupTimer.IN:=TRUE;
bInit :=FALSE;
END_IF
tStartupTimer(PT:=T#3S);
If (iTermBits=0) THEN iTermBits := 30518;END_IF
rV := 10*INT_TO_REAL(IG.i_iPRESS_R)/iTermBits;
(* Set Guage State based on the Analog voltage*)
IF rV < vDisconnected THEN
(* Set Guage State based on the Analog voltage*)
IF rV <= vDisconnected AND IG.i_xHV_ON and IG.q_xHV_DIS THEN
IG.eState := ValidLo;
IG.rPRESS := rMinPressure;
ELSIF rV <= vDisconnected AND Not IG.i_xHV_ON and IG.q_xHV_DIS THEN
IG.eState := GaugeDisconnected;
IG.rPRESS := cDefaultPressure;
ELSIF rV >= vDisconnected AND rV < (vGaugeOff -rDeadband) THEN
ELSIF rV > vDisconnected AND rV < (vGaugeOff -rDeadband) AND IG.i_xHV_ON and IG.q_xHV_DIS THEN
IG.eState := Valid;
IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV*vBase)- vTorr)));
ELSIF rV >= (vGaugeOff -rDeadband) THEN
IG.eState := Off;
//IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
IG.rPRESS := cDefaultPressure;
ELSE
IG.eState := OoR;
//IG.rPRESS := LREAL_TO_REAL(EXPT(10,((rV-vBase)/vSlope+LOG(pBase))));
IG.rPRESS := cDefaultPressure;
END_IF
(* Ion Gauge Protection Functions *)
(* If the PG pressure is greater than the VG.PRO_SP then the gauge is disabled *)
(* If the PG pressure is less than the VG.PRO_SP then the gauge is enabled *)
Expand All @@ -87,6 +109,7 @@ ELSE
IG.xILKOk := FALSE;
END_IF
(* Pressure gauge OK checks *)
GaugeTurnOnTmr(IN:=IG.q_xHV_DIS, PT:=T#10S, Q=>IG.xTurnOnTime);
Expand All @@ -104,6 +127,11 @@ ACT_Logger();
IO();
(*Load or save the persistent variables*)
ACT_Persistent();
(*Run Auto Recovery*)
ACT_Recover();
]]></ST>
</Implementation>
<Action Name="ACT_Logger" Id="{99961f85-7dce-4ed0-bee5-af963152edee}">
Expand Down Expand Up @@ -150,6 +178,7 @@ END_IF
<Action Name="ACT_Persistent" Id="{d61b101a-8e7b-490f-9c85-1ba602630ca3}">
<Implementation>
<ST><![CDATA[(*On first PLC pass, load the persistent value into the structrue variable*)
IF (SUPER^.bRestorePersistentData) THEN
SUPER^.bRestorePersistentData := FALSE;
IF ( rVAC_SP <> 0) THEN
Expand All @@ -161,6 +190,9 @@ IF (SUPER^.bRestorePersistentData) THEN
IF ( rHYS_PR <> 0) THEN
IG.rHYS_PR := rHYS_PR;
END_IF;
IF ( bAutoRecoverWrite) THEN
IG.xAutoOn := bAutoRecover;
END_IF;
END_IF
(*Check if a new value has been written in the structure variable copy it to the persistent variable*)
IF NOT (IG.rVAC_SP = rVAC_SP) THEN
Expand All @@ -173,15 +205,39 @@ END_IF;
IF NOT (IG.rHYS_PR = rHYS_PR) THEN
rHYS_PR:= IG.rHYS_PR;
END_IF;
IF NOT(bAutoRecoverWrite) OR NOT (bAutoRecover = IG.xAutoOn) THEN
bAutoRecover := IG.xAutoOn;
bAutoRecoverWrite := TRUE;
END_IF;
stateTimer(PT:=T#10S);
IF (stateTimer.Q) THEN
bWasOn := (IG.eState >=Valid );
stateTimer.IN := FALSE;
fbWritePersistentData(NETID:='', PORT:=851, START:=TRUE, TMOUT:=T#1s );
END_IF;]]></ST>
</Implementation>
</Action>
<Action Name="ACT_Recover" Id="{e533aa39-f7e4-475e-a226-8e757c2d178a}">
<Implementation>
<ST><![CDATA[fbGetCurTaskIdx();
IF (TwinCAT_SystemInfoVarList._TaskInfo[fbGetCurTaskIdx.index].FirstCycle) THEN
tRecover.IN := TRUE;
END_IF
tRecover(IN:= , PT:=tRecoverDelay);
IF NOT(bAutoRecoverWrite) OR (tRecover.Q AND bAutoRecover ) THEN
This^.M_Recover();
tRecover.IN := FALSE;
END_IF]]></ST>
</Implementation>
</Action>
<Action Name="IO" Id="{d8491859-09d0-4a11-84b1-64e10f403b2b}">
<Implementation>
<ST><![CDATA[(*soft link inputs*)
IG.i_iPRESS_R:= i_iPRESS_R;
IG.i_xHV_ON:= i_xHV_ON;
IG.i_xDisc_Active:=i_xDisc_Active;
//IG.i_xDisc_Active:=i_xDisc_Active;
(*soft link outputs*)
q_xHV_DIS := IG.q_xHV_DIS;
Expand All @@ -199,6 +255,17 @@ END_VAR
this^.IG.xHV_SW:= enable;]]></ST>
</Implementation>
</Method>
<Method Name="M_Recover" Id="{f68e6453-2e78-43b5-a7e3-ff49d68f47d8}">
<Declaration><![CDATA[METHOD M_Recover : BOOL
VAR_INPUT
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[This^.M_HVE(This^.bWasOn);
M_Recover := bWasOn;
IF (bWasOn) THEN fbLogger(sMsg:='Auto Recovery Initiated.', eSevr:=TcEventSeverity.Info); END_IF;]]></ST>
</Implementation>
</Method>
<Method Name="M_SetBits" Id="{72c14520-2c59-468a-859d-9b3fd8e0ae82}">
<Declaration><![CDATA[METHOD M_SetBits : BOOL
VAR_INPUT
Expand All @@ -209,5 +276,54 @@ END_VAR
<ST><![CDATA[This^.iTermBits := TermBits;]]></ST>
</Implementation>
</Method>
<LineIds Name="FB_CCM501">
<LineId Id="3" Count="0" />
<LineId Id="218" Count="4" />
<LineId Id="214" Count="3" />
<LineId Id="4" Count="3" />
<LineId Id="105" Count="0" />
<LineId Id="128" Count="0" />
<LineId Id="106" Count="0" />
<LineId Id="193" Count="2" />
<LineId Id="199" Count="14" />
<LineId Id="24" Count="16" />
<LineId Id="229" Count="0" />
<LineId Id="42" Count="2" />
<LineId Id="228" Count="0" />
<LineId Id="45" Count="17" />
<LineId Id="122" Count="0" />
<LineId Id="121" Count="0" />
<LineId Id="2" Count="0" />
<LineId Id="225" Count="1" />
<LineId Id="224" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.ACT_Logger">
<LineId Id="2" Count="35" />
<LineId Id="1" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.ACT_Persistent">
<LineId Id="2" Count="0" />
<LineId Id="28" Count="37" />
<LineId Id="26" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.ACT_Recover">
<LineId Id="2" Count="7" />
<LineId Id="1" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.IO">
<LineId Id="2" Count="6" />
<LineId Id="1" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.M_HVE">
<LineId Id="3" Count="0" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.M_Recover">
<LineId Id="6" Count="1" />
<LineId Id="5" Count="0" />
</LineIds>
<LineIds Name="FB_CCM501.M_SetBits">
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
Loading

0 comments on commit c9fae6c

Please sign in to comment.