|
Instructions The STEP 7 - Micro/WIN standard library does not include generation of the Gray code. Using the download attached you can convert 8-, 16- and 32-bit binary numbers.
Description of the "GRAY CODE" library The "graycode.mwl" library includes function blocks for encoding and decoding the Gray code for the formats Byte, Word and Double Word.

Fig. 01
Conversion of binary code into Gray code (BIN_GRAY)
The functions BIN_GRAY_B, BIN_GRAY_W and BIN_GRAY_DW encode the input values for the number dimensions BYTE, WORD and DOUBLE WORD in Gray code.

Fig. 02
| Function |
Parameter |
Data type |
Operands |
| BIN_GRAY_B |
IN |
[BYTE] |
VB, EB, AB, MB, SB, SMB, LB, AC, Constant, *VD, *LD, *AC |
| OUT |
[BYTE] |
VB, EB, AB, MB, SB, SMB, LB, AC, *VD, *LD, *AC |
| BIN_GRAY_W |
IN |
[WORD] |
VW, EW, AW, MW, SW, SMW, LW, T, Z, AEW, Constant, AC, *VD, *AC, *LD |
| OUT |
[WORD] |
VW, EW, AW, MW, SW, SMW, LW, T, Z, AC, *VD, *AC, *LD |
| BIN_GRAY_DW |
IN |
[DWORD] |
VD, ED, AD, MD, SD, SMD, LD, AC, HC, Constant, *VD, *LD, *AC |
| OUT |
[DWORD] |
VD, ED, AD, MD, SD, SMD, LD, AC, *VD, *LD, *AC |
Table 01
Conversion of Gray code into binary code (GRAY_BIN)
The functions GRAY_BIN_B, GRAY_BIN_W and GRAY_BIN_DW decode the input values (Gray code) for the number dimensions BYTE, WORD and DOUBLE WORD in binary code.

Fig. 03
| Function |
Parameter |
Data type |
Operands |
| GRAY_BIN_B |
IN |
[BYTE] |
VB, EB, AB, MB, SB, SMB, LB, AC, Constant, *VD, *LD, *AC |
| OUT |
[BYTE] |
VB, EB, AB, MB, SB, SMB, LB, AC, *VD, *LD, *AC |
| GRAY_BIN_W |
IN |
[WORD] |
VW, EW, AW, MW, SW, SMW, LW, T, Z, AEW, Constant, AC, *VD, *AC, *LD |
| OUT |
[WORD] |
VW, EW, AW, MW, SW, SMW, LW, T, Z, AC, *VD, *AC, *LD |
| GRAY_BIN_DW |
IN |
[DWORD] |
VD, ED, AD, MD, SD, SMD, LD, AC, HC, Constant, *VD, *LD, *AC |
| OUT |
[DWORD] |
VD, ED, AD, MD, SD, SMD, LD, AC, *VD, *LD, *AC |
Table 02
Definition range There are no restrictions of range, because the conversion is binary and all types of display (decimal, hexadecimal, with sign) are interpreted as binary beforehand.
Auxiliary functions for converting Gray code into binary code
The subprograms GRAY_BIN and XOR are required for decoding the Gray code into binary code.
The STEP 7 Micro/WIN library as zip file Copy the file "graycode.zip" to a separate directory and extract the file. You can then integrate the "graycode.mwl" library, which can be used in version V3.2.4.27 and higher of STEP 7 Micro/WIN, into your S7-200 project.
Notes
- These gray code coding and decoding blocks cannot be used in conjunction with serial SSI (Synchronous Serial Interfaces) encoders, because they cannot be connected to the communication interfaces of the S7-200 CPUs due to the required baud rate of >187.5 Kbit/s and the two cable pairs required (for clock pulse and data).
- More information on the Gray code (value table, coding law) is available in
Entry ID: 25629271
- Information on inserting libraries in STEP 7 Micro/WIN is available in
Entry ID: 16689345
graycode.zip ( 3 KB )
|