PDA

View Full Version : Reading an absolute encoder with 9 bit Parallel ouput.. spin code .. need to co



OzStamp
02-09-2007, 05:14 PM
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

Paul Baker
02-10-2007, 01:28 AM
Ive got a neat trick for you, to get a pre-masked copy of ina[0..8] use MOVS with ina for the source. Your complex case statement is another story however.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

Mike Green
02-10-2007, 01:33 AM
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.

JoannaK
02-10-2007, 04:10 AM
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

OzStamp
02-10-2007, 09:30 AM
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

OzStamp
02-10-2007, 01:27 PM
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

JoannaK
02-10-2007, 05:04 PM
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[12..9] rather than outa[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

OzStamp
02-10-2007, 08:07 PM
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 [12..9] := Mydata [ina [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