Shop OBEX P1 Docs P2 Docs Learn Events
Manipulating Bits in a LONG - Page 2 — Parallax Forums

Manipulating Bits in a LONG

2»

Comments

  • RobertDyerRobertDyer Posts: 23
    edited 2013-07-23 08:55
    OK guys, HELP!! I'm stuck. I've attached a file of my latest try. I've reduced my code down to the minimum number of lines, the simplest I can think of, to light all 8 of the WS2812s of my Adafruit NeoPixel Stick as a simple test - nothing fancy at all! I just want to turn on all 8 LEDs white at full brightness - 24 bits of 1's. I know something is happening because the output pin is twiddling. (I can only see this with my digital volt meter - I don't currently have a scope to check timing.) My hardware is a Propeller Board of Education. I'm using pin 14. I've checked the output voltage and it is 5V. I've tried various values of the 1-bit high and low values, but still no light! I must be missing something very basic and simple. What is it???? Also, I couldn't read the codes you sent telling me how to cut and paste formatted code into a window. Thanks! Robert
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-07-23 09:57
    Maybe you are just to perfect with timings and are pushing the upper limit of 800kHz operation frequency?
    Try to change to
    _T1L long 52 ' clock cycles low for a one bit (0.6uS)

    and you could also change:
    sub BitCntr, #1 wz ' test for last bit
    if_nz jmp #BitDisplayLoop ' if done fall thru

    can be replaced with
    djnz BitCntr, #BitDisplayLoop
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-07-23 10:01
    Code like this can be simplified:
    sub     BitCntr, #1       wz  ' test for last bit
                      if_nz jmp     #BitDisplayLoop       ' if done fall thru
    


    to this:
    djnz    BitCntr, #BitDisplayLoop
    


    I've attached an archive with my driver and a demo -- give it a try to see if it works for you. It works with the NeoPixels (see pic in post #25), so it should work with the stick. You'll need to adjust the call to the start method to 8 to match the LEDs in the stick.
  • RobertDyerRobertDyer Posts: 23
    edited 2013-07-23 10:27
    Tony and Jon, SO WEIRD!!!!!!!!!!! I tried all your suggestions - nothing had helped up to that point. (Thanks though!!) I had loaded your code, Jon, having changed the number of LEDs and also played with the output pin, both to no avail. I was just writing this response when the mini-fridge next to my bench turned off. It occasionally spikes the power when that happens. As soon as it did, the LED strip came on! (First time I've ever had a power spike help me!!) The stick is busy changing colors in unison, though the longer it runs the more sporadic the colors get and some of the LEDs are jittering various colors as the strip changes. It just stopped after a couple minutes of steady running with one LED blue and a couple others barely on (orange, pink and red). Now it just started again going through the colors, but again with some jittering. (The fridge is still off.) I'll start playing with all my power connections. Do you guys have any ideas what might be happening? I'm kind of afraid to touch anything since it is working after a fashion. ;)) Thanks again. Robert
  • RobertDyerRobertDyer Posts: 23
    edited 2013-07-23 10:39
    OK, so I disconnected the wall-wart from the Prop-BOE, and it appears that your code is working perfectly Jon. I'm guessing I had some sort of a ground loop. I have NO idea how the LEDs are running so brightly on just the USB power, but all appears to be working now. Thanks again for all your help. I'll keep working away on my own code now that it appears that THIS problem is solved. Who knew.... btw, nice display Jon. Really cool! Robert
  • RobertDyerRobertDyer Posts: 23
    edited 2013-07-25 00:20
    Tubular wrote: »

    BTW the B version of the WS2812 (WS2812B) is extremely easy to solder, because it has 4 pins rather than 6 (one pin in each corner, spread relatively far apart). Its more like a 0.1" pitch. I have 1000 on order, hope to see them soon. I can send you some when they arrive if you like (and anyone else that wants a few samples)
    Hey Lachlan, Have your WS2812Bs come in yet? Are you going to be ordering more? I would definitely be interested in buying 600 of them. Robert
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-17 18:34
    JonnyMac,

    Thanks for another LED driver. I just received a few of these from AdaFruit and I've been playing with your code.

    I noticed you changed your "color" method between post #25 and post #34.

    The code attached to post #34 has this color method (the driver in the OBEX also uses this code).
    pub color(r, g, b)
    
    '' Packs r-g-b bytes into long
    
    
      result.byte[2] := r                                           ' r << 16
      result.byte[1] := b                                           ' b << 8
      result.byte[0] := g                                           ' g << 0
    
    
    

    My guess is the chip's strange color order crept into the Spin portion of the driver.

    The file attached to post #25 has this code.
    pub color(r, g, b)
    
    '' Packs r-g-b bytes into long
    
    
      r := $00 #> r <# $FF                                          ' fix bad values
      g := $00 #> g <# $FF
      b := $00 #> b <# $FF  
    
    
      return r << 16 | g << 8 | b                                   ' pack
    
    
    

    The above code packs the long as I expect you intended.

    The NeoPixel wheels from AdaFruit have been a lot of fun to play with. I've been trying to find some hypnotic effects with these circles. I have what I think is a fun algorithm. I'll try to post a video of it in action soon.

    Thanks again for sharing your code.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-08-17 19:29
    Thanks for pointing that out, Duane -- it was just a typo on my part. I have to be more careful during my "make it pretty" edit phase!

    I've fixed and uploaded new code to ObEx.
Sign In or Register to comment.