[?]: Conversion blocks binary-gray (17 bits)

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Scarch
Posts: 103
Joined: Fri Aug 31, 2007 8:17 pm
Location: Europe

[?]: Conversion blocks binary-gray (17 bits)

Post by Scarch »

Hi all,
I need to convert binary to grey code but siemens requires a password from this page: http://support.automation.siemens.com/W ... n/25629271

Somebody have these blocks available?
Many thanks
Last edited by Scarch on Fri Feb 17, 2012 4:05 pm, edited 2 times in total.
Homeroid_BL
Posts: 258
Joined: Fri Apr 03, 2009 3:24 pm
Location: Bosnia and Herzegovina

Re: Conversion blocks binary-gray

Post by Homeroid_BL »

C'mon, do it youself.
Here is a converter for 4bits, using XOR logic.
:)

Image
Info
Faq & Info
Faq & Info
Posts: 428
Joined: Wed Oct 05, 2005 9:00 am

Re: [?]: Conversion blocks binary-gray

Post by Info »

Scarch
Posts: 103
Joined: Fri Aug 31, 2007 8:17 pm
Location: Europe

[?]: Convert Gray code to decimal 16 bits

Post by Scarch »

Hi...
I have used a program from Sania in order to convert from gray to decimal for 10 bits, but now I need it for 16 bits (1 word) and do not know how to modify it.
Please help. It is used for an absolute multiturns encoder, being able to read from zero to 65536 in gray code.
I can't manage it.
Nick_N
Posts: 2
Joined: Mon Jun 21, 2010 2:16 pm
Location: Kharkov, Ukraine

Re: [?]: Conversion blocks binary-gray (16 bits)

Post by Nick_N »

Wikipedia says there's another formula. STL implementation:

Code: Select all

//C formula:
//        unsigned short temp = num ^ (num>>8);
//        temp ^= (temp>>4);
//        temp ^= (temp>>2);
//        temp ^= (temp>>1);
//        return temp;
//Taken from http://en.wikipedia.org/wiki/Gray_code#Converting_to_and_from_Gray_code
// temp = num ^ (num>>8);
      L     #Gray
      SRW   8
      L     #Gray
      XOW   
      T     #Temp
// temp ^= (temp>>4);
      L     #Temp
      SRW   4
      L     #Temp
      XOW   
      T     #Temp
// temp ^= (temp>>2);
      L     #Temp
      SRW   2
      L     #Temp
      XOW   
      T     #Temp
// temp ^= (temp>>1);
      L     #Temp
      SRW   1
      L     #Temp
      XOW   
//return temp;
      T     #RET_VAL
Variables #Gray, #Temp and #RET_VAL are of type WORD.
#Gray (IN) = Gray code
#Temp (TEMP) = temporary value
#RET_VAL (RETURN) = result of calculation, binary value

Works for 16-bit Gray code.