0

I am working with a fast loop (0.5 ms cycle time) and slow loop (10 ms cycle time) which communicate with each other. How can I make the in- and outputs to be consistent?

Consider the example below, I want the assignments in the SlowLoop to be atomic, to be sure that both referenced inputs from the FAST loop correspond with values from the same cycle.

Example

FastLoop [0.5 ms]

FAST_CNT = some rising edge detection
FAST_RUNIDX += 1

SlowLoop [10 ms]

<-- Atomic Operation
pulseCount = FAST_CNT
elapsedTicks = FAST_RUNIDX 
Atomic Operation -->

2 Answers2

3

Anytime that anything needs to be 'Atomic', you need to handle an object (STRUCT or FUNCTION_BLOCK). In this case as there is no associated logic, a STRUCT should do the job nicely.

TYPE st_CommUnit :
STRUCT
    Count       : UINT;
    Index       : UINT;
END_STRUCT
END_TYPE

You can then have this STRUCT be presented as either an Input or Output between tasks using the %Q* and %I* addressing.

- Fast Task - 
SourceData AT %Q* : st_CommUnit
- Slow Task - 
TargetData AT %I* : st_CommUnit

Using this you end up with a linkable object such that you can link:

  • The entire unit
  • Each individual component

Example Atomic Unit

Steve
  • 963
  • 5
  • 16
2

If you use two different tasks with different cycle times maybe also running on different cores, you need a way to synchronize the two tasks when doing read/write operations.

In order to access the data in an atomic way use the synchronization FBs that Beckhoff provides like for example FB_IecCriticalSection. More info here on the infosys Website:

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/45844579955484184843.html&id=

Filippo Boido
  • 1,136
  • 7
  • 11