1. I am writing code for interfacing DP1903 with MCU. MCU is run by 16Mhz internal oscillator.
As per DP1903 datasheet;
TIH = 2us & T1L = 0.5us +-150ns
T0H = 0.5us & T0L = 2us +-150ns
Treset >= 24us
2. Data-sheet: http://www.depuw.com/Public/images/pdf/depuw/DP1903.pdf
Page 4 & 5 specify timings.
3. What is purpose of mentioning 800Khz & 400Khz speed? How does I have to account this is in code?
Data-sheet specify timings as already written in point 1, so I need to write code according to that, right?
So how does this 800Khz comes in between? What does it signify?
4. Suppose I have to send a zero & then a reset pulse at some given point.
So timing will be T0H, T0L & Treset, i.e
a. Pin high for 0.5us
b. Pin low for 2.0us
c. Pin low for 24us
Do after step b, I have to make high & then low again? As in page4, on T0L completion bit again goes to high? Or it is for representation only, I can combine step b & c & keep pin low for 24+2 = 26us?
5. Attached is my code. I saw some problem sometimes when I run the code. Code is run on full speed optimization i.e O3,
mainly problem occurs when I turn on all lights blue, The lights do not go all blue, but some whitish color appears.
6. I have 100 led connected. Also noticed if I make 24us delay, color don't appear correctly at all, with 50us there is some problem, increasing further delay don't have any effect. Why is that so?
7. For 0.5us, 8 nops are used, while for 2us, 32 nops are used.
As per DP1903 datasheet;
TIH = 2us & T1L = 0.5us +-150ns
T0H = 0.5us & T0L = 2us +-150ns
Treset >= 24us
2. Data-sheet: http://www.depuw.com/Public/images/pdf/depuw/DP1903.pdf
Page 4 & 5 specify timings.
3. What is purpose of mentioning 800Khz & 400Khz speed? How does I have to account this is in code?
Data-sheet specify timings as already written in point 1, so I need to write code according to that, right?
So how does this 800Khz comes in between? What does it signify?
4. Suppose I have to send a zero & then a reset pulse at some given point.
So timing will be T0H, T0L & Treset, i.e
a. Pin high for 0.5us
b. Pin low for 2.0us
c. Pin low for 24us
Do after step b, I have to make high & then low again? As in page4, on T0L completion bit again goes to high? Or it is for representation only, I can combine step b & c & keep pin low for 24+2 = 26us?
5. Attached is my code. I saw some problem sometimes when I run the code. Code is run on full speed optimization i.e O3,
mainly problem occurs when I turn on all lights blue, The lights do not go all blue, but some whitish color appears.
6. I have 100 led connected. Also noticed if I make 24us delay, color don't appear correctly at all, with 50us there is some problem, increasing further delay don't have any effect. Why is that so?
7. For 0.5us, 8 nops are used, while for 2us, 32 nops are used.
Code:
int main(void)
{
LED_pin_output_low();
while(1)
{
ws2811_reset_us(50);
for(led_cnt = 0U ; led_cnt < 100U ; led_cnt++)
{
ws2811_rgb_write(0xff, 0x00, 0x00);
}
delay_sec(2);
ws2811_reset_us(50);
for(led_cnt = 0U ; led_cnt < 100U ; led_cnt++)
{
ws2811_rgb_write(0x00, 0xff, 0x00);
}
delay_sec(2);
ws2811_reset_us(50);
for(led_cnt = 0U ; led_cnt < 100U ; led_cnt++)
{
ws2811_rgb_write(0x00, 0x00, 0xff);
}
delay_sec(2);
}
} /* function ends here */
static void ws2811_rgb_write(uint8_t red, uint8_t green , uint8_t blue)
{
uint8_t red_arr[8];
uint8_t green_arr[8];
uint8_t blue_arr[8];
uint8_t cnt;
uint8_t idx;
/* store the bits values of RGB in a array */
idx = 0x80U;
for(cnt = 0U; cnt < 8U; cnt++)
{
if(red & idx)
{
red_arr[cnt] = 1U;
}
else
{
red_arr[cnt] = 0U;
}
if(green & idx)
{
green_arr[cnt] = 1U;
}
else
{
green_arr[cnt] = 0U;
}
if(blue & idx)
{
blue_arr[cnt] = 1U;
}
else
{
blue_arr[cnt] = 0U;
}
idx = idx >> 1U;
}
/* send pixels as fast as possible */
/* red pixel */
if(red_arr[0]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[1]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[2]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[3]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[4]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[5]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[6]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(red_arr[7]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
/* green pixel */
if(green_arr[0]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[1]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[2]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[3]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[4]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[5]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[6]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(green_arr[7]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
/* blue pixel */
if(blue_arr[0]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[1]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[2]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[3]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[4]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[5]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[6]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
if(blue_arr[7]) { ws2811_bit_set(); } else { ws2811_bit_reset(); }
} /* function ends here */
static inline void ws2811_bit_set(void)
{
LED_PIN_ON();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
LED_PIN_OFF();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
}
static inline void ws2811_bit_reset(void)
{
LED_PIN_ON();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
LED_PIN_OFF();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();__no_operation();
}