Faster SHIFTOUT without dedicated hardware, possible?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Faster SHIFTOUT without dedicated hardware, possible?

    Hello, I'm driving APA102 LEDs with shiftout, and while for on-off speed is ok, when I want to do some cool and fast color change, speed is not enough.
    So as I understand, SHIFTOUT is just making data pin high-low with required bits, synced with clock pulses, right?
    So maybe there's a code which can do this at faster rate, than shiftout does? without using MSSP, 18F series and so on.

  2. #2
    Join Date
    Aug 2011
    Posts
    412


    2 out of 2 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Faster SHIFTOUT without dedicated hardware, possible?

    Sure.

    Here's some code that would shift out a byte without using asm or anything special... should be much faster than SHIFTOUT since it's format is dedicated and loop is unrolled. Just set WREG to the value to shift out and call SHOUT.

    Code:
    SHCLK var PORTB.0
    SHDAT var PORTB.1
    
    ; init pins to output low
    low SHCLK
    low SHDAT
    
    ; send $55
    WREG = $55
    call SHOUT
    
    ; send $AA
    WREG = $AA
    call SHOUT
    
    
    ; SHOUT
    ; shift out 8 bits of data, LSB to MSB
    ; data clocked on rising edge of SHCLK
    ; WREG = data to send
    SHOUT:
    SHDAT = 0
    if WREG.0 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.1 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.2 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.3 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.4 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.5 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.6 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    SHDAT = 0
    if WREG.7 then
      SHDAT = 1
    endif
    SHCLK = 1
    SHCLK = 0
    
    return
    That would be the equivalent of
    SHIFTOUT SHDAT, SHCLK, LSBFIRST, [bval/8]
    Last edited by tumbleweed; - 27th July 2022 at 12:31.

  3. #3
    Join Date
    Aug 2011
    Posts
    412


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Faster SHIFTOUT without dedicated hardware, possible?

    You may find that routine is actually too fast for the hardware you're controlling.
    If so, you can add NOPs to slow it down a bit...
    Code:
    SHDAT = 0
    if WREG.0 then
      SHDAT = 1
    endif
    asm NOP endasm
    SHCLK = 1
    asm NOP endasm
    SHCLK = 0
    asm NOP endasm

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Faster SHIFTOUT without dedicated hardware, possible?

    Thanks, that's great!
    So if we can replace SHIFTOUT with faster code easily, maybe there is a such way for I2CREAD too? without using MSSP module?

  5. #5
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: Faster SHIFTOUT without dedicated hardware, possible?

    I2C operations are slower to begin with, but you could speed things up over the stock routines.

    Having the pins be set in software is what usually slows things down. I've implemented these before and ended up with something around 240KHz with programmable pins.
    Dedicated pins speeds it up a lot... think I got around 400KHz doing it that way (running at 64MHz).

    You have to watch out with the speed and open-drain IO operation to size the pullups as required.
    For faster speeds I like to use active pullups which can really speed up the low-to-high transitions vs using a resistor.
    This works out well when using the MSSP since you can get much faster speeds there.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Faster SHIFTOUT without dedicated hardware, possible?

    Well, I tried to use MSSP, but no luck, so this is why I'm asking.
    Current I2CREAD is too slow, it runs at about 50khz (and is NOT oscillator dependent, as someone stated, I checked with scope, it is around 50khz at 4mhz, 8mhz or 16mhz oscillator speed).
    200Khz would be fine for me. I'm using 24C64 as an external font data storage, and at current speed (50khz), reading 1kb of data takes about 1 second, which does looks cool at certain moment - you see how letters are being drawn on the screen, but absolutely not cool for long-time usage.

Similar Threads

  1. Replies: 29
    Last Post: - 20th May 2010, 03:47
  2. Is there a faster way to compare?
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th February 2010, 19:48
  3. Dedicated LCD Controller question
    By chuckles in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th February 2006, 14:44
  4. Is there a faster/better way of doing this?
    By Mad_Labs in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th October 2005, 11:01

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts