John_R Posted November 14 Report Share Posted November 14 Hey All, Any of you have have a Vision routine made up to decode 1-16 from a 4-bit Gray Code? I'm picturing a lot of logic for a seemingly simple task... ABEF 1 - 0000 2 - 0001 3 - 0011 4 - 0010 5 - 1010 6 - 1011 7 - 1111 8 - 1110 9 - 0110 10- 0111 11- 0101 12- 0100 13- 1100 14- 1101 45- 1001 16- 1000 Regards, JohnR Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted November 14 MVP 2022 Report Share Posted November 14 Maybe this will be useful: https://www.plcdev.com/using_ladder_logic_for_gray_code_conversion Quote Link to comment Share on other sites More sharing options...
MVP 2022 kratmel Posted November 14 MVP 2022 Report Share Posted November 14 I played with a data table (4 columns of bits) in which I wrote down possible codes for the position of the turret. With one command (Data Table Find (Extended), I searched for the line number in which the required combination was found. The task was to automatically find the position number as a decimal number. In my case it was the row numbe r of the data table. Quote Link to comment Share on other sites More sharing options...
John_R Posted November 15 Author Report Share Posted November 15 What I have here is a piece of audio gear that uses this encoder wheel to scroll through options. And sometimes it goes wanky, when it should be scrolling "up", it will go up one step then down a step (or vice-versa). I first assumed it was a quadrature encoder, either Incrementing or Decrementing some counter, and was missing pulses that confused direction. Turns out the encoder outputs this Gray code, which gives a consistent output step by step, checking with a meter. So I thought I would make a "quick and dirty" test program on a PLC, where I could watch the results of spinning the encoder at normal speed, maybe something is floating... The encoder is a 16 position mechanical switch encoder (CTS series 288), which I have already sprayed with De-Oxid contact cleaner, with no improvement. And following up on years of troubleshooting experience, programmed controllers don't go wanky (it either works or doesn't), more than likely a problem with the input devices.. So here I am trying to find a way to real-time test this encoder.. Quote Link to comment Share on other sites More sharing options...
MVP 2022 kratmel Posted November 15 MVP 2022 Report Share Posted November 15 4 hours ago, John_R said: So here I am trying to find a way to real-time test this encoder.. Similar to your task, I set up a PLC to detect problems with the turret encoder. It should be noted that your code is slightly offset from the standard Gray code. Therefore, standard conversion methods need "improvement". Quote Link to comment Share on other sites More sharing options...
John_R Posted November 15 Author Report Share Posted November 15 7 hours ago, kratmel said: It should be noted that your code is slightly offset from the standard Gray code Hmmm, well this is the Gray Code truth table taken from the CTS spec sheet. and my encoder does follow this pattern (checking each output step by step with a meter). I've never played with a Gray code (so it's a gray area to me).🥴 Anyway, like I said, I thought a PLC program would be a good way of testing (but after 3 years of retirement, my coding is getting slow and rusty). JohnR Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.