Positive ranting please submit here..
Hi Guy's and girls...
I have never been an expert·in bit bashing·..
But resort to it when raw speed is needed..
Never learnt C and will never have the time now.. so prefer to be in full control
down to the core if needed...
I like to see here in this thread positive rant only on ·the awesome assembler programming
that is possible with the Propeller..
Saw an seasoned "experienced" programmer yesterday and we shared some stuff ..over a coffee
and a cake..how boring is that... talking about assembler lingo...
This·customer of ours and myself have been playing with a small project that requires
sampling of an high resolution SSI encoder ( yes we have spoken along similar lines before)
Now the task is to sample this encoder SSI interface at speeds above 300KHZ or higher..
( a minimum pulse rate between CLK pulses of 100KHZ is a spec of this protocol)
It is like a CLK·· DATA interface· (RS422 type)·
The data the encoder sends back is absolute positional data and is 13...17bits(selectable)..
The data for obvious reasons is in GRAY code ( Kudo's to Mr Frank Gray)··
Now sampling the CLK DATA is easy... just looping· + collecting...
Don't you love the 32 bits ... awesome ( positive rant only)
The tricky bit is converting the GRAY code back to Binary ..
And to do it fast .. effecient code is required...( okay you GURU"S it maybe easy
if you have done it before)
We did this years ago with a SX28 dipper and the code was based on
shifting the GRAY· left ..collecting the initial MSB ..carry and doing the rest ...
We used the PC + W jmp instruction· .. effectively EXORING collected flags
and updating the NEW BINARY register...
Anyway to cut a long story short... we grabbed the SX code· ... woow we
do not have a PC+ W jump in Propeller... a quick astute customer noticed the
awesome· conditional IF conditions that can be used with instructions like
OR·· XOR·· AND· TEST...
So if you set up a mask bit...( picking on a particular bit in a LONG)
and also picking on another bit using a different·instruction so that you
end up with code like..( this is Xoring aligned bits ..GRAY to BIN CODE conversion..)
IF_C_and_Z····· jmp #do this task 1
IF_C_and_NZ··· jmp #do this task 2
IF_NC_and_Z··· jmp #do this task 3
IF_NC_and_NZ· jmp #do this task·4
You get blazing fast conversion rates in very little code...
Just some moving of the mask bits above the code listed and your away.
We tested some 10bit gray codes and ran the code .. looking at it with
a scope ..the rates are impressive... still fine tuning other associated code...
The interesting part of this little project is that the Propeller does
all these things and some other totally not related stuff as well.
It runs some simple logic on a couple of inputs and spits out pulses
to some DC solenoids at all high rates... no interrupts.... loving it..
Okay people·· .. my good deed for the day done..
More positive rants here please.
Cheers
Ron···Nollet··· Melbourne OZ..
Post Edited (OzStamp) : 12/5/2007 6:17:27 AM GMT
I have never been an expert·in bit bashing·..
But resort to it when raw speed is needed..
Never learnt C and will never have the time now.. so prefer to be in full control
down to the core if needed...
I like to see here in this thread positive rant only on ·the awesome assembler programming
that is possible with the Propeller..
Saw an seasoned "experienced" programmer yesterday and we shared some stuff ..over a coffee
and a cake..how boring is that... talking about assembler lingo...
This·customer of ours and myself have been playing with a small project that requires
sampling of an high resolution SSI encoder ( yes we have spoken along similar lines before)
Now the task is to sample this encoder SSI interface at speeds above 300KHZ or higher..
( a minimum pulse rate between CLK pulses of 100KHZ is a spec of this protocol)
It is like a CLK·· DATA interface· (RS422 type)·
The data the encoder sends back is absolute positional data and is 13...17bits(selectable)..
The data for obvious reasons is in GRAY code ( Kudo's to Mr Frank Gray)··
Now sampling the CLK DATA is easy... just looping· + collecting...
Don't you love the 32 bits ... awesome ( positive rant only)
The tricky bit is converting the GRAY code back to Binary ..
And to do it fast .. effecient code is required...( okay you GURU"S it maybe easy
if you have done it before)
We did this years ago with a SX28 dipper and the code was based on
shifting the GRAY· left ..collecting the initial MSB ..carry and doing the rest ...
We used the PC + W jmp instruction· .. effectively EXORING collected flags
and updating the NEW BINARY register...
Anyway to cut a long story short... we grabbed the SX code· ... woow we
do not have a PC+ W jump in Propeller... a quick astute customer noticed the
awesome· conditional IF conditions that can be used with instructions like
OR·· XOR·· AND· TEST...
So if you set up a mask bit...( picking on a particular bit in a LONG)
and also picking on another bit using a different·instruction so that you
end up with code like..( this is Xoring aligned bits ..GRAY to BIN CODE conversion..)
IF_C_and_Z····· jmp #do this task 1
IF_C_and_NZ··· jmp #do this task 2
IF_NC_and_Z··· jmp #do this task 3
IF_NC_and_NZ· jmp #do this task·4
You get blazing fast conversion rates in very little code...
Just some moving of the mask bits above the code listed and your away.
We tested some 10bit gray codes and ran the code .. looking at it with
a scope ..the rates are impressive... still fine tuning other associated code...
The interesting part of this little project is that the Propeller does
all these things and some other totally not related stuff as well.
It runs some simple logic on a couple of inputs and spits out pulses
to some DC solenoids at all high rates... no interrupts.... loving it..
Okay people·· .. my good deed for the day done..
More positive rants here please.
Cheers
Ron···Nollet··· Melbourne OZ..
Post Edited (OzStamp) : 12/5/2007 6:17:27 AM GMT
Comments
I really enjoyed working in Melbourne and Sydney these past years. We need more of that attitude here in this forum.
Let's get on with solving real world problems with the silicon Parallax has provided us...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
A major speed-up and code saving came from making the long in Hub not an index but a pointer to the handler address within the Cog. But how to set that up in Spin ? Turned out to be easy, and even nicer when it's hidden in a function ...
I'll tell you about some other problem. For the LMM kernel, I need to save the flags... and restore them. The deal went down to 4 instructions, from some 6 or so:
As the restore of flags does not clear krnl_flags, I couldn't get rid of the first mov... After some deep thought... I remembered mux, it sets bits according to flags !!
Restoring flags is the same shr krnl_flags,#1 wc wz
I know i saved 1 long, but at the same time... I used an instruction I never used before
To complete the kernel I'll have to pull almost every trick know to man... It will be fun.
Just to follow up on my first post re converting GRAY to BIN.
Wev'e just run some tests on a 13 bit GRAY number .
Conversion rate confirmed to be about 120-125 KHZ..(at 80MHZ)
Looking at the data sheet and adding the "Ticks" each instruction will take
the 2 correlate nicely...
Next task is to glue all my code samples together into a single object..
ie >> sampling the actual SSI encoder
·· >>·converting the sampled data from GRAY to BIN
·· >>· send the data to a serial port ..( using the Full Duplex object probably)
Fred H.
It is strange even for me to celebrate Christmas whilst it can be hot..
Today it is 23-28 Celsius...summertime has started..
Originally from Europe ( cold and windy Holland)· ..great place though
just to many Dutchies...they are called CLOG WOGS here..
Still miss the snow at this time of the year..and mums PEA SOUP as well.
Quantum
If your ever down this way .. make sure you pop in and say hello.
Cheers people·
Keep those interesting snippits of code coming guy's.
Ron Nollet··· Melbourne· OZ..
·
If your doing stuff with SSI encoders..you will find that there is 2 pairs of cables
for the comms part of it..
These are labelled Clock + CLOCK- and Data + Data- so it requires a 4 wire
interface ie you can use for example 2 off 75176B RS422/485 drivers..
But a neater way is to use the MAX490 available in 8 PIN DIP..
It has a sender and receiver in it .. the layout of the pins is awesome for PCB layout.
Check it out people..... from MAXIM the MAX490-CPA...
Cheers Ron Melbourne OZ