PIC32MZ + WS2812 Not Working

Moderator: Benj

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi guys,

We need your urgent help. We've got a very simple test program with 2x WS2812 LEDs, attached. We are trying to update 2x WS2812 LEDs without luck :-(

MCU: PIC32MZ1024EFE100 (Supported) and FC Version: 8.2.1.13
TEST_Program.jpg
TEST_Program.jpg (81.74 KiB) Viewed 7959 times
First to clarify, we get compiling error messages, but the HEX file is generated in the end.

Code: Select all

D:\Projects\CASHAR~1\Products\ELECTR~1\U22BEL~2\FC8\CONTRO~1\CONTROL_PCB_V1_TEST.c:262:0: warning: "MOSIPIN" redefined [enabled by default]
 #define MOSIPIN LATBbits.LATB4
 ^
D:\Projects\CASHAR~1\Products\ELECTR~1\U22BEL~2\FC8\CONTRO~1\CONTROL_PCB_V1_TEST.c:183:0: note: this is the location of the previous definition
 #define MOSIPIN LATBbits.LATB5
 ^
D:\Projects\CASHAR~1\Products\ELECTR~1\U22BEL~2\FC8\CONTRO~1\CONTROL_PCB_V1_TEST.c:267:0: warning: "MOSIBIT" redefined [enabled by default]
 #define MOSIBIT 4
 ^
D:\Projects\CASHAR~1\Products\ELECTR~1\U22BEL~2\FC8\CONTRO~1\CONTROL_PCB_V1_TEST.c:188:0: note: this is the location of the previous definition
 #define MOSIBIT 5
 ^
Configuring more than 1x WS2812 LED in Flowcode breaks the whole program.
> Only LED_A is updating on hardware.
> LED_B NEVER gets updated on hardware (no output signal).
> If we disable in Flowcode all LED_A components, still LED_B doesn't get any output on hardware.
> The issue has to be related to the compiling error messages received as with 1x LED we don't get any compiling errors at all.

Can you please help? We are unable to move forward because of this :-( Our main program has got 20+ WS2812 LED components and also not working at all. Many thanks in advance!
R
Attachments
CONTROL_PCB_V1_TEST.fcfx
(18.25 KiB) Downloaded 188 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Thanks for letting us know. I'll have a look into this for you.

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Cheers Ben!

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi ben,

Any news on this one?

R

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Hello,

I have found the cause of the problem. To speed things up I placed the IO into definitions to allow direct access to the IO without going via the standard IO function. I'm currently trying to work around the problem but it's tricky.

Do you need 20 individual output channels? Can you simply chain the various LEDs together instead?

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi Ben,

Thanks for your lines and glad you found the root cause.

Well the program has got 20x WS2812 LED channels. 16 instances are individual LEDs (as in 1x LED only per instance) and the 4 rest have got 25x LEDs each.

The 16x LED channels are not chained together I'm afraid, they are spread on 4 different custom PCBs, this way we can control the brightness of each LED individually now. The previous version of our hardware (on dsPIC33) was working fine in a similar setup with APA102 LEDs chained together instead of WS2812 ones, but brightness control was a real problem and was limiting our ability to work with them.

Many thanks for your efforts. Any workaround will do for us, thanks again!

R

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Ok thanks. I think I might have figured out a way to do it for you.

I'll have a go at this now.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

I think I've now solved the problem and allowed up to 20 individual components to live alongside each other with individual pin connections.

The timings must be the same across all components as these do not have their own individual definitions atm.

The new component is now available via the update system.

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi Ben,

Many thanks for this hofix.

It seems to work up to 1~2x concurrent LEDs. When I add a 3th of 4th LED, the timings on hardware start to stretch and the LEDs dont' respond any more.

So with 3x LEDs updating e.g. for a green colour at 0.5 brightness, total sequence timing for those 3 LEDs is 111us, whereas when I enable a 4th LED (Refresh routine), the sequence for those same first 3 LEDs stretches to 135us. When I enable a 4th LED, the timing jumps to 160us and so on...

I'm using a timer for the Refresh() routine, if I run Refresh() on the main program, the timing for each sequence is also a bit different than running it from the Timer.

The properties of the LEDs are all the same at the moment:
ws2812b_properties.jpg
ws2812b_properties.jpg (17.52 KiB) Viewed 7853 times
Thanks again for your efforts!
R

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by mnf »

If I might interrupt with a couple of suggestions: (based on some Arduino code I did in v7 - I rewrote several of the ws2812 macros...)

1) Adding a SetPixelBrightness macro for a specified pixel might allow a chain of LEDs to be used? (An array of scaling factors could be used for 'ease' of use and memory permitting - or just SetBrightness(n, scale)?

2) Scaling factor is currently a float - might a byte (0..255) scaling factor avoid the FP math and be quicker. (0 for full brightness and 1 minimum?)

3) SetAllLeds currently does the FP math for every LED in the chain so is much slower with scaling than without - it would be more efficient to pre-compute the RGB values before the loop to write to the buffer. (& see 2!)

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Hello,
So with 3x LEDs updating e.g. for a green colour at 0.5 brightness, total sequence timing for those 3 LEDs is 111us, whereas when I enable a 4th LED (Refresh routine), the sequence for those same first 3 LEDs stretches to 135us. When I enable a 4th LED, the timing jumps to 160us and so on...
Can I see your program. You can send it via PM if it's sensitive.
2) Scaling factor is currently a float - might a byte (0..255) scaling factor avoid the FP math and be quicker. (0 for full brightness and 1 minimum?)
I think I did consider this as yes FP maths would best be avoided if possible. I can have a quick play with this and see if I can improve this. The good news is the delay is only when assigning colour and not when refreshing but obviously if you are changing colour a lot then this will have an impact.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Hello,

I've now added a new scaling function which will take a byte and I've also changed the code so that the floating point calculation is always avoided when assigning colours. Hopefully should run much faster now when writing lots of new pixel values. I've updated the APA102C, WS2801, WS2811 and Grove Chainable LED components.

I've also addressed this, thanks.
3) SetAllLeds currently does the FP math for every LED in the chain so is much slower with scaling than without - it would be more efficient to pre-compute the RGB values before the loop to write to the buffer. (& see 2!)
Arrays of scaling factors could quickly get messy so for now I have left this out but something to consider for the future.

Have a play and see what you think.

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Thanks Ben for this, I've just checked it and the same problem happens. My test FC program is attached.

When refreshing 2 LEDs, the LEDs display the right colour and the timing for each LED is ~33us
2_LEDS.png
(226.05 KiB) Downloaded 2242 times
When refreshing a 3rd LED, the timings change a bit and the LEDs don't responde any more (all of them), timing is ~39us:
3_LEDS.png
(245.41 KiB) Downloaded 2242 times
Cheers,
R
Attachments
CONTROL_PCB_V1_TEST_2.fcfx
(36.13 KiB) Downloaded 117 times

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Forgot to mention Ben, the more LEDs are added and Refreshed(), the bigger the delta timing is on hardware per LED.

BTW - My PIC32MZ is running at 198MHz, not 200MHz as the Crystal is 12MHz and the PIC32 calculator gave me 198MHz for the different options, this is needed for the USB interface (Data Sheet says it must be 12MHz or 24MHz). Have created another post for the USB compiling error...

Cheers!!!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Hello,

Just to rule things out have you tried calling the code outside of the interrupt macro? Seems very strange. I've looked at your program and it looks like it should be ok.

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Sure Ben,

I've tried without interrupt of any kind, just normal <D>elay, attached the updated FC program.

2 LEDs show fine
2_LEDS_NO_INT.png
(38.92 KiB) Downloaded 2230 times
3 LEDs - LEDs don't repond (well colours are wrong)
3_LEDS_NO_INT.png
(47.94 KiB) Downloaded 2230 times
I can try anything you need on hardware, just let me know if you need anything :-)
Attachments
CONTROL_PCB_V1_TEST_3.fcfx
(31.54 KiB) Downloaded 116 times

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

1 LED refreshing
SDS00009.png
(35.96 KiB) Downloaded 2225 times
6 LEDs refreshing
SDS00008.png
(37.01 KiB) Downloaded 2225 times
Somehow the stream gets corrupted?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

I can only think that adding more LEDs is causing the LED pin to be looked up using some sort of lookup table behind the scenes.

I am currently doing the code like this.

#define LEDPIN1 LATBbits.0
#define LEDPIN2 LATBbits.1

Refresh1()
{
#define LEDPIN LEDPIN1
Output 1 to LEDPIN
Output 0 to LEDPIN
#undefine LEDPIN
}

Refresh2()
{
#define LEDPIN LEDPIN2
Output 1 to LEDPIN
Output 0 to LEDPIN
#undefine LEDPIN
}

What I could do is to remove the #define optimisation for PIC32 and this should allow multiple components to work without any #define shennanigans. I'll do this and let you know when it's ready to try.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by Benj »

Ok uploaded and ready to try now.

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi Ben,

Great, it works now as expected ;-)

I have tried 6 concurrent Refresh() updates and all LEDs work perfectly well. I'm using interrupt routine for this.

Only thing to note for anyone else trying this out... the LEDs are WS2812B, timings on data Sheet should be 50us, 0.35us, 0.9us, 0.9us and 0.35us.

In order to get those times on hardware, the settings in FC need to be as follows:
GRB_New_Settings.jpg
GRB_New_Settings.jpg (19.01 KiB) Viewed 7774 times
Measured hardware output:
WORKING.png
(148.27 KiB) Downloaded 2198 times
Just a question to you, can I tweak each LED for different timings or not yet? I need to hook up all 20x LED instances including the ones with ~1m cables and will get some feedback on that. So far for the LEDs on close PCBS it works perfectly well.

Many thanks for this fix, keep up the great work with Flowcode!
R

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi Ben,

I found a small bug, brightness control doesn't make a difference now... the colours are displayed correctly, though...

I've tried SetBrightness() and SetBrightnessByte() functions, but brightness output doesn't change when settings them after colour change and before a Refresh()

No timers are used, just plain code and a delay...

Thanks,
R
Attachments
CONTROL_PCB_LEDS.fcfx
(29.81 KiB) Downloaded 109 times

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

Hi Ben,

OK the issue came back when driving more than 9 LEDs. I have created a very simply program with no interrupts, no timers and the LEDs being driven one after the other. I was able to replicate this problem consistently. Program attached. Brightness doesn't work at the moment, so I'm fixing each call with a number rather than variable to avoid any potential problems there.

So the problem is clear... the output signal gets corrupted... not on all LEDs, but some of them.

9 LEDs being driven:
SDS00013.png
(16.66 KiB) Downloaded 2004 times
10 LEDs being driven:
SDS00014.png
(16.53 KiB) Downloaded 2004 times
Thanks for your help
R
Attachments
CONTROL_PCB_LEDS.fcfx
(62.75 KiB) Downloaded 107 times

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

FYI - The example program above is good as it's easy to reproduce the issue with it... When I run more code on our main program, I see the problem even by updating only 4~6 LEDs at the same time...

Cheers,
R

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

OK some further findings... From reading the C code output, it seems the timing for
//Data 0 High Pulse Timing : 0.200000us
is wrongly calculated? Should be 39 instructions and it's 35... I have counted all nop() and they are as from the code comments...

Code: Select all

//Data 1 High Pulse Timing : 0.500000us - 99 Instruction cycles
#define T1HNOPSDEF  nop();  (98 more times)

//Data 1 Low Pulse Timing : 0.200000us - 39 Instruction cycles
#define T1LNOPSDEF  nop(); (34 more times)

//Data 0 High Pulse Timing : 0.200000us - 35 Instruction cycles
#define T0HNOPSDEF  nop(); (34 more times)

//Data 0 Low Pulse Timing : 0.500000us - 99 Instruction cycles
#define T0LNOPSDEF  nop(); (98 more times)

ronaldlijs
Posts: 139
Joined: Tue Jan 05, 2010 10:07 am
Has thanked: 20 times
Been thanked: 25 times
Contact:

Re: PIC32MZ + WS2812 Not Working

Post by ronaldlijs »

I have tried the latest PIC32 Microchip compiler
"C:\Program Files (x86)\Microchip\xc32\v2.30\bin\xc32-gcc.exe"
with same results :-(

Furthermore, if I remove the -O1 (optimization) flag for the compiler command line, it still doesn't work, with both FC8 and Microchip's xc32-gcc

Post Reply