Shop OBEX P1 Docs P2 Docs Learn Events
Positive ranting please submit here.. — Parallax Forums

Positive ranting please submit here..

OzStampOzStamp Posts: 377
edited 2007-12-06 21:37 in Propeller 1
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

Comments

  • Mike HuseltonMike Huselton Posts: 746
    edited 2007-12-04 02:58
    A refreshing attitude in lieu of the recent posts. The whining got really old.

    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
  • hippyhippy Posts: 1,981
    edited 2007-12-04 06:12
    I spent ages trying to work out how to improve a jump table, mainly to save space. This is part of my Music Synth project so it reads 'tasks' from Hub and needs to vector off to a handler, effectively JMP PC+W ...

    MyCogCode org    0
    
    Loop      rdlong idx,PAR
              add    idx,#JumpTable
              jmp    idx
    
    JumpTable jmp    #Handler0
              jmp    #Handler1
               :        :
              jmp    #HandlerN
    
    
    



    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 ...

      hubJumpTo := SetAddress( @Handler0 )
      Pause_mS(100)
      hubJumpTo := SetAddress( @Handler1 )
    
    PRI SetAddress( atCogAddress )
      result ( atCogAddress >> 2 ) - ( @MyCogCode >> 2 )
    
    
    



    MyCogCode org    0
    
    Loop      rdlong idx,PAR
              jmp    idx
    
    
  • AleAle Posts: 2,363
    edited 2007-12-04 07:44
    Avoiding the jump table..., thanks hippy !, is a nice way of saving some very useful longs.

    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:

    ' save flags
          mov krnl_flags,#0
     if_c or krnl_flags,#1
     if_z or krnl_flags,#2
    
    ' restore flags, two flags in one instruction
          shr krnl_flags,#1 wc wz
    
    



    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 !!


    'save flags
          muxc krnl_flags,#1
          muxnz krnl_flags,#2
    
    



    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 wink.gif

    To complete the kernel I'll have to pull almost every trick know to man... It will be fun.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-12-05 00:35
    OT, but it did wake me up yesterday morning: Oz, what sort of imagery surrounds Santa in the southern hemisphere? (Jingle bells doesn't seem to fit summertime at all)
  • OzStampOzStamp Posts: 377
    edited 2007-12-05 02:27
    Hi to all..
    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..

    ·
  • OzStampOzStamp Posts: 377
    edited 2007-12-06 21:37
    Hi All.

    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
Sign In or Register to comment.