FUNCTION hourly_average : UINT
VAR_INPUT
product_oneshot : BOOLEAN;
VAR_END;
VAR
stdNow : SysTimeDate;
current_wMinute : UINT;
VAR_STAT
last_wMinute : UINT := 0;
running_total : UINT := 0;
current_minute_count : UINT := 0;
ppm_history : ARRAY[0..59] OF UINT := { 0, 0, [...], 0};
END_VAR;
current_wMinute := stdNow.wMinute;
IF current_wMinute <> last_wMinute THEN
running_total := running_total - ppm_history[last_wMinute];
ppm_history[last_minute] := current_minute_count;
running_total := running_total + ppm_history[last_wMinute];
last_wMinute := current_wMinute
END_IF;
IF product_oneshot THEN
current_minute_count := current_minute_count + 1;
END_IF;
hourly_average := running_total;
END_FUNCTION;