Shop OBEX P1 Docs P2 Docs Learn Events
Reading an absolute encoder with 9 bit Parallel ouput.. spin code .. need to co — Parallax Forums

Reading an absolute encoder with 9 bit Parallel ouput.. spin code .. need to co

OzStampOzStamp Posts: 377
edited 2007-02-10 13:07 in Propeller 1
Hi All

Thought I share this project with all you Prop heads..

I have attached a file .. started having a play with an absolute encoder
that we will be using on a little project with a local customer here in OZ..
The encoder has a 9 bit parallel output ( it is a renishaw magnetic absolute encoder)
Very robust device excellent for very harsh enviroment applications.

See the attached file it explains all as to what has been done and what we
would like to do.
Trying to get my brain to come up with a neat way to do this in asm..
Spin is probably fast enough for the initial application but in ASM it would
open up more applications .. like high speed cam controller swithces etc etc ..

Ronald Nollet··· Australia

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-09 18:28
    Ive got a neat trick for you, to get a pre-masked copy of ina[noparse][[/noparse]0..8] use MOVS with ina for the source. Your complex case statement is another story however.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-09 18:33
    There's lots of room for improvement even in Spin. For example, the CASE statement is fairly inefficient, particularly when there are lots of choices. Better would be a 512 byte table with entries classifying each entry type, particularly when there are only a few possible choices for actions. So much depends on what you actually want to do for a given position.
  • JoannaKJoannaK Posts: 44
    edited 2007-02-09 21:10
    I would suggest improving Spin code first.. Mike's table lookup is most likely fastest way to do it.. I might also take advantage of input value symmetry.. (limiting table/Case size)

    for example.. (not real spin code.)
    temp :=input
    if temp >256
    temp := temp-256

    (now case structure should be half as small, and thus somewhat faster).

    Post Edited (JoannaK) : 2/9/2007 9:44:25 PM GMT
  • OzStampOzStamp Posts: 377
    edited 2007-02-10 02:30
    Hi
    Had another stab at it .. why not break up the code and share the task using 3 COGS.
    So have knocked up the attached spin file ... not tested but compiles okay.

    First attempt ran okay pretty fast even with all the case statements.
    Should run faster now.
    Could work even faster with 6 COGS ... need 4 other cogs for something else..
    so 3 cogs is the max I wanna use for this project..



    Ronald Nollet
    Australia
  • OzStampOzStamp Posts: 377
    edited 2007-02-10 06:27
    • Hi All
    • Decided to do the lookup table method as well. The whole 512 bytes....
    • Using 1 COG only...( would this in 1 COG if done in assembler ??? 512 Bytes· of DATA???)
    • The Spin file is attached for reading the 9 bit absolute encoder
    • All the data that I need for this project is loaded as well.
    • 1 line of SPIN ( with some help from Mike Green awhile ago) points to the lookup table.
    • Program attached complies okay not wired up as yet but should work okay.
    • Ronald Nollet··· Australia
  • JoannaKJoannaK Posts: 44
    edited 2007-02-10 10:04
    This one should be a lot faster, you may not need to do Asm version. Table looks good but I'm not sure if the output bit order might be outa[noparse][[/noparse]12..9] rather than outa[noparse][[/noparse]9..12] ?


    For assembler version.. (1 cog)
    - Code size ain't problem.
    - Data table could be stored by Nibbles,. => 512 long table would use only 64 Long's of cog memory


    For shorter table, see Sin/Cos table lookup routines for reference. There's only one table and that 1/4th of a full circle. In this case.. I'd say 1/2 would be easy and 1/6 quite doable. In this case the table size dosn't matter a lot, but if there were other code running on same cog it might
  • OzStampOzStamp Posts: 377
    edited 2007-02-10 13:07
    Hi·· JoannaK

    Have tested the code and wired it up on a PRO DeV board from Parallax· + USB PropStick..

    Your right the outa format is the wrong way around.

    should be >>········· ·outa [noparse]/noparse]12..9] := Mydata [noparse][[/noparse]ina [noparse][[/noparse]8...0

    Works wonderfull... awesome fast ..not·sure how fast it samples·..·but good enough

    HAd a lookup table ready for 8 bit gray to dec ready so it was not such a big job after all.

    The Propeller editor is cool being able to copy and paste and insert/overwrite/replace ·etc etc

    Jeff Martin did a awesome job on that..

    Still will work on getting this into asm .. need to sort an algo to do a zone compare function.

    Ronald Nollet··· Australia
Sign In or Register to comment.