Introduction
Trend charts help you see how process values change over time. They make it easy to spot problems or patterns.
1. Define variables to store process values. 2. Use a timer or cycle count to sample values regularly. 3. Store sampled values in an array or buffer. 4. Use a display or HMI function to plot the stored values as a chart.
// Define array to hold 10 samples VAR TempSamples: ARRAY[1..10] OF REAL; SampleIndex: INT := 1; CurrentTemp: REAL; END_VAR // On each cycle CurrentTemp := ReadTemperatureSensor(); TempSamples[SampleIndex] := CurrentTemp; SampleIndex := SampleIndex MOD 10 + 1;
// Using a timer to sample every second VAR Timer1: TON; TempSamples: ARRAY[1..20] OF REAL; SampleIndex: INT := 1; END_VAR Timer1(IN:=TRUE, PT:=T#1S); IF Timer1.Q THEN TempSamples[SampleIndex] := ReadTemperatureSensor(); SampleIndex := SampleIndex MOD 20 + 1; Timer1(IN:=FALSE); END_IF
VAR TempSamples: ARRAY[1..5] OF REAL := [0,0,0,0,0]; SampleIndex: INT := 1; CurrentTemp: REAL; CycleCount: INT := 0; END_VAR // Simulate reading temperature and storing samples FOR CycleCount := 1 TO 10 DO CurrentTemp := 20.0 + CycleCount * 0.5; // Simulated temperature TempSamples[SampleIndex] := CurrentTemp; SampleIndex := SampleIndex MOD 5 + 1; END_FOR // Print stored samples FOR SampleIndex := 1 TO 5 DO Print('Sample ' + INT_TO_STRING(SampleIndex) + ': ' + REAL_TO_STRING(TempSamples[SampleIndex])); END_FOR
VAR samples: ARRAY[1..5] OF REAL; index: INT := 1; temp: REAL; END_VAR // On each cycle: temp := ReadTemperature(); samples[index] := temp; index := index + 1; IF index > 5 THEN index := 1; END_IF
VAR samples: ARRAY[1..5] OF REAL; counter: INT := 0; index: INT := 1; pressure: REAL; END_VAR
counter := counter + 1;
IF counter = 10 THEN
samples[index] := ReadPressure();
index := index + 1;
counter := 0;
IF index > 5 THEN
index := 1;
END_IF
END_IFPass the test and this pattern moves unknown