This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to control brightness of ws2812b rgb led using msp430g2553 launchpad

Other Parts Discussed in Thread: MSP430G2553

-> I am beginner in embedded system design.

-> i want to control  color and brightness of ws2812b rgb led using msp430 g2553 launchpad.

-> I search on internet and develop code which control rgb color of  ws2812b  using spi of launchpad.

-> But i can't find any thing to control brightness of led ws2812b.

                                              thanks in advance...

  • Moved this to MSP forum.
  • If you managed to communicate with led controller then to change brightness of each color or change them all - you have to change corresponding R, G or B 8-bit values you send to controller. That' s it. Did you read datasheet of the controller?

  • Maheshkumar,

    I did not work with the WS2812B myself, but after a short look into the datasheet it does not look like these LEDs are controlled via SPI. You could have noticed yourself that there isn't a data and clock input. It is just a single data input (and output for cascading). It is NRZ coded

    In the datasheet:

    It tells you that a logic one is represented by 0.8µs high followed by 0.45µs low and a logic zero is 0.4µs high followed by 0.85µs low. 24 bits of data is one complete information block for a LED. 256 brightness levels for red, green and blue respectively.

    I would have a look at the timer of the MSP430G2553 - start with the code examples:

    These code examples give you an overview of how to use the timer module:

    • msp430g2xx3_ta_01.c                        Timer_A, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
    • msp430g2xx3_ta_02.c                        Timer_A, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
    • msp430g2xx3_ta_03.c                        Timer_A, Toggle P1.0, Overflow ISR, DCO SMCLK
    • msp430g2xx3_ta_04.c                        Timer_A, Toggle P1.0, Overflow ISR, 32kHz ACLK
    • msp430g2xx3_ta_05.c                        Timer_A, Toggle P1.0, CCR0 Up Mode ISR, 32kHz ACLK
    • msp430g2xx3_ta_06.c                        Timer_A, Toggle P1.0, CCR1 Cont. Mode ISR, DCO SMCLK
    • msp430g2xx3_ta_07.c                        Timer_A, Toggle P1.0-2, Cont. Mode ISR, DCO SMCLK
    • msp430g2xx3_ta_08.c                        Timer_A, Toggle P1.0-2, Cont. Mode ISR, 32kHz ACLK
    • msp430g2xx3_ta_10.c                        Timer_A, Toggle P1.1/TA0, Up Mode, DCO SMCLK
    • msp430g2xx3_ta_11.c                        Timer_A, Toggle P1.1/TA0, Up Mode, 32kHz ACLK
    • msp430g2xx3_ta_13.c                        Timer_A, Toggle P1.1/TA0, Up/Down Mode, DCO SMCLK
    • msp430g2xx3_ta_14.c                        Timer_A, Toggle P1.1/TA0, Up/Down Mode, 32kHz ACLK
    • msp430g2xx3_ta_16.c                        Timer_A, PWM TA1-2, Up Mode, DCO SMCLK
    • msp430g2xx3_ta_17.c                        Timer_A, PWM TA1, Up Mode, 32kHz ACLK
    • msp430g2xx3_ta_19.c                        Timer_A, PWM TA1, Up/Down Mode, DCO SMCLK
    • msp430g2xx3_ta_20.c                        Timer_A, PWM TA1, Up/Down Mode, 32kHz ACLK
    • msp430g2xx3_ta_21.c                        Timer_A, Normal Timer Mode Input Period and Duty Cycle Measurement

    And in addition you should read the user's guide:

    Chapter 12 on page 355 describes the timer module. Don't be scared by that big document - you only have to read the chapter of the function you wnat to use at that moment.

    To be honest: For an absolute beginner I would say that this is not the right project to start from. SPI would be easier. But you can accomplish it anyway, of course.

    I would start with writing a program that generates a timer interrupt at freely chosen time intervalls.

    Dennis

  • i read data sheet and control color of led. i have to send 24 bit (8-bit R, 8-bit G, 8-bit B). Each colour contain value from 0x00 to 0xff. Using that i got different color and shadow color of that. But i want to change brightness of same color. PWM is good method for brightness controll but i can't use pwm for this led.
  • The datasheet tells you that the byte controls the brightness of the appropriate LED. Each byte controls the individual brightness of R, G and B respectively. A change in brightness of R, G or B automatically changes the color of the whole LED. Imagine a bucket where you put red, green and blue color in - the amount of each single color determines your final overall color. So if you want to change the brightness of the complete LED, then you have to change the brightness value of each single color.

    Dennis
  • hi Dennis Eichmann sir,
    ya, u r wright. it's NRZ coded. i understand all that and send 24-bit data using MOSI pin (p1.7) of launchpad. Led doesn't need clock. i send 24 data and got different color as per bits sended by me. But i want to control brighness of led. I need same color with different brightness.
  • According to the datasheet the MOSI of the USCI is not suitable for that since it does not output a variable high/low time NRZ signal. Using SPI is not how the LED is controlled. Read my first answer. It is all about timing of high and low time of your data bit. And changing the brightness of the whole LED is done by changing the brightness of R, G and B at the same time.

    Dennis

  • i develop my code with reference to below link.

    forum.43oh.com/.../3971-wearable-ws2812-strip-controllers

    sample code is provided on this link. i little modify code as per below,
    i remove uart receiveing and give hardcoded data for color.
  • The data signal format used with the ws2812b is a ‘RZ’ ‘Self clocking’ signal.
  • Dennis Eichmann said:
    Using SPI is not how the LED is controlled.

    I disagree here. Obviously you shall not expect SPI to translate your data into NRZ format during transmission, instead you shall format data into NRZ before you put it into SPI transmit register.

    Specification says:

    Dennis Eichmann said:
    logic one is represented by 0.8µs high followed by 0.45µs low and a logic zero is 0.4µs high followed by 0.85µs low

    You missed to mention that tolerance for pulses is +/- 150ns which is +/-0.150µs. So we are free to _not_ stretch low signals by 0.05µs compared to high signals. So we run SPI clock at 2.5MHz to get bit time 0.4µs, send two bits to have long pulse and one bit to have short pulse.

    Example: data "0110" translates to 100110110100 which we shall send out of SPI peripheral. So to send 24bits of LED data you have to shift out 72 bits of NRZ-encoded bits which conveniently is 9 bytes of SPI transmission.

  • I would do 7bit UART, active high (so reversed from standard TTL UART)
    Put 3 LED  bits in every 9bit data as 33% and 66% high for respective 0 or 1 should be within tolerance.
    uart-start-bit is always used for the first bit, stop bit is the 0 bit in the last LED bit

    example 3bits are all zeros :
    1_0010010_0
    └─┘=One LED bit

    example 3bits are all 1:
    1_1011011_0
    └─┘=One LED bit

  • I like your idea :) Another approach to send exact number of data bits per one write would be using USI (if available on chip) with bit counter set to 15 bits. BTW similar approach can be used to software-emulate UART TX using USI.
  • Let's say, for example, you send R=100, G=50, B=70 and get the color you want.

    Now if you want to reduce or increase the brightness, you could simple reduce or increase those values of RGB proportionally. That is:

    R=100, G=50, B=75 is your “normal” brightness.
    R=200, G=100, B=140 will be twice as bright.
    R=50, G=25, B=35 will be half as bright.
    R=10, G=5, B=7 will be very dim.
  • I'm ordering some boards from OshPark and stencil from OshStencils

    As Launchpad's Vcc is actually 3.6V so it's within ws2812b minimum.
    Two cap-sense pads to adjust fade speed etc.



  • I also want to know could it control the sk6812 ic ?
    the datasheet about sk6812 ic:www.rgbledcolor.com/sell-1968049-sk6812-led-digital-rgb-full-color-smd.html
    as well as apa102 ? thanks

**Attention** This is a public forum