CX-One, CX programmer, NTST, Syswin ....
-
ahmed yousri
- Posts: 65
- Joined: Thu Apr 17, 2008 11:48 am
- Location: Egypt
Post
by ahmed yousri » Sat Dec 27, 2008 12:56 pm
can i convert Gray code to binary code using ladder diagram ,
if there is document pls uploaded it
http://en.wikipedia.org/wiki/Gray_code
Here is an algorithm to convert Gray code to natural binary codes (decode):
C function
Code: Select all
unsigned int graydecode(unsigned int gray) {
unsigned int bin;
for (bin = 0; gray; gray >>= 1) {
bin ^= gray;
}
return bin;
}
Code: Select all
Let G[n:0] be the input array of bits in Gray code
Let B[n:0] be the output array of bits in the usual binary representation
B[n] = G[n]
for i = n-1 downto 0
B[i] = B[i+1] XOR G[i]
3-bit Grey code
Code: Select all
Dec Gray Binary
0 000 000
1 001 001
2 011 010
3 010 011
4 110 100
5 111 101
6 101 110
7 100 111
-
Schtiel
- Site Admin
- Posts: 1121
- Joined: Wed Sep 06, 2006 12:03 pm
- Location: CIS
Post
by Schtiel » Sat Dec 27, 2008 1:52 pm
ahmed yousri wrote:can i convert Gray code to binary code using ladder diagram
of course yes, for what PLC do you need the program?
-
Олег
- Posts: 58
- Joined: Wed Dec 13, 2006 6:54 am
- Location: Russia
-
Contact:
Post
by Олег » Sat Dec 27, 2008 3:11 pm
GRAY CODE CONVERSION (GRY(474)) for Easy Conversion of Parallel Inputs from Absolute Encoders
to Binary, BCD, or Angle Data
This instruction converts Gray binary codes to binary, BCD, or angle data.
This enables easily handling position or angle data input as parallel signals
(2n) from an Absolute Encoder with a Gray code output using a DC Input Unit.
-
Info
- Faq & Info
- Posts: 425
- Joined: Wed Oct 05, 2005 9:00 am
Post
by Info » Sun Dec 28, 2008 6:00 am
gray code to decimaly this XOR command
see S7 STL code
L0.2 - L0.7 this no use bits (encoder 10 bits)
Code: Select all
L #IN0 // IW encoder
T #encod_gray_dec // LW0
SET
R L 0.7
R L 0.6
R L 0.5
R L 0.4
R L 0.3
R L 0.2
AN L 0.1
JC M003
AN L 0.0
= L 0.0
M003: AN L 0.0
JC M004
AN L 1.7
= L 1.7
M004: AN L 1.7
JC M005
AN L 1.6
= L 1.6
M005: AN L 1.6
JC M006
AN L 1.5
= L 1.5
M006: AN L 1.5
JC M007
AN L 1.4
= L 1.4
M007: AN L 1.4
JC M008
AN L 1.3
= L 1.3
M008: AN L 1.3
JC M009
AN L 1.2
= L 1.2
M009: AN L 1.2
JC M010
AN L 1.1
= L 1.1
M010: AN L 1.1
JC M011
AN L 1.0
= L 1.0
M011: NOP 0
L #encod_gray_dec
T #OUT1 //decimaly out encoder
-
Scarch
- Posts: 103
- Joined: Fri Aug 31, 2007 8:17 pm
- Location: Europe
Post
by Scarch » Thu Dec 08, 2011 9:12 pm
Thanks sania, I will try it soon.