Shop OBEX P1 Docs P2 Docs Learn Events
Gray code 10bit SSI encoder project — Parallax Forums

Gray code 10bit SSI encoder project

OzStampOzStamp Posts: 377
edited 2007-09-27 00:52 in Propeller 1
Hi All

Been testing a bit of stuff with a Propeller.
Need to read a 10BIT absolute encoder with SSI interface .
The absolute angular data needs to be send to a PLC.
Very expensive dedicated cards can be bought from all major PLC vendors
so thought try and do this with a Propeller.

Hacked some code in Spin to get the "Flow" of what is required happening.
Spin samples way to slow and this code needs to be ported to assembly.
The code sample attached as a PDF file shows only half what is required,
Getting the data from the SSI encoder is via a very fast Shiftin type routine
but the code the encoder sends is in GRAY code so it needs to be converted to BINARY.
Cannot use a "Look UP TABLE" as we may use the full 13 bit resolution of the encoder as we
progress to bigger and better things.
The lookup table would simply be too BIG

The 32bit longs and the incredible power to do complex calculations all in one line
make things a little easier in SPIN·... anyway need to port this to Assembly for speed
We need to shiftin data at frequencies over 100KHZ minimum ...
The code example ran about 2000 HZ ( inserted a toggle flasher at the end .. now removed)
See the screenshot of the scope also embedded in the document
Spin runs at about 80K instructions ... correct ??

Once we get one encoder working the Propeller should be able to do at least 3
Thought we share this stuff with you all.

Ronald Nollet·· OZ·

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-25 09:55
    Which encoders are you using, Avago (formally agilent)?

    Graham
  • OzStampOzStamp Posts: 377
    edited 2007-09-25 13:31
    Hi Graham.
    Presently using the below as we had one laying around .. there are amny SSI encoders
    All use the same protocol

    Sick/StegMann CoreTech series T21 series .. probably now different series as
    the company Stegmann was bought by SICK (optic electronics) a few years ago now
    10-32VDC >> with SSI interface clcok + data + remote zero function .
    These encoders are real robust ..thick shaft and high IP rating..
    The unit I have is 8192 resolution (13 bit)

    Cheers
    Ronald Nollet OZ
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-25 15:52
    These may be of use

    basic stamp completed project http://forums.parallax.com/forums/default.aspx?f=21&m=208940
    quadrature encoder with spin files from Jeff Martin and Graham Stabler http://forums.parallax.com/forums/default.aspx?f=25&m=156619
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 21:07
    OzStamp said...
    ...We need to shiftin data at frequencies over 100KHZ minimum ...
    The code example ran about 2000 HZ ( inserted a toggle flasher at the end .. now removed)
    ..
    Spin runs at about 80K instructions ... correct ??
    It is difficult to say what a "SPIN instruction" really is. According to my measurements, SPN is a little bit faster, but not much...

    When hand-translating SPIN to assembly I have generally gotten a speed-up of 80. But there is more potentiality in case of tight INA/OUTA handling.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 21:20
    Just BTW: This is the draft assembly translation
    gray2bin
            MOV length, #10
    loop10
            SHL sh_gray, #1
            MOV xor_calc, sh_gray
            XOR xor_calc, msb_bin
            AND xor_calc, initmask
    
            SHL msb_bin, #1
            ADD msb_bin, xorcalc
            DJNZ length, #loop10
    
     ' 70 instructions = 3,5 us = 300 kHz
    
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-25 22:07
    the wikipedia entry:

    en.wikipedia.org/wiki/Gray_code

    has a decoding algorithm possibly similar to that posted by deSilva (I haven't stepped through it yet).

    Graham
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-25 22:27
    That is indeed a VERY instructive article
  • OzStampOzStamp Posts: 377
    edited 2007-09-25 23:39
    Hi Fred H

    The file you pinted to is for 2 channel incremental encoders.(Jeff Martin one)
    These just provide A and B phase ( some with zero marker as well)
    These types of encoders do not provide absolute feedback .. non volatile..
    Meaning when you turn the power off you loose where you are and need to
    rehome for zero or reference to a datum switch...

    The absolute encoder we use gives an unique code (13bit max res)at which
    position it is ..

    Hi Graham.

    There are various methods to converting Gray to BIN all boil down to of course
    achieving the same goal..My method is straight from the old Ronald Tocci digital
    fundamentals book ( used at school many moons ago) I believe Don Lancaster had a similar
    method in one his books as well.
    Not being much of a C programmer .. seen some various short C code examples as well.

    Hi De Silva.

    Thanks for the starter.
    Not being an expert assembly programmer I find it easier to get something happening in Spin
    and then translate it to Assembly.. seems to work for me.

    Now here is an idea .. what about a PropSpin to Prop Assembly compiler...?
    Is that a stupid idea ?

    Cheers to all
    Ronald Nollet·· Australia
  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-09-26 03:45
    I put together a GrayCode document for one of my courses. In the doc, I give a simple method of creating/decoding GrayCodes.

    You can take a peek here:
    http://hamster.foxhollow.ca/GrayCodes/GrayCodes.htm
    http://hamster.foxhollow.ca/GrayCodes/GRAY-CODES-Final-Report.pdf
  • OzStampOzStamp Posts: 377
    edited 2007-09-26 04:43
    Hi Mark B.

    Had a peeky boo at your Final report Gray Code PDF.. a very neat document.
    Downloaded it and with your okay will put on our CD that we post out sometimes to people
    needing help with stuff...pm me or a quick post here is probably fine as well..

    My posting here as above was a simple hey this is what we are up to and not asking for any help
    but as usual and this is absolutely sensational about this Forum .. there are just so many people just wanting to
    help and share what they have done.. this is truly reflecting the spirit of the Parallax company..

    Cheers
    Ronald Nollet Melbourne Australia
  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-09-26 04:48
    sure no problem. I consider all academic material public.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-26 12:59
    Mark,
    Nice. In your research did you find an algorithm for a single track gray code? Or is that a patented item?

    Fred
  • Mark BramwellMark Bramwell Posts: 56
    edited 2007-09-26 15:04
    Our course was the analysis of existing number codes of which Gray Codes was one of them. The single track looks interesting but we did not go down that road. Since the course was 'math' and not 'engineering', we spent lots of time with proofs trying to see why the codes work or fail. Although not required, I went the extra step of building the device to show how they work in practice.

    The algorithm with the loop and bit flipping is a good way to convert natural binary to gray code binary otherwise you need to build a table.

    I think the propeller could do this without grief. The algorithm is fairly lightweight. You would read the encoder, convert it to a binary code and you could send out the response on the serial port. I am not sure if spin allows variable-based access to pins. The loop accesses 2 pins based on where it is in the loop. Since it is only 10-bit, hard-code 10-lines of code instead of the following...

    Assume: 
      NB is the integer in Natural Binary representation 
      GC is the integer in Gray Code representation 
      i = a specific bit
    
    Starting Point: 
      Initialize the Natural Binary to the value of the Gray Code; BN = GC 
    
    LOOP through the bits: 
    For i=n-1 down to i=0 
       { 
       NB(i) = NB(i)+1 XOR GC(i) 
       }
    
    




    Some questions that you must ask yourself is how you want the data sent from the propeller and how often. You could have it sent with a timed interval (every 10ms ?), non-stop or perhaps only when the codes change (if new_code <> old_ code then send_new_code)

    Post Edited (Mark Bramwell) : 9/26/2007 3:19:00 PM GMT
  • OzStampOzStamp Posts: 377
    edited 2007-09-26 23:10
    Hi Fred H

    Regarding to a single track Gray code ??
    This term is generally associated with a single track with 2 sensors slightly offset from each
    to create 2 pulses that are 90 degrees out of phase with each other.
    These encoders are commonly known as "Incremental encoders " or also as "Quadrature encoders."
    Jeff Martin from Parallax has an object that does that .. goto the object downlaod section
    Jeff references to it as a 2 BIT gray code .. his terminology is correct but it is not commonly used in the industry.
    I have communicated with Jeff re this ...it is a very neat object for this type of encoder .. check it out.

    Rgds
    Ronald Nollet Australia
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-27 00:39
    Wiki's Gray Code article shows a five sensor version of a gray code. If I understand their diagram correctly, they place the equally spaced sensors along the circumference of their pattern and read their gray code. As the disk rotates, the gray code advances. I was looking for more information and perhaps a generalized method to produce a n bit pattern.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-09-27 00:52
    Well reference 12 might be some light reading for you [noparse];)[/noparse]

    www.cs.technion.ac.il/~etzion/PUB/Gray2.pdf
Sign In or Register to comment.