0

I have Just started working on PLC using Structured text, I have to store values in Array of Temperature variable after delay of 1 min every time but i am not able to do that.

FOR i := 0 TO 5 DO
    Temp[i] := tempsensor;
END_FOR;

This is kind a pseudo code. I just need to bring in the delay in the loop that after every 1 min it could read the value and store it in the array location.
Even if there is any other way then I will really appreciate that.

Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57
Mazdak Khan
  • 1
  • 1
  • 2

2 Answers2

3

Try this

VAR 
   i:INT;
   Temp: ARRAY[0..10000] OF LREAL; 
   delayTimer: TON;
END_VAR

delayTimer(IN := not delayTimer.Q, PT := T#1m);

IF delayTimer.Q THEN
   Temp[i] := tempsensor;
   i := i + 1;

   IF i > 10000 THEN
       i := 0;
   END_IF;
END_IF;

After 1 minute it will record 1 temperature value and index the array. If it reaches the end of the array it will start to write over at the beginning.

mrsargent
  • 2,267
  • 3
  • 19
  • 36
0

Once every minute you cycle through array and set values.

VAR
    i: INT := 1; (* Cycle number *)
    temp: ARRAY[1..5] OF REAL; (* Array of temperatures *)
    ton1: TON; (* Timer *)
END_VAR

ton1(IN := NOT ton1.Q, PT := T#1m);

IF ton1.Q THEN
    temp[i] := tempsensor;
    IF i >= 5 THEN i := 1 ELSE i := i + 1 END_IF;
END_IF;
Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38
  • It doesn't work, It waits for one Minute but after one Minute delay it fills all the array locations at once. The task which I need to do is to store values after one Minute delay at different array locations in my case [0 to 5]. So after one Minute it should store value at Locaation '0' then after one Minute on Location '1' and so on. – Mazdak Khan Oct 21 '19 at 11:07
  • I've corrected the code. Are you making a sort of filter? If yes you have to initialize array first. – Sergey Romanov Oct 23 '19 at 13:52