一个使用Pwm驱动ws2812的问题

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

一个使用Pwm驱动ws2812的问题

跳至解决方案
4,145 次查看
5angxr
Contributor III

芯片是rt1062, 我想使用eflexpwm外设来给ws2812发送数据波形,

配置如下:
* pwm频率设定为800khz
initializationControl = kPWM_Initialize_LocalSync
forceTrigger = kPWM_Force_Local
* reloadSelect = kPWM_LocalReload
* reloadLogic = kPWM_ReloadImmediate

数据波形的发生如下代码:

 

 

static void ws2812_ratio_update(uint8_t val)
{
	uint16_t val_tran = 0;
	
	/* 四舍五入,以提高准确性 */
    val_tran = ((65535U * val) + 50U) / 100U;
    PWM_UpdatePwmDutycycleHighAccuracy(PWM_BASE_WS2812, WS2812_PWM_SUBMODULE, WS2812_PWM_CHANNEL, kPWM_SignedCenterAligned, val_tran);
}

/**
 * @author 
 * @brief  
 * @Param  strip 
 * @return 
 * @note   每次调用color_flush的事件都应大于280us
 */
static ws2812_status_t color_flush(ws2812_strip_t *strip)
{
    ws2812_status_t res = ws2812_ok;

    for(uint8_t i = 0; i < WS2812_LED_NUM; i++)
    {
        for(uint8_t j = 0; j < TRI_COLOR_BITS; j++)
        {
            // 等待pwm重载完成
            while(1)
			{
				if(PWM_GetStatusFlags(PWM_BASE_WS2812, WS2812_PWM_SUBMODULE) & kPWM_ReloadFlag)
				{
					break;
				}
			}

            if((strip->out_color_data[i] >> (TRI_COLOR_BITS -1 - j)) & (0x01))
            {
                ws2812_ratio_update(WS2812_T1H_RATIO);
            }
            else
            {
                ws2812_ratio_update(WS2812_T0H_RATIO);
            }
        }
    }

    return res;
}​

 

但是数据波形一直不能正确输出, 请问我该怎么做呢?

标记 (2)
0 项奖励
回复
1 解答
4,013 次查看
diego_charles
NXP TechSupport
NXP TechSupport

HI @5angxr 

I hope you are doing great, where you able play with the eflexPWM priority ? It seems that it is the lowest priority level in your system. You may want to increase its level. 

There is documentation from ARM on interrupt handling techniques, for example this post that may help> https://developer.arm.com/documentation/dui0646/a/The-Cortex-M7-Processor/Exception-model/Interrupt-...

Try to isolate the issue, test without any other interrupts, see if we are really seing issues due to the interrupt being preempted.

On the other hand, If the eflexPWM interrupt needs to occur very  often and all the time, you may opt for another way to configure the module, so that does need to operate with a interrupt method, in example combine it with PWM.

All the best,

Diego

 

 

在原帖中查看解决方案

0 项奖励
回复
7 回复数
4,085 次查看
5angxr
Contributor III

现在已可以使用eFLEXPWM模块生成数据波形. 实现方式是在完成一个周期之后进入PWM的中断, 然后改变占空比.

不过, 现在遇到的问题是:

  • 如果有其他中断被使能, 则pwm有时候会在应该进入中断的时候无法进入pwm中断, 这样就无法及时更新占空比, pwm波形就会不正确

------

English:

Thank you for your reply @diego_charles 

The eFLEXPWM module can now be used to generate data waveforms. This is achieved by entering a PWM interrupt after one cycle, and then changing the duty cycle.

However, here's the problem:

  • If other interrupts are enabled, the pwm sometimes fails to enter the pwm interrupt when it should, so the duty cycle cannot be updated in time and the pwm waveform will be incorrect.

@diego_charles any commont on that?

标记 (1)
0 项奖励
回复
4,059 次查看
diego_charles
NXP TechSupport
NXP TechSupport

Hi @5angxr 

Thanks for your reply!

From which other modules are this other interrupts ?However, it could be the case that higher priority interrupt is wining  over  the eFlexPWM one. Try to increase the priority of eFlexPWM.

Btw,  Is you application  running an  RTOS or bare-metal ?

All the best, 

Diego

0 项奖励
回复
4,047 次查看
5angxr
Contributor III

hello, @diego_charles 

Thank you for your reply, and sorry for the late response.

There're timer(priority 3), lcdif(priority 3), gpio(priority 4), spi master(priority 1), spi slave(priority 1), another spi slave(priority 0), pit(priority 3), uart(priority 3), usb(priority 1) and eflexpwm(priority 5) interrupts.

my application is running an bare-metal.

It seems that my current interrupt priority configuration is a bit confusing, I'm wondering, how to set interrupt priority properly.

0 项奖励
回复
4,014 次查看
diego_charles
NXP TechSupport
NXP TechSupport

HI @5angxr 

I hope you are doing great, where you able play with the eflexPWM priority ? It seems that it is the lowest priority level in your system. You may want to increase its level. 

There is documentation from ARM on interrupt handling techniques, for example this post that may help> https://developer.arm.com/documentation/dui0646/a/The-Cortex-M7-Processor/Exception-model/Interrupt-...

Try to isolate the issue, test without any other interrupts, see if we are really seing issues due to the interrupt being preempted.

On the other hand, If the eflexPWM interrupt needs to occur very  often and all the time, you may opt for another way to configure the module, so that does need to operate with a interrupt method, in example combine it with PWM.

All the best,

Diego

 

 

0 项奖励
回复
3,987 次查看
5angxr
Contributor III

thank you diego, I'll check the ARM documentation for the interrupt configuration.

Maybe eFlexPwm is not suitable for my project, now I use FlexIO to control WS2812 and it works fine!

3,971 次查看
diego_charles
NXP TechSupport
NXP TechSupport

Hi @5angxr 

Thanks for the follow up! best wishes on your application 

Diego 

0 项奖励
回复
4,108 次查看
diego_charles
NXP TechSupport
NXP TechSupport

Hi @5angxr 

I hope that you are doing excellent. 

From what I translated  to English  it seems that the  eflexpwm perihpheral is not generating the expected PWM output  signal, when configured as you show.

However, could you provide more descriptions on your issue? Also, SDK version and if you are using our evaluation board are useful.

If my understanding is  correct , I still  recommend you to use  our RT1062 eflexpwm example to see if we can replicate this issue.

All the best,

Diego.

 

0 项奖励
回复