Reputation: 715
We are trying to perform a real-time measurement/calculation on sampled data. Our previous experience was based on C
programming. I wonder if anyone can help me transfer the real-time c
programming structure into the PLC IEC61131 Structured Text?
For a real time control loop (with a constant loop cycle), we need a start timer, an end timer, and a wait function that works as follows:
while(1) {
t_start=timems(); /* a variable gets the current processor time in ms*/
/*... here the function performs the calculation...*/
t_stop=timems(); /* a variable gets the current processor time in ms*/
deltaT=t_stop-t_start; /* time difference between the start of the loop and end of the loop is calculated*/;
waitms(loop_constant-deltaT); /* the loop waits for the remainder of the constant loop time before the next iteration*/
}
Specifically, I'm wondering how we can do these timing structures inside the IEC61131? We can do the delay using TON, I think. However, any advice on how to get the time from the processor is highly appreciated.
(This post discusses that it's possible to write the code and transfer it to IEC61131. However, for educational purposes, writing the code inside the IEC61131 is preferred.)
p.s.1: I am working on a SEL-3350 device which is equipped with CODESYS firmware for writing IEC61131 programs.
p.s.2: after a couple of days of search I understood the difference between the real-time control based on C programming and the ones with IEC61131 (using CODESYS).
Basically, when you code using the PLC devices, you have the option inside the task manager to set up the properties of the controller processing cycle. Therefore, unlike "C" there is not need to perform an infinite loop (while (1)) and the software takes care of it. For example, in the CODESYS environment, you choose the type of program as "cyclic" and the interval time as your "loop constant", and it will be similar to the C code mentioned above.
Upvotes: 1
Views: 562
Reputation: 312
CoDeSys provides the library CmplecTask
which gives you detailed information regarding the current task. Let your code run in a dedicated task that is triggered cyclically and control everything with the information programmatically read from the task information. All timings, jitters etc are accessible there.
Upvotes: 0