Shop OBEX P1 Docs P2 Docs Learn Events
shiftout speed — Parallax Forums

shiftout speed

Scott MScott M Posts: 43
edited 2009-04-23 21:02 in General Discussion
How quickly does a shiftout send bits? If the doc describes this, I missed it.

Is there any way to do shiftout as a VP? It would be wonderful to be able to throw bits at a VP and have them sent in the background, just like a serial port...

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-08 07:10
    Shiftout is about 100 kHz (individual byte) I think. It can not be used as a background VP.

    However, the limiting factor is the ram access time. I have found that for

    tansmitting a stream of bytes, the throughput is limited to about 10k·baud

    (or 1000-1200 bytes per second).

    Try timing to read an array of 10000 bytes like

    char[noparse]/noparse myarray = new char[noparse][[/noparse]10000];

    char c;

    for (int i=0; i<10000; i++) {

    · c = myarray[noparse][[/noparse]i];

    }

    and you find the maximum throughput.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-04-23 20:39
    Hi Peter,

    Regarding the ShiftOut/ShiftIn, do we have a way to slow it? It's a native methode, so I was not able to check it.

    If we can't slow it, do we have a way to reproduce this methode by software?

    Thanks,

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-04-23 20:55
    You can use CPU.writePin() and CPU.readPin to mimic
    a shift function.

    void ShiftOut(int clkPin, int dataPin, int value, int bits, int mode) {
    · boolean clkState = CPU.readPin(clkPin);
    · //mode CPU.SHIFT_LSB·is assumed here
    · for (int i=0; i<bits; i++) {
    ··· boolean bit = (value & 0x0001) !- 0;
    ··· CPU.writePin(dataPin,bit);
    ··· CPU.writePin(clkPin,!clkState);
    ··· CPU.writePin(clkPin,clkState);
    ··· value >>= 1;
    · }
    }

    You'll just have to figure out when to raise and lower the clockpin
    according to mode (CPU.SHIFT_LSB, CPU.SHIFT_MSB).

    For ShiftIn() you can create a simular function.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-04-23 21:02
    Perfect, thanks.

    I will use that, do the same for shiftIn and add some delay between the clkPin stats changes.

    Regards,

    JM
Sign In or Register to comment.