Tested the cod but had made some beginners misstake..
But i noticed something strange:
In your original code it looks like this for FIFO_16:
NW := INC1(N:=NW, X:=16);
This doesnt work for me had to switch places so it look like this:
NW := INC1(N:=16, X:=NW);
Ok but here are my code:
VAR_INPUT
Din : DWORD;
WR : BOOL;
RD : BOOL;
E : BOOL;
RST : BOOL;
N : INT;
END_VAR
VAR_OUTPUT
Dout : DWORD;
empty : BOOL := TRUE;
full : BOOL;
END_VAR
VAR
fifo : ARRAY[0..32] OF DWORD;
NW : INT;
NR : INT;
RD_Edge : BOOL;
WR_Edge : BOOL;
END_VAR
BEGIN
IF rst THEN
(* asynchronous reset for the fifo *)
NW := 0;
NR := 0;
Dout := 0;
empty := TRUE;
full := FALSE;
ELSIF E THEN
IF WR AND NOT full AND NOT WR_Edge THEN
(* write action *)
fifo[NW] := Din;
NW := INC1(N:=N, X:=NW);
full := NW = NR;
empty := FALSE;
WR_Edge := TRUE;
ELSIF WR AND full AND NOT WR_Edge THEN
(* read from stack *)
Dout := fifo[NR];
NR := INC1(N:=N, X:=NR);
empty := NR = NW;
full := FALSE;
(* write action *)
fifo[NW] := Din;
NW := INC1(N:=N, X:=NW);
full := NW = NR;
empty := FALSE;
WR_Edge := TRUE;
ELSIF NOT WR THEN
WR_Edge := FALSE;
END_IF;
IF RD AND NOT empty AND NOT RD_Edge THEN
(* read from stack *)
Dout := fifo[NR];
NR := INC1(N:=N, X:=NR);
empty := NR = NW;
full := FALSE;
RD_Edge := TRUE;
ELSIF NOT RD THEN
RD_Edge := FALSE;
END_IF;
END_IF;
END_FUNCTION_BLOCK