 |
 |
| View previous topic :: View next topic |
| Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Sat Dec 07, 2019 3:40 pm |
|
|
hmm, interesting... built in 'repeater'....
Timing probably isn't too much of an issue for the short runs but my stuff was good for 15 miles (yes, MILES), asynchronous though (think RS-232 on steroids,+-60 volts). If timing was off (RC clock) the furthest away unit would 'drop' control bits. Replacing RC clock with xtal, 4060, 2-4018s got it 'spot on'.
Now I'm always leary about reading about RC clocks and distance......
Jay |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Sun Dec 08, 2019 6:25 am |
|
|
Hello, your date of joining this group is 2003-2001. However, I just joined (2019). I can understand what you're saying with sample codes or algorithms. Thank you very much for your answers.
Please consider what I said |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 12:31 am |
|
|
Help or support
 |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Mon Dec 09, 2019 6:46 am |
|
|
| Code: | /*THREE LEDs addressed. Once per second it will be updated
to cycle through Blue --> Green --> Red, and repeat.*/
void threeLEDs_driver(void) {
static unsigned int8 temp = 0;
switch(temp) {
//first LED
case 0: RGB_color(0x00, 0x00, 0xFF); temp += 1; break;
case 1: RGB_color(0x00, 0xFF, 0x00); temp += 1; break;
case 2: RGB_color(0xFF, 0x00, 0x00); temp += 1; break;
//2nd LED
case 3: RGB_color(0x00, 0x00, 0xFF); temp += 1; break;
case 4: RGB_color(0x00, 0xFF, 0x00); temp += 1; break;
case 5: RGB_color(0xFF, 0x00, 0x00); temp += 1; break;
//3rd LED
case 6: RGB_color(0x00, 0x00, 0xFF); temp += 1; break;
case 7: RGB_color(0x00, 0xFF, 0x00); temp += 1; break;
case 8: RGB_color(0xFF, 0x00, 0x00); temp = 0; break;
}
WS_RESET(DATA_PIN);
delay_ms(1000);
} |
This might work ? I don't have LEDs to test though ! I'd change the colours of 2rd, 3rd LEDs to SEE if they do work.
Jay |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 6:52 am |
|
|
Hello to everyone. Now the code works within 8 pins. You can use. But I have this problem. For example, the first led turns red. Other 7 colors blue,
After 1 second, seven LEDs are green. The first led could not do in the old color. So when the other leds change, I want an LED to remain in its old color How do I do it? Thank you.
| Code: |
#include "18f46k22.h"
#device adc = 10
#define OSC 32000000
#use delay (internal = OSC)
//#use delay(internal=16MHz, clock=64MHz)
#fuses INTRC_IO, NOWDT, PUT, NOMCLR //Internal RC Osc IO on CLKIN, Wtchdg Timer Disabled, Pwrup Timer Disabled, Internal MCLR
#fuses NOBROWNOUT, NOLVP, NOCPD, NODEBUG, //Brwn-Out Reset disabled, LVP Disabled, Data Memory Code Protect disabled, PDAT&PCLK IO
#fuses NOPROTECT, //Program memory Code Protect Disabled, Two Speed External-Internal OSC Changeover disabled
#fuses NOFCMEN, NOWRT, STVREN //External Clock Failsafe Disabled, Flash Memory Slf Write Protect Disabled, Stack Over&Under-flow causes reset
#use FAST_IO(ALL)
//////////////////////////////////////////////////
// BIT BANG Driver for WS2812B RGB LEDs //
//////////////////////////////////////////////////
#define DATA_PIN PIN_B0
/*Creates the timing for the 1's and 0's. Very dependent on hardware.If oscillator speed changes, or fast_io is disabled, timing will be altered.*/
//1
#define WS_ONE(pinPtr) {\
output_high(pinPtr); delay_cycles(1); delay_cycles(1); \
delay_cycles(1); delay_cycles(1); delay_cycles(1); delay_cycles(1); \
delay_cycles(1); delay_cycles(1); output_low(pinPtr);\
}
#define WS_ZERO(pinPtr) {\
output_high(pinPtr); delay_cycles(1); delay_cycles(1); \
output_low(pinPtr); delay_cycles(1); delay_cycles(1); \
delay_cycles(1); delay_cycles(1); delay_cycles(1);\
}
//2
//3
/*Latches the data in to the devices after passing. Call this
at the end of each update cycle.*/
#define WS_RESET(pinPtr) output_low(pinPtr); delay_us(1);
/*Low Level interface for sending data*/
void data_stream(unsigned int8 temp) {
//1
if(temp & 0x80) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x40) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x20) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x10) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x08) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x04) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x02) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
if(temp & 0x01) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
}
/*WS2812 accepts colors in order of green-red-blue.
I do not, so these assign as red-green-blue which
is more comfortable to me.*/
void RGB_color(char red, char green, char blue,) {
//1 //ilk en alttaki
// r,g,b -- g,r,b
// r,b,g -- g,b,r
// g,b,r -- b,g,r
// g,r,b -- r,g,b
// b,r,g -- r,b,g
// b,g,r -- b,r,g
data_stream(red);
data_stream(green);
data_stream(blue);
// WS_RESET(DATA_PIN);
//2
data_stream(red);
data_stream(green);
data_stream(blue);
//3
data_stream(red);
data_stream(green);
data_stream(blue);
//4
data_stream(red);
data_stream(green);
data_stream(blue);
//5
data_stream(red);
data_stream(green);
data_stream(blue);
//6
data_stream(red);
data_stream(green);
data_stream(blue);
//7
data_stream(red);
data_stream(green);
data_stream(blue);
//8
data_stream(red);
data_stream(green);
data_stream(blue);
// data_stream(blue);
}
/*Single LED addressed. Once per second it will be updated
to cycle through Blue --> Green --> Red, and repeat.*/
//int r,g,b;
void prove_driver(void) {
static unsigned int8 temp = 0;
for(int r=0;r<254;r++){
RGB_color(r, 0x00, 0x00);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int g=0;g<254;g++){
RGB_color(0x00, g, 0x00);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int b=0;b<254;b++){
RGB_color(0x00, 0x00, b);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int rg=0;rg<254;rg++){
RGB_color(rg, rg, 0x00);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int rb=0;rb<254;rb++){
RGB_color(rb, 0x00,rb);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int gb=0;gb<254;gb++){
RGB_color( 0x00,gb,gb);
WS_RESET(DATA_PIN);
delay_ms(5);
}
for(int rgb=0;rgb<254;rgb++){
RGB_color( rgb,rgb,rgb);
WS_RESET(DATA_PIN);
delay_ms(5);
}
}
void main(void) {
delay_ms(1000);
output_drive(DATA_PIN);
while(TRUE){
prove_driver();
}
}
|
 |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Mon Dec 09, 2019 7:25 am |
|
|
You need to setup an array and transmit the entire array of data THEN the reset.
Also you should copy, name and edit the copy of 'prove_driver' function ! That way you ALWAYS have the original version to look at.
also...
Add comments at the end of lines of code. They cost nothing (no space in PIC) BUT allow you and others to understand what you're doing (or trying to do).
Jay |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 7:40 am |
|
|
Yes I add the description lines But can you be a little more descriptive? Which array do I throw in the show? And what I use for the 'prove_driver' function that I copied.
-------------------------------------------------
Your knowledge is as much as the other person understands |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 8:18 am |
|
|
EMergeny help  |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 09, 2019 2:11 pm |
|
|
Have you looked at your pulse timing on a scope ? I looked at the .LST
file and it seems incorrect. The high time for WS_ONE is too long.
Also, the low times should be checked on a scope.
Make a test program that sends 0x55 as the data, continuously.
Look at the timing and get it right.
Here is my analysis of the high times for each pulse:
| Code: |
.................... if(temp & 0x01) {WS_ONE(DATA_PIN);} else {WS_ZERO(DATA_PIN);}
00162: BTFSS 0F.0
00164: BRA 017C
// WS_ONE - high pulse is 9 cycles = 1125ns. Should be 6 cycles = 750ns.
00166: BSF LATB.0
00168: NOP
0016A: NOP
0016C: NOP
0016E: NOP
00170: NOP
00172: NOP
00174: NOP
00176: NOP
00178: BCF LATB.0
0017A: BRA 018E
// WS_ZERO - high pulse is 3 cycles = 375ns. This is OK.
0017C: BSF LATB.0
0017E: NOP
00180: NOP
00182: BCF LATB.0
00184: NOP
00186: NOP
00188: NOP
0018A: NOP
0018C: NOP
0018E: RETURN 0 |
|
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Mon Dec 09, 2019 2:45 pm |
|
|
well I see other possible problems
1) heading says WS2811 but code is for WS2812. I checked a bit online, seems they have different timing requreiments.....
2) timing is dependent on clock speed. The original code ONLY works for whatever clock speed it was designed for.
we really need to know which LEDs you're using.
Jay |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 2:54 pm |
|
|
Thank you for question PCM Programmer.
1) My code is running.
2) Can give eight led light at the same time.
3) LEDs give different or same color light at the same time.
So I think the 'WS_ONE' or 'ws_zero' functions are correct.
My problems are;
1) | Code: |
data_stream (red);
data_stream (green);
data_stream (blue);
|
I wrote this function eight times for eight leds.
r, g, b --> g, r, b
r, b, g --> g, b, r
g, b, r --> b, g, r
g, r, b --> r, g, b
b, r, g --> r, b, g
b, g, r --> b, r, g
If I change the rankings, the luminous order of the leds changes.
I couldn't understand the how of that.
2) When changing the LED colors in order, I want one of them to remain the same color. But I couldn't.
Actually, the same two questions.
data_stream (red);
data_stream (green);
data_stream (blue);
How this function works.  |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 2:55 pm |
|
|
| I use WS2812B |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Mon Dec 09, 2019 3:02 pm |
|
|
OK.. you should start a new thread !! You're using a different PIC and different LED than the original poster !!!
arrgh.. no wonder I'm confused.....
Now since you are using the WS2812B AND the 18F46K22, I know ther eis code posted here, code library, or 'somewhere' onteh Internet as I have a copy of it on my PIC PC....
TIMING is critical.....you really need scope or 'pencil and paper' to see what's happening.
Jay |
|
 |
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Mon Dec 09, 2019 3:45 pm |
|
|
Okey new topic: WS2812b and Pic18f46k22
Pls help me for this topic |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|