einnh
Lifetime Supporting Member
What would be the best way to toggle a bit on then back off in ST? two OSRI's?
// power cycle reset.
if Local:2:I.PresentData = 0 then
Local:2:C.Preset := current_count; // set preset value to last known value.
storage.0 [:=] 1;
if storage.0 then
Local:2:O.CounterPreset [:=] 1; // reset value to preset.
end_if;
elsif Local:2:I.PresentData <> 0 then
storage.1 [:=] 1;
if storage.1 then
Local:2:O.CounterPreset [:=] 0; // reset value to preset.
end_if;
Local:2:C.Preset := 1000;
current_count := Local:2:I.PresentData; // store the count to a program variable.
else
// nothing.
end_if;
ResetBit:=False;
if RestBitCondition then ResetBit:=True;
// power cycle reset.
if Local:2:I.PresentData = 0 then
Local:2:C.Preset := current_count; // set preset value to last known value.
Local:2:O.CounterPreset [:=] 1; // reset value to preset.
elsif Local:2:I.PresentData <> 0 then
Local:2:O.CounterPreset [:=] 0;
current_count := Local:2:I.PresentData; // store the count to a program variable.
else
// nothing.
end_if;
I'd be tempted to try it like this (basically using the PresentData value to trigger things):
The idea being is that the first scan through the preset value would be updated. The second scan through the PresentData would be non-zero and would thus reset the CounterPreset bit.Code:// power cycle reset. if Local:2:I.PresentData = 0 then Local:2:C.Preset := current_count; // set preset value to last known value. Local:2:O.CounterPreset [:=] 1; // reset value to preset. elsif Local:2:I.PresentData <> 0 then Local:2:O.CounterPreset [:=] 0; current_count := Local:2:I.PresentData; // store the count to a program variable. else // nothing. end_if;
// begin program.
// power cycle reset.
if Local:2:I.PresentData = 0 then // first start after power cycle.
Local:2:C.Preset := current_count; // set preset value to last known value.
Local:2:O.CounterPreset [:=] 1; // toggle reset.
elsif Local:2:I.PresentData <> 0 then // normal operation.
if not storage.0 then
Local:2:O.CounterPreset := 0; // toggle reset.
storage.0 [:=] 1; // set storage bit.
end_if;
if storage.0 then
Local:2:C.Preset := 1000;
current_count := Local:2:I.PresentData; // store the count to a program variable.
end_if;
else
// nothing.
end_if;
//end program.
// power cycle reset.
// placed outside separately but could easily be combined with lower if statement
if (hmi_change_value_command) then
current_count := hmi_new_value;
end_if;
if ((Local:2:I.PresentData = 0) OR (hmi_change_value_command)) then
Local:2:C.Preset := current_count; // set preset value to last known value.
Local:2:O.CounterPreset [:=] 1; // reset value to preset.
hmi_change_value_command [:=] 0; // turn the HMI command back off
elsif Local:2:I.PresentData <> 0 then
Local:2:O.CounterPreset [:=] 0;
current_count := Local:2:I.PresentData; // store the count to a program variable.
else
// nothing.
end_if;
IF(EDGEPOS(MyBit)) THEN
//Code
END_IF
MyRTRIG.CLK:= MyBit;
MyRTRIG();
IF(MyRTRIG.Q) THEN
//Code
END_IF
IF(MyBit AND NOT(zMyBit)) THEN
//Code
END_IF
zMyBit:= MyBit;