// setup
Local:2:C.Preset := preset_value; // (DINT) the preset value.
present_count := Local:2:I.PresentData; // (DINT) the preset count.
Local:2:O.CounterPreset := preset_toggle; // (BOOL)toggle the preset value to set.
inhibit_module := 4; // (INT) inhibit module.
uninhibit_module := 0; // (INT) un-inhibit module.
delay_timer1.PRE := 1000; // set the timer to 1000ms (1s).
delay_timer2.PRE := 1000; // set the timer to 1000ms (1s).
delay_timer3.PRE := 1000; // set the timer to 1000ms (1s).
delay_timer4.PRE := 1000; // set the timer to 1000ms (1s).
operator_preset_value := 1000; // operatore reset value.
if s:fs then // reset sequence on first scan.
sequence [:=] 0; // (DINT)
end_if;
// begin program
// begin startup routine.
if present_count = 0 then
if sequence = 0 then
preset_value := stored_count; // set the preset to the stored value.
if preset_value = stored_count then // if completed, move to next step.
sequence [:=] 1;
end_if;
end_if;
if sequence = 1 then
ssv(module,counter,mode,inhibit_module); // inhibit the counter module.
gsv(module,counter,mode,status_module); // (INT) check the status of the module.
if status_module = 4 then // if completed, move to next step.
sequence [:=] 2;
end_if;
end_if;
if sequence = 2 then
delay_timer1.TimerEnable [:=] 1; // start timer.
tonr(delay_timer1); // call timing function.
if delay_timer1.DN then // if completed, move to next step.
sequence [:=] 3;
end_if;
end_if;
if sequence = 3 then
ssv(module,counter,mode,uninhibit_module); // un-inhibit the counter module.
gsv(module,counter,mode,status_module); // check the status of the module.
if status_module = 0 then // if completed, move to next step.
sequence [:=] 4;
end_if;
end_if;
if sequence = 4 then
delay_timer2.TimerEnable [:=] 1; // start timer.
tonr(delay_timer2); // call timing function.
if delay_timer2.DN then // if completed, move to next step.
sequence [:=] 5;
end_if;
end_if;
if sequence = 5 then
preset_toggle [:=] 1; // toggle preset to present data.
if present_count = stored_count then
sequence [:=] 6;
end_if;
end_if;
if sequence = 6 then
error [:=] 2; // error because it should have moved to next if then.
end_if;
// begin normal running routine.
elsif present_count <> 0 then
if ((sequence = 0) or (sequence = 5) or (sequence = 6) or (sequence = 56)) then
preset_toggle [:=] 0;
if not preset_toggle then // call main routine.
sequence [:=] 100;
end_if;
end_if;
if sequence = 100 then
stored_count := present_count; // (DINT) save the count.
if operator_reset then
sequence [:=] 50; // call reset routine.
end_if;
end_if;
// begin operator reset
if sequence = 50 then
preset_value := operator_preset_value; // set the preset to the stored value.
if preset_value = operator_preset_value then // if completed, move to next step.
sequence [:=] 51;
end_if;
end_if;
if sequence = 51 then
ssv(module,counter,mode,inhibit_module); // inhibit the counter module.
gsv(module,counter,mode,status_module); // (INT) check the status of the module.
if status_module = 4 then // if completed, move to next step.
sequence [:=] 52;
end_if;
end_if;
if sequence = 52 then
delay_timer3.TimerEnable [:=] 1; // start timer.
tonr(delay_timer3); // call timing function.
if delay_timer3.DN then // if completed, move to next step.
sequence [:=] 53;
end_if;
end_if;
if sequence = 53 then
ssv(module,counter,mode,uninhibit_module); // un-inhibit the counter module.
gsv(module,counter,mode,status_module); // check the status of the module.
if status_module = 0 then // if completed, move to next step.
sequence [:=] 54;
end_if;
end_if;
if sequence = 54 then
delay_timer4.TimerEnable [:=] 1; // start timer.
tonr(delay_timer4); // call timing function.
if delay_timer4.DN then // if completed, move to next step.
sequence [:=] 55;
end_if;
end_if;
if sequence = 55 then
preset_toggle [:=] 1; // toggle preset to present data.
if present_count = operator_preset_value then
sequence [:=] 56;
end_if;
end_if;
else
error [:=] 1; // error
end_if;