rustmatic
rustmatic copied to clipboard
Implement parsing of MVP IEC
Need #35 , #33 , #34
Rough sketch, there could be errors here...
PROGRAM Blinky
VAR
clock: RTC;
start: DT# := DT#2019-12-17-00:00:00.000; // Some arbitrary start time
current: DT#;
previous: DT#;
elapsed: T#;
previous: T#;
valid: bool;
period: REAL;
END_VAR
IF %IB4 = 0 THEN
period := 1.0;
ELSE
period := 1.0 / %IB4; // %IB4 contains frequency. Byte is promoted to real?
END_IF;
// The stuff that follows could also be solved more elegantly
// with a duty-timer circuit.
// But what's below maps more closely to the blinky.rs example
clock(IN:=TRUE, PDT:=start_time, Q=>valid, CTD=>current_time); // Get current time
elapsed := elapsed + SUB_DT_DT(IN1:=current_time, IN2:=previous);
previous := current;
// REAL_TO_TIME takes msecs
IF elapsed > REAL_TO_TIME(period*1000.0) THEN
elapsed := T#0;
%QX0.0 := NOT %QX0.0;
END_IF;
END_PROGRAM