Shop OBEX P1 Docs P2 Docs Learn Events
Bit Banging from TAQOZ — Parallax Forums

Bit Banging from TAQOZ

@"Peter Jakacki", @JonnyMac and others. This may seem a lazy post, but things have been busy for a while and totally upended a couple weeks ago, so I probably missed it in the threads. I am looking for how to bit bang a string of data bits, for example the neopixel ring or other things from the P2 using TAQOZ. If anyone knows of a thread detailing how it can be done, with an example or two I would appreciate it. Thanks to all.....

Comments

  • I don't know how to do this in TAQOZ, but I can show you how I do it with inline PASM2; if Peter hasn't yet built in WS2812 support, you may be able to translate this.

    con
    
    ' CLK_FREQ = 200_000_000
    
    ' US_001   = CLK_FREQ / 1_000_000
    
      WSTR     = US_001 *  250                                      ' reset timing
      WST0     = US_001 *  400 / 1000 - 8                           ' 0 bit timing
      WST1     = US_001 *  800 / 1000 - 8                           ' 1 bit timing
      WSTC     = US_001 * 1250 / 1000                               ' cycle ticks @ 800kHz
    
    
    pub ws2812b(pin, count, p_colors) | outval, rgswap, cycle
    
    '' Update WS2812b strip on pin
    '' -- count is # of LEDs on strip
    '' -- p_colors is pointer to colors (array of longs)
    ''    * uses $RR_GG_BB_00 color format
    
      org
                    drvl      pin                                   ' make output
                    waitx     ##WSTR                                ' allow reset
    
    led_loop        rdlong    outval, p_colors                      ' get color
                    add       p_colors, #4                          ' point to next
    
                    movbyts   outval, #%%2310                       ' swap R and G bytes
    
                    getct     cycle                                 ' start timing frame
    
                    rep       @.bitz, #24                           ' 8 bits x 3 colors
                     shl      outval, #1                    wc      ' get MSB
                     drvh     pin                                   ' pin on
        if_nc        waitx    ##WST0                                ' hold for bit timing
        if_c         waitx    ##WST1
                     drvl     pin                                   ' pin off
                     addct1   cycle, ##WSTC                         ' update cycle timer
                     waitct1                                        ' let cycle finish
    .bitz
    
                    djnz      count, #led_loop                      ' do next LED
      end
    
  • Thank you Jon.

    Between what you put up and what I just found in Peter's TAQOZ doc, I may be able to figure this out. Let y'all know how it turns out.

  • @"frank freedman" Sorry, I've been totally tied up for the past week. This kind of bit banging is fairly easy and assuming you P2 clock is 200MHz, you could try this quick and dirty one-liner.
    : PIXELS ( src bytes -- ) L ADO I C@ 12 COG@ 8 FOR H H H LSBOUT NOP L NEXT 2DROP LOOP ;
    The main thing with timing is to remember the decode in the pixel is fairly simply and the lohi is necessary to clock a bit using a delay which I breakdown to bit period into 3 parts: a high, the data bit, a low.
    If you want top call this continually just remember that it needs at least 50us before the start of a new transmission.

    This above just uses a byte buffer, so 3 bytes per pixel but if you want a long for each pixel then it is simply this:
    : PIXELS ( src longs -- ) L ADO I @ 12 COG@ 24 FOR H H H LSBOUT NOP L NEXT 2DROP 4 +LOOP ;

    With 8 Neopixels on P8 and a the pattern held in BUFFERS I would type 8 PIN BUFFERS 24 PIXELS

    I have the Neopixels running in Tachyon, so I may just get to check out some code later on and post that here.

  • frank freedmanfrank freedman Posts: 1,975
    edited 2021-03-29 05:32

    Thank you Peter. No worries, no rush. Hope all is well where you are. Got shown Forth in the early 80's, not sure what to do with it then, now starting to make sense. Also now a faster way to make use of the P2 for now.

  • BTW, I'm just about to update the binary and other files. I also added a simple WSTX instruction which takes a buffer address and byte count just as it did in Tachyon. On my Neopixel strip the order is green,red,blue. At the start of each transmission it calculates the timing required for the current clkfreq as well. Just set the pin or pin range that you want.

    TAQOZ# 33 PIN BUFFERS 24 WSTX ---  ok
    TAQOZ# BUFFERS 24 LAP WSTX LAP .LAP --- 52,896 cycles= 264,480ns @200MHz ok
    TAQOZ# 320 clkfreq! ---  ok
    TAQOZ# BUFFERS 24 LAP WSTX LAP .LAP --- 80,544 cycles= 251,700ns @320MHz ok
    TAQOZ# 100 clkfreq! ---  ok
    TAQOZ# BUFFERS 24 LAP WSTX LAP .LAP --- 29,856 cycles= 298,560ns @100MHz ok
    
Sign In or Register to comment.