News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

WS2812

Started by joesaliba, Oct 25, 2025, 05:03 PM

Previous topic - Next topic

joesaliba

I have some WS2812 and I have a problem.

No matter what colour I chose, the blue always lights up. Has anyone encountered similar problem please?

Thank you

RGV250

Hi,
I do not know if it is your issue but what xtal speed are you using as I think there are issues if it is slow.

Bob

Trikkitt

Quote from: joesaliba on Oct 25, 2025, 05:03 PMI have some WS2812 and I have a problem.

No matter what colour I chose, the blue always lights up. Has anyone encountered similar problem please?

I don't know what library you're using... but that certainly isn't a problem I've had.  However you do need make sure your timing and byte order are correct.  Perhaps you could share code, fuses and how many LEDs you're trying to drive?

Also personally I've typically offloaded WS2812 transmission where possible.

For example this is from a recent project using a 64Mhz xtal on the 18F47Q10. Then I just use an interupt to shove the buffer into the SPI interface to drive my pixels.

; NeoPixel - Disable CLC
  Clear CLC3CON

; NeoPixel - Configure Inputs
  CLC3SEL0  = 0x1A     ; PWM3
  CLC3SEL1  = 0x2E     ; SCK1
  CLC3SEL2  = 0x2D     ; SDO1
  CLC3SEL3  = 0x00

; NeoPixel - Clear ANSEL Bits

; NeoPixel - Configure
  CLC3GLS0  = 0x05  ; 00000101   CLCIN1 inverted to CLC Gate 0, CLCIN0 inverted to CLC Gate 0
  CLC3GLS1  = 0x10  ; 00010000
  CLC3GLS2  = 0x08  ; 00001000
  CLC3GLS3  = 0x20  ; 00100000
  CLC3POL   = 0x01  ; Output Gate 1 has inverted output
  CLC3CON   = 0x80  ; Enable CLC

  T2CLKCON=%00000001 ' Fosc/4
  'T2CON=%10000010 ' Timer 2 on with 1:4 post scaler
  'T2CON=%10000001 ' Timer 2 on with 1:2 post scaler
  'T2CON=%10000000 ' Timer 2 on with no post scaler
  T2CON=%10010000 ' Timer 2 on with no post scaler 1:2 prescaler
  T2HLT=0
  T2PR=0x4
  T2RST=0
  T2TMR=0

  'CCPTMRS=%10010101 ; PWM4 uses TMR4, PWM2 uses TMR2
  CCPTMRS=%10010110 ; PWM4 uses TMR4, PWM2 uses TMR2
  PWM3CON=0x80
  PWM3DCH=2
  PWM3DCL=0x40

  SSP1ADD=2
  SSP1CON2=0
  SSP1CON3=0
  SSP1MSK=0xFF
  SSP1STAT=0x40
  SSP1CON1=0x23     ; SPI Enabled, Mode SPI Master, Clock TMR2 output/2

  RB3PPS=0x1A ; Direct CLC3 output to Port B.3


To start sending data, load the LED data into LED1Data and call this routine.

SendLEDData:
  LED1ByteCount=57
  Set PIE3.0 ' enable MSSP1 (SPI) interrupts
  Set PIR3.0 ' Make sure we trigger an interrupt the moment it is enabled, no matter what.
  Return

Then this bit of code is my interrupt routine

  If PIR3.0=1 Then  ' SPI1 interrupt for Neopixels
    If ClockCount>0 Then
      Clear PIR3.0
      Dec ClockCount
      SSP1BUF=LED1Data[ClockCount]
      ;Clear SSP1STAT.0 ' Clear buffer full
    Else
      If LED1ByteCount>0 Then ' If data is waiting for LED1 then transmit that
        ClockCount=LED1ByteCount
        Clear LED1ByteCount
        Set PIR3.0  ' ### Shouldn't be needed as isn't cleared
        RB3PPS=0x1A
      Else
        While SSP1STAT.2=1
        Wend
        Clear PIR3.0 ' Clear is nothing more to send.  Otherwise this will get called again
        Clear PIE3.0 ' Turn off this interrupt
        RB3PPS=0
        Clear PORTB.3
      EndIf
    EndIf
  EndIf


Sorry it is all a bit here and there.  I pulled this from a live project i'm working on right now.  But it gives you a handy alternative.  I actually have another project that drives multiple chains of neopixels from differnet buffers using the same CLC/SPI, it just re-maps the CLC output as needed.  If your clock speed isn't 64Mhz then you'll need to rework the timings (I do have 32Mhz timings somewhere). 

joesaliba

I only did one project just for fun long time ago, I think when Les issued the first library.

I did this clock using 60 LED's, setting up the face of the clock to white, 5-minute interval to Yellow, 15-minute interval to Orange.

Using a DS3231 for time, I sent data to show the seconds in red, clearing the LED each time the second move, and so on.

It was a complex project just for fun and to train my skills.

However, now, after long time and a couple of updates to the compiler, with just 8 LED's for testing, I found a problem.

At first I thought that the problem is coming from the hardware I have.

But this morning, after several testing, I think I found that the problem is within the compiler. Not necessary a problem, perhaps it is something that has been changed for a reason.

Will keep every one updated.   

joesaliba

Can I ask which library are you using please and from where you downloaded it?

joesaliba

Check here please, I opened an anomaly issue, if it is an anomaly: -

https://protoncompiler.com/index.php/topic,3073.new.html#new