FLL — Fill

FLL in rungs.dev writes one value into every element of a run of an array. Use it to clear a buffer, preset a recipe, or zero a structure in one rung.

FLL

Source

source

Dest

dest

Length

length

Writes one value into every element of a run of an array.

What it does

FLL is the fast way to clear or preset a block of memory: zero a buffer before a new batch, set every alarm limit to a default, blank a display array.

Like COP, it runs on every scan the rung is true — not once per rising edge.

Operands

NameTypeNotes
sourceDINT, INT, SINT, REALThe value to write. A tag or a number
destDINT, INT, SINT, REAL, STRING, TIMER, COUNTER, CONTROLOne element — where the run starts
lengthDINT, INT or SINTHow many elements to fill. A tag or a number

length clamps to the destination, exactly as COP's does, and never faults.

Converting on the way in

For an ordinary array, the source is converted to the destination's type once, then written into every element — the same rule MOVE uses.

SourceDestinationResultWhy
2.5 (REAL)DINT[]2Halves round to even
3.5 (REAL)DINT[]4Halves round to even
300SINT[]44Wrapped to 8 bits, not clipped
70000INT[]4464Wrapped to 16 bits
3.0e9DINT[]-1294967296Wrapped to 32 bits

This is conversion, not saturation: a value too big for the type wraps round rather than sticking at the maximum.

Filling a structure

A TIMER, COUNTER or CONTROL destination is different: the source's bytes are written raw, with no conversion, over the whole structure — the numbers and the status bits alike. A DINT or a REAL fills each 4-byte word; a SINT or an INT repeats its own 1 or 2 bytes, so a SINT holding -2 fills every byte with the same pattern.

FLL(0, Dwell, 1) is the useful case: it zeroes the whole timer, preset included.

A STRING is filled the same way, over all of its bytes: FLL(0, Msg, 1) empties it and clears every character. FLL(65, Msg, 1) does not fill it with As: 65 lands in .LEN as well, and only every fourth character is an A. To fill a STRING with text, use MOVE.

To fill only the characters, name the first one: FLL(0, Msg.DATA[0], 82) sets all 82 to 0 and leaves .LEN alone. Here each character is one SINT, so the value is converted, as it is for any number array: FLL(65, Msg.DATA[0], 3) writes AAA. A length past the characters runs on into the two spare bytes and stops at the end of the STRING, or of the whole array when Msg is an element of one.

FLL(7, Dwell, 1) does not set the preset to 7 and stop there

It writes 7 into .PRE and .ACC, because both are words of the same structure. And a value with a high bit set lands in the status bits too: FLL(2.5, Dwell, 1) writes the decimal's bit pattern, which switches .TT on.

To set just one member, use MOVE: MOVE(5000, Dwell.PRE).

Example — Clear a Buffer

0

NewBatch

FLL

Source

0

Dest

Readings[0]

Length

20

1

NewBatch

FLL

Source

0

Dest

Total

Length

1

Structured Text

FLL has no Structured Text form. In a Structured Text routine, write a FOR loop, or use COP with the replicate idiom.

Common Mistakes

  • Using FLL on a timer to set its preset. It fills every member. Use MOVE.
  • Expecting 300 into a SINT array to clip at 127. It wraps to 44.
  • Naming the bare array — FLL(0, Readings, 20). Name an element: Readings[0].

On this page