Simaticer meets CoDeSys

kaputt

Level-1
Beiträge
100
Reaktionspunkte
11
Hi all!

In my Step7 i can set an outputbit indexed by an integer more or less like this:
(range of 64 limiting omitted).

L P#xS0 // the first output bit
LAR1
L 0
T DW[AR1,P#0.0] // reset all outputs
T DW[AR1,P#4.0]
L iStep // output bit to be set
+AR1
SET
= [AR1,p#0.0]

I like the outputs to be boolean pins on the function block, because of the convenience when used in CFC.

So my question is; how can this be done in CoDeSys (V2)?
Do I need to make 64 comparisation rungs?

MfG
Kaputt
 

Anhänge

  • OutputX.png
    OutputX.png
    22,6 KB · Aufrufe: 75
I don't really know Step7, but I think I know what you want. In CoDeSys 2 there are no real bit variables except in the I/O area, so in your FB you have to use 64 BOOL variables "Xs0".."xs63" which are in fact 64 bytes. You can access them with a pointer to an array[0..63] OF BOOL.
Code:
FUNCTION BLOCK IndexBit;
VAR_INPUT
   Index:USINT;
END_VAR
VAR_OUTPUT
   xs0:BOOL;
   xs1:BOOL;
   xs2:BOOL;
    *
    *
   xs63:BOOL;
END_VAR
VAR
   P:POINTER TO ARRAY[0..63] OF BOOL;
   Loop:BYTE;
END_VAR

P:=ADR(xs0);   (* Set pointer to first bool output *)
FOR Loop:=0 TO 63 DO   
   P^[Loop]:=FALSE;   (* Clear all outputs *)
END_FOR
P^[Index]:=TRUE;   (* Set indexed output *)
 
Zuletzt bearbeitet:
Zurück
Oben