Gray code GCD in ML1400

JZerb

Member
Join Date
Oct 2016
Location
Here
Posts
421
Using RSemulate, according to technote 55723, i should be able to use the GCD instruction to test some logic but it seems as if its not working. i set it up as Source of I:0.0 and Dest of N7:0 and im getting nothing through to N7:0. Thought that whatever i put into the data file for the I:0.0 (111111111111111), i would get out into N7:0 as a binary number(4095). am i missing something?
 
In the actual PLC you would not be able to write to a digital input word (I:0.0) as the PLC would overwrite it each scan. Not sure how RSEmulate handles this.
You might try using a binary word e.g. B3:0 instead.

Are you calling the subroutine if using one?
 
so i tried it with a Binary word as the source and still no good. I just playing around with how i would go about getting gray code output from an absolute encoder into something use able in a ML1400. I saw a method of using logic to go from gray to binary the 'long way' and got that to work. but i figured why would i do that if i can just use a GCD instruction to do what i assume would be the same thing, take gray code and turn it into binary.

edit: i have a CPW instruction behind that B3 popup window, thats why B3:1 reads the same as B3:0, just in case someone saw that and said....wait a second here.

GCD.jpg
 
Obviously that should be giving 2730. I'll assume that as you toggle bits in B3:0 that changes take place in B3:1 and N7:1 showing that the code is running. Sorry, no other thoughts.
 
it must be something that the RSEmulate doesnt handle well, unless im just totally doing it wrong.

to simplify here for myself i did the attached. if i have an encoder outputting gray code, 12 bit so if the MSB is 1 and all others are 0 i should get 2048 right? so i put N7:0 as the source in the GCB, it reads 2048, but on the Dest for that instruction its giving me bubkiss. i assumed, it should give me 2048, but again perhaps im not fully understanding what should be going on here.

ill try it live on a ML1400 tomorrow, if its still not working ill give AB a call and see what im not understanding.

GCD2.jpg
 
Actually that bit pattern should decode to 4095. The next pattern from the encoder (counting up) should be all zeroes which decodes as zero. (I'm using the Do-more plc software with its simulator to check.)
 
Actually that bit pattern should decode to 4095. The next pattern from the encoder (counting up) should be all zeroes which decodes as zero. (I'm using the Do-more plc software with its simulator to check.)

ok. well then im clearly confused here and i need to do some more reading up on the subject matter.

i was under the impression that if you took an encoder, say from automation direct that was 11 bit gray code output, 2048ppr and attached that to an input card on your PLC, AB ML1400 in my case, on inputs 0-10, then used the GCD instruction to take those 1's and 0's from I:1.0 it would spit them out as a decimal number in the Dest from the GCD instruction. again my assumption is that the number it would spit out in the Dest would be a number from 0-2048(?) because thats the PPR of said encoder. ill end this by saying ive never worked with a gray code encoder before so i could be totally and completely wrong in how i thought it was supposed to work with what ive said above.
 
In the last example (post #6) you set bit 11 which would be the top bit of a 12 bit encoder. Setting the top bit of an 11 bit encoder (bit 10) would give you a raw value of 1024 and a decoded value of 2047 representing the highest code of your 11 bit encoder.


Gray code (it's most correct to capitalize the 'G' since it's the name of the man who invented the coding method) is also used in encoders with counts not a power of 2 (like 360). Have fun with them.
 
Last edited:
ok, so the attached pic now would be correct for an 11 bit encoder then? again i would assume if the GCD instruction was working properly it would read 1024 on the Dest as well. so with that being said, the encoder in question here is an 11 bit, 2048ppr unit. since the Gray code only reads out 1024, or half of 2048, would one then need to take that Dest value and MUL by 2 in order for it to be useful within the logic?

GCD3.jpg
 
No, the result after conversion is not that obvious (well, except for 0 and 1 in Gray which give 0 and 1 in the converted number). Read up on the logic in the conversion. Actually the logic to go the other way - normal number to Gray - is fairly easy. The Gray to normal takes a few more steps. I can write it up in RSLogix (ML1100 - free software only) if you wish but I don't have a unit or emulator to test the code.
 
i attached a zipped .rss that i came across online when reading up about Gray to binary. i assume theses are the 'steps' youre talking about. again i was just under the assumption that i could skip doing all of that logic and use the GCD instruction to accomplish the same thing.

the screenshot is the beginning of another sample code i found as well. where in the comment its saying that one method is to use the GCD and the other method is to use some lines of logic to get the same result. i figured i could use the GCD then use the binary that it outputs, put that through a MVM and get a number out of it thats useful to me in the end.

GCD4.jpg
 

Attachments

  • Gray_to_BinaryML1400.zip
    18.8 KB · Views: 8
Last edited:
It sounds like the emulator is the problem. Your ladder in the jpg is what I would have provided. Set the logic in a subroutine while using the emulator and change the call to the GCD instruction when it's time to use the actual hardware.
 

Similar Topics

Hey guys, Although I've poured through this forum for help in the past this is my first post. I am looking at replacing obsolete Baumer IVO...
Replies
6
Views
1,936
First time I have used an absolute encoder and it is definitely:banghead:. I have a Siemens 6FX2001-5FN25...
Replies
21
Views
6,035
I am migrating a PLC-5 to CLX. I do not have the option of changing out the existing encoders (845D-SJHZ25AGCW4). 8-24v DC, 256...
Replies
0
Views
1,588
Hi I have a question about a gray code absolute 8 bit encoder. The encoder is connected to 8 inputs on an Allen Bradley PLC. if you turn the...
Replies
6
Views
2,258
Any recommendation on using a gray code encoder as input to a compactlogix PLC to trigger a digital input every 15 degree position on a rotary...
Replies
3
Views
2,765
Back
Top Bottom