F116_FIFR

Read from FIFO buffer

F116_FIFR reads the data d1 from the FIFO (First-In-First-Out) buffer and stores the data in area specified by d2.

Parameters

Input

d1_Start (WORD, INT, UINT)

starting 16-bit area of FIFO buffer

Output

d2 (WORD, INT, UINT)

16-bit area for storing data read from FIFO buffer

Remarks

  • Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_FIFO_READ, FP_LIFO_READ

  • Reading of data is done starting from the address specified by the reading pointer when the instruction is executed.

    1.  (1) Memory size of FIFO buffer (n)
    2.  (2) Number of stored data items (words), written and not read
    3.  (3) Reading pointer in upper byte
    4.  (4) Reading pointer
    5.  (5) Data storage area (n words)
  • (0), (n–2) and (n–1) are addresses assigned to the data storage area.

  • n is the value specified by the F115_FIFT instruction.

  • The reading pointer is stored in the upper eight bits of the third word of the FIFO buffer area. The actual address is the value of the leading address in the FIFO buffer area specified by d1 plus 3, plus the value of reading pointer (the value of which only the first byte is a decimal value).

  • When the reading is executed, 1 is subtracted from the number of stored data items, and the reading pointer is incremented by 1, or reset to zero if the reading pointer pointed to the final element.

NOTE
  • An error occurs if this is executed when the number of stored data items is 0 or when the reading pointer is equal to the writing pointer.

  • Reading is only carried out when the reading pointer is not equal to the writing pointer.

  • If this is executed when the reading pointer is indicating the final address in the FIFO buffer (the n defined by the FIFO instruction minus 1), the reading pointer is set to 0.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the size (n) of the FIFO specified by d1 is n = 0, or when n > 256.

  • if the number of stored data items of the FIFO = 0.

  • if the number of stored data items of the FIFO > FIFO size (n).

  • if the final address of the FIFO based on the FIFO size (n) exceeds the area.

  • if the FIFO reading pointer > FIFO size (n).

  • if the FIFO reading pointer is 256 (16#100) or higher after the data has been read.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the size (n) of the FIFO specified by d1 is n = 0, or when n > 256.

  • if the number of stored data items of the FIFO = 0.

  • if the number of stored data items of the FIFO > FIFO size (n).

  • if the final address of the FIFO based on the FIFO size (n) exceeds the area.

  • if the FIFO reading pointer > FIFO size (n).

  • if the FIFO reading pointer is 256 (16#100) or higher after the data has been read.

Example

DUT

This example illustrates the FIFO buffer by incorporating the functions F115_FIFT, F116_FIFR and F117_FIFW.

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

VAR
		FIFO: FIFO_n_WORD;
		iRead_Data: INT:=0;
		iWrite_Data: INT:=1;
		bFIFO_Initialize: BOOL:=FALSE;
		bFIFO_Write: BOOL:=FALSE;
		bFIFO_Read: BOOL:=FALSE;
		bChange_Value: BOOL:=FALSE;
	END_VAR

POU body

The example below illustrates the status of the buffer after bFIFO_Write has been enabled twice and bFIFO_Read once. When bFIFO_Write was activated the first time, the value 1 was written into FIFO.awData[0]. When bFIFO_Read was enabled, iRead_Data then read this value. When bFIFO_Write was enabled the second time, the writing pointer was incremented by one and the value 2 written into FIFO.awData[1]. see Entry Data Monitor 1

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bFIFO_Initialize,6,1,8,3,R);
B(B_F,F115_FIFT,,24,0,33,5,,?DEN?Dn?Dd1?AENO);
B(B_VARIN,,FIFO.awData,11,3,13,5,);
B(B_F,Size_Of_Var,,13,2,23,5,,?D@'Var'?CSize);
B(B_VARIN,,FIFO.iSize,11,5,13,7,);
L(1,0,1,7);
L(1,2,6,2);
L(8,2,24,2);
L(23,3,24,3);
L(23,3,23,4);
L(24,4,24,6);
L(13,6,24,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_COMMENT,,The LT (Lower Than) operator prevents a writing error from occurring.,3,1,33,2,);
B(B_VARIN,,FIFO.iNumber,8,4,10,6,);
B(B_F,@LT-2,,10,3,15,7,,?D?D?C);
B(B_CONTACT,,bFIFO_Write,17,4,19,6,R);
B(B_VARIN,,FIFO.iSize,8,5,10,7,);
B(B_F,F117_FIFW,,24,4,33,8,,?DEN?D@'s'?AENO?Cd1);
B(B_VARIN,,iWrite_Data,22,6,24,8,);
B(B_VAROUT,,FIFO.iSize,33,6,35,8,);
L(1,0,1,9);
L(15,5,17,5);
L(19,5,19,6);
L(19,6,24,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_COMMENT,,The GT (Greater Than) operator prevents a reading error from occurring.,3,1,34,2,);
B(B_VARIN,,FIFO.iNumber,7,4,9,6,);
B(B_F,@GT-2,,9,3,14,7,,?D?D?C);
B(B_CONTACT,,bFIFO_Read,16,4,18,6,R);
B(B_VARIN,,0,7,5,9,7,);
B(B_F,F116_FIFR,,24,4,33,8,,?DEN?Dd1?AENO?Cd2);
B(B_VARIN,,FIFO.iSize,22,6,24,8,);
B(B_VAROUT,,iRead_Data,33,6,35,8,);
L(1,0,1,9);
L(14,5,16,5);
L(18,5,18,6);
L(18,6,24,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_COMMENT,,The E_ADD function is for cosmetic purposes only. It increments the value for the variable iWrite_Data~ which you can more easily differentiate when it is written into the Array of the FIFO buffer.,3,1,34,4,);
B(B_CONTACT,,bChange_Value,9,5,11,7,R);
B(B_F,E_ADD-2,,22,4,28,9,,?DEN?Da_NumN?Da_NumN?AENO?C);
B(B_VARIN,,iWrite_Data,20,6,22,8,);
B(B_VAROUT,,iWrite_Data,28,6,30,8,);
B(B_VARIN,,1,20,7,22,9,);
L(1,0,1,9);
L(1,6,9,6);
L(11,6,22,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF DF(bFIFO_Initialize) THEN
	(* Create the FIFO buffer *)
	F115_FIFT(n_Number := Size_Of_Var(FIFO.awData), d1_Start :=  FIFO.iSize);
	REPEAT
		(* Initialize FIFO buffer with values *)
		iWrite_Data:=iWrite_Data+1;
		F117_FIFW(s := iWrite_Data, d1_Start => FIFO.iSize);
	UNTIL(FIFO.iNumber>=FIFO.iSize)
	END_REPEAT;
END_IF;

IF DF( bFIFO_Write) THEN
	(* Write value of Write_Data to FIFO buffer *)
	(* at leading edge of FIFO_Write *)
	F117_FIFW(s := iWrite_Data, d1_Start => FIFO.iSize);
END_IF;

IF DF(bFIFO_Read) THEN
	(* Read value from FIFO buffer *)
	(* at leading edge of FIFO_Read *)
	F116_FIFR(d1_Start := FIFO.iSize, d2 => iRead_Data);
END_IF;

Modified on: 2023-10-25Feedback on this pagePanasonic hotline