show the entry list
STEP 7 Micro/WIN -- Creating S7 programs -- Calling blocks and functions
How do you reset the high-speed counters of the S7-200?
Using an S7-200 without twilight switch, how do you have shutters open at sunrise and close at sunset?
How do you count values over 16 bits with the S7-200?
How can you limit the pitch of jumps with S7-200?
How do you configure the positioning module EM253 so that the connected stepper motor can proceed in both directions?
How do you position a servo drive axis using the S7-200 pulse interface?
How do you create a bar display in TD 200 or TD 200C?
How can you optimize use of timers in STEP 7 Micro/WIN?
How do you determine the frequency of a pulse sequence and speeds?
How can you scale analog values with S7-200 in conjunction with CPU224XP and expansion modules EM 231, EM 232 and EM 235?
How do you convert a binary number into Gray code (or vice versa) in STEP 7 Micro/WIN?
How do you convert the number format DOUBLE INTEGER into BCD code (or vice versa) in STEP 7 Micro/WIN?
How do you form the absolute and negative values of numbers in STEP 7 Micro/WIN?
Why does the PID controller created by the instruction wizard sometimes not work?
What do you have to do in the SIMATIC S7-200 in order to edit part of the program once after restarting?
Which library with the inverse functions to the trigonometric functions (sine, cosine, tangent) is available for STEP 7-Micro/WIN?
Scaling the setpoint and actual values in the STEP 7 Micro/WIN V4 wizards for PID control loops
Positioning Wizard for PTO/PWM in STEP 7 Micro/WIN V4.0
How to implement a three step control with PID-loop in the S7-200 via STEP 7-Mirco/WIN?
How do you convert a binary number into Gray code (or vice versa) in STEP 7 Micro/WIN?
Part number:

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 )

 Entry ID:26485059   Date:2012-05-03 
I regard this article....as helpfulas not helpful                                 
mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Help
Online Help
Guided Tour