Shop OBEX P1 Docs P2 Docs Learn Events
SPIN performance — Parallax Forums

SPIN performance

ftkalcevicftkalcevic Posts: 10
edited 2009-12-09 00:59 in Propeller 1
Sorry if this has been discussed elsewhere, but I just can't get this forum's search to work for me.

I'm trying to write an SPI slave implementation in SPIN, but the data I'm receiving isn't anything like what appears on the wire.· This is a stripped down version of my code...

· repeat
··· b := 0
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 1
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 0
··· repeat 32
····· b <<= 1
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 0
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 1
····· if ina[noparse][[/noparse]MOSI_PIN] == 1
······· b |= 1
··· vt100.PrintHex( b, 8 )
··· vt100.PrintString(string(13))
···
I wait for CS to go low, then read the bits as the clock goes high.·

The SPI is clocked at 125kHz.· Is this too much for SPIN?· Do I need to use PASM (when I get it working I want to up the clock to 1MHz)

Thanks,
Frank
·

Comments

  • heaterheater Posts: 3,370
    edited 2009-12-09 00:45
    I'm pretty sure this is a job for PASM.
    Spin is going at something like 100 instructions per statement, last I heard.
    Perhaps using waitpeq and friends to wait for pin states rather than repeat loops would do it in Spin (see the manual).
    For 1MHz definitely PASM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • ftkalcevicftkalcevic Posts: 10
    edited 2009-12-09 00:48
    Thanks heater. I love how quickly people reply on this forum.

    Originally I used waitpeq, but got the same results. I'll start playing around with PASM.
  • heaterheater Posts: 3,370
    edited 2009-12-09 00:55
    Just now I'm doing some funky serial communication protocol at 5Mbit/s.
    That's just exactly 4 instructions for Tx and 4 for Rx on an 80MHz Prop. Just works nicely.

    I guess there is a SPI driver or two in OBEX. You could look at those to see how the bit sampling goes even if they are the master end. Have a look at the SD card low level driver in FSRW.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • lonesocklonesock Posts: 917
    edited 2009-12-09 00:59
    ftkalcevic said...
    ...
    repeat 32
    b <<= 1
    repeat until ina[noparse][[/noparse]SCK_PIN] == 0
    repeat until ina[noparse][[/noparse]SCK_PIN] == 1
    if ina[noparse][[/noparse]MOSI_PIN] == 1
    b |= 1
    ...
    Just a note: even using waitpeq and friends (and I definitely recommend switching to them), you have an IF, OR, Repeat, SHL all happening after the clock pin goes high. You can split those so that some of the action happens after the CLK went low. Better yet, you could combine the SHL IF and OR into a single command:
    b += b + ina[noparse][[/noparse]MOSI_PIN]
    


    b +=b is the same as multiplying by two, which is the same as SHL by 1. And adding the actual value of the bit adds a 1 if the bit is high, and adds a 0 if it's low. You may want to check for CLK hi, then do the above line, then check for CLK low, then let it repeat, that way the overhead of the repeat can be concurrent with the CLK pin being low.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
Sign In or Register to comment.