Understanding DP1903 timing (WS2811 variant) - Page 1
Forum section: electronics / beginners

author: Vindhyachal.takniki
author_rank: Frequent Contributor
timestamp: August 20, 2017, 06:36:12 pm
content: 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 +-150nsT0H = 0.5us & T0L = 2us +-150nsTreset >= 24us2. Data-sheet:http://www.depuw.com/Public/images/pdf/depuw/DP1903.pdfPage 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.ea. Pin high for 0.5usb. Pin low for 2.0usc. Pin low for 24usDo 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;uint8_t green_arr;uint8_t blue_arr;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 = 1U;}else{red_arr = 0U;}if(green & idx){green_arr = 1U;}else{green_arr = 0U;}if(blue & idx){blue_arr = 1U;}else{blue_arr = 0U;}idx = idx >> 1U;}/* send pixels as fast as possible *//* red pixel */if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(red_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }/* green pixel */if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(green_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }/* blue pixel */if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { ws2811_bit_set(); } else { ws2811_bit_reset(); }if(blue_arr) { 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();}