AnsweredAssumed Answered

How can we vary duty cycle on PWM2 for IMX6SL to drive W2812B RGB Strip

Question asked by Sudhanshu Bhutani on Oct 5, 2016
Latest reply on Mar 17, 2017 by Sudhanshu Bhutani

Hi NXP experts,


I have a task to drive W2812B RGB Strip using  PWM2 IMX6SL board. For this strip, the strict timing needs to be followed.


As per strip internals, we need to produce 800Khz on PWM out, for this, we calculated period to be 1250ns.

I made correct entries to DTB like this:-


backlight {

compatible = "pwm-backlight"

pwms = <&pwm2 0 1250>

brightness-levels = <0 74 163  255>;

default-brightness-levels = <0>;



&pwm2 {

status = "okay"



pwm2 {

        pinctrl_harman_iot_pwm2 : pwm2-fornt-led {

        fsl,pins = <MX6SL_PAD_EPDC_SDCE3__PWM2_OUT 0x110b0>




When kernel boots up, LED strip remains off, as default-level is 0.


First, when we do echo 1 > /sys/class/backlight/backlight/brightness, we see PWMSAR register written with 362, i believe this is the first sample value for FIFO. We see correct duty as 33%

Then, we do echo 2 > /sys/class/backlight/backlight/brightness, we see PWMSAR register written with 163 and we see correct duty as 66%


Now, the question is

1. How can we get variable duty cycle in single pulse? Because, driver gets set to the particular duty cycle and starts running pulse of that duty (infinitely). Even if we send echo multiple times, with correct different values, PWM IMX only works on last PWM SAR duty cycle?


2. How can we modify both these values ? Do we need to change these values at all for producing multiple duty cycle?

* Prescale is always coming as 1

* period_cycles = 82 - 2 = 80


As per LED datasheet,

1. we need 800ns as 1  and rest 450ns as 0 - so that LED takes this as 1

2. we need 450 ns as 1 and rest 800ns as 0 - so that LED takes this as 0

3. for reset, we need 5000ns delay - which can be sent as 0.


3. We need to actually drive red,green,blue color using this LED strip, and we need to achieve this waveform, which i have attached it is for red color for RPI2. How can we acheive this waveform using PWM-IMX driver?

Is it achievable? Please refer to tek0000.png file for waveform.


4. How can we achieve this waveform, what settings we should do, and how we should send data to PWM SAR config register each time is our concern?


5. Do we need to change clock i.e 66 MHz which we are using, currently, we are giving HIGH_IPG clock?


Kindly help in achieving this task?