View previous topic :: View next topic |
Author |
Message |
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sun Aug 26, 2018 1:33 pm |
|
|
If you use the 'search' button on the top, keyword 'ws2811' you'll get 5 or 6 hits so some code does exist though maybe for a diferent PIC. It'd be a starting point though...
Jay |
|
|
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
ws2811 CLC |
Posted: Sun Aug 26, 2018 2:37 pm |
|
|
You are right.
I have PIC running with ws2811, using SPI, but it takes to much cpu power.
Could be great to use CLC, and only one spi byte pr. byte instead of 8.
/john |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 26, 2018 4:47 pm |
|
|
They give you sample code at the end of the appnote. The code consists
of loading PIC registers with numbers. You could declare the register
addresses with #byte statements and then use their exact routine.
You could translate it to CCS later if you wanted to, but this would get you
up and running quickly.
Example:
Code: |
#include <16F1509.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT
#use delay(clock=4M)
#byte CLC2GLS0 = getenv("SFR:CLC2GLS0")
#byte CLC2GLS1 = getenv("SFR:CLC2GLS1")
#byte CLC2GLS2 = getenv("SFR:CLC2GLS2")
#byte CLC2GLS3 = getenv("SFR:CLC2GLS3")
// Add the remaining registers listed in the appnote routine.
//----------------------------
void WS2811_Init(void)
{
CLC2GLS0 = 0x20;
CLC2GLS1 = 0x00;
CLC2GLS2 = 0x00;
CLC2GLS3 = 0x00;
// copy the rest of their routine from the appnote.
}
//====================
void main(void)
{
WS2811_Init();
while(TRUE);
} |
|
|
|
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
|
Posted: Mon Aug 27, 2018 1:17 am |
|
|
Hi PCM programmer
Tnx. Good point, I will try this evening.
/john |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Aug 27, 2018 1:42 am |
|
|
The CCS code to build the CLC logic, should be:
Code: |
clc2_setup_input(1, CLC_INPUT_0);
clc2_setup_input(2, CLC_INPUT_0);
clc2_setup_input(3, CLC_INPUT_6); //selects PCM1 out as input
clc2_setup_input(4, CLC_INPUT_0);
clc2_setup_gate(1, CLC_GATE_NON_INVERTED_INPUT_3);
clc2_setup_gate(2, CLC_GATE_SET);
clc2_setup_gate(3, CLC_GATE_SET);
clc2_setup_gate(4, CLC_GATE_SET); //For AND, the unused bits must be on
setup_clc2(CLC_MODE_AND | CLC_ENABLED); //output this
clc4_setup_input(1, CLC_INPUT_0); //SCK & SDO
clc4_setup_input(2, CLC_INPUT_5);
clc4_setup_input(3, CLC_INPUT_5);
clc4_setup_input(4, CLC_INPUT_0); //setup inputs
clc4_setup_gate(1, CLC_GATE_INVERTED_INPUT_4 | CLC_GATE_INVERTED_INPUT_2 | CLC_GATE_OUTPUT_INVERTED);
clc4_setup_gate(2, CLC_GATE_INVERTED_INPUT_3);
clc4_setup_gate(3, CLC_GATE_NON_INVERTED_INPUT_4);
clc4_setup_gate(4, CLC_GATE_NON_INVERTED_INPUT_3);
setup_clc4(CLC_OUTPUT | CLC_ENABLED);
|
Setup the PWM to twice the bit rate and that should be all you need.
It is potentially a very tidy way of generating the pulse sequences needed. |
|
|
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
|
Posted: Mon Aug 27, 2018 11:07 am |
|
|
Life is not easy :-)
I'm using a pic18f27k42, and the example is with pic16f1509, so there are some adjustments of registry, to use PCM programmer's solution.
The same problem is also applicable to Ttelmah's solution.
I'm working on it.
Thanks you for your input for a solution :-)
/john |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Aug 27, 2018 12:17 pm |
|
|
As you say, never easy...
However remember the basic logic will remain exactly the same. The CCS solution ought to be close to right (since it will make the required bit changes to select the same logic), the big thing that will have to change is the selections to get the required inputs. The table of the inputs will be different on the other PIC.
Reading the data sheet, unlike the 1609, where the inputs can only be selected from specific groups, so only particular inputs can be fed to specific gates, on this one the inputs are all individually selectable. In fact this means you don't have to use the CLC2 at all. The PWM is directly selectable, so the whole logic can be done in a single CLC. |
|
|
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
|
Posted: Mon Sep 03, 2018 10:31 am |
|
|
To get on, I have bought some 16f1509 to see the code work. It works fine and there is reasonably cpu power to convert a one-byte color index to a 3-byte color, on the fly. I used the PCM programmers' suggestions to move on quickly. Now the code has to be changed to 18F27K42, to control 3000 LEDs in my wine cellar, to point out wine bottles. The way in which the CCS compiles configurer CLC is, for my head, far away from logical : - ( |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Sep 03, 2018 2:31 pm |
|
|
The CCS settings very carefully just match what is in the chip....
So in the 1509, there are four multiplexer inputs to each gate block, and each can be connected to one of four sources. The actual sources these correspond to is different on each input (bit table in the data sheet...). So if you want a particular input, you have to find it in the table, and then look up that this is selection 3 on input 5 for example. This is then what you feed into the CCS input setup. This part of the complexity disappears on the 27K42, where instead of just four possible selections for each input, each can be fed from all possible input sources.
Then each of the feeds into the actual gate can be fed from one of the input multiplexers, or driven high/low. This is the 'setup_gate' control.
Then with the inputs all setup, and selected, you set the actual logic with the setup_clc instruction.
Blame the chip for how screwy this actually seems... |
|
|
windcode
Joined: 26 Aug 2018 Posts: 6 Location: Aarhus, Denmark
|
|
Posted: Tue Sep 04, 2018 1:33 am |
|
|
Tnx Ttelmah i will try to figure it out: -) |
|
|
|