Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用ESP32的RMT控制4路WS2812灯带 (IDFGH-10396) #11651

Closed
3 tasks done
MrYanLK opened this issue Jun 12, 2023 · 7 comments
Closed
3 tasks done

使用ESP32的RMT控制4路WS2812灯带 (IDFGH-10396) #11651

MrYanLK opened this issue Jun 12, 2023 · 7 comments
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally

Comments

@MrYanLK
Copy link

MrYanLK commented Jun 12, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v4.4

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-WROOM-32E-N4

Power Supply used.

External 3.3V

What is the expected behavior?

希望能在ESP32上使用RMT控制4路WS2812灯带(现在调试时每条灯带上有40个LED,将来实际使用时可能会有几百个LED),具体步骤为蓝牙收到手机端的设置指令,然后通过led_strip.h里面的库函数设置灯带,目前IDF中的esp-idf/examples/peripherals/rmt/led_strip例程只能控制一条ws2812灯带,我尝试在代码中增加到4路RMT控制4路WS2812灯带,但是效果不理想,似乎会有时序问题,就会出现灯的颜色变了,我不确定是不是因为有蓝牙功能在使用,因为是freeRTOS系统,会不会是有更高级的任务,抢占了时间?怎么实现原子执行?(屏蔽掉其它任务),我现在不确定问题出在哪里。

What is the actual behavior?

1

Steps to reproduce.

  1. Step
  2. Step
  3. Step
    ...
    1

Debug Logs.

1

More Information.

1

@MrYanLK MrYanLK added the Type: Bug bugs in IDF label Jun 12, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jun 12, 2023
@github-actions github-actions bot changed the title 使用ESP32的RMT控制4路WS2812灯带 使用ESP32的RMT控制4路WS2812灯带 (IDFGH-10396) Jun 12, 2023
@suda-morris suda-morris removed the Type: Bug bugs in IDF label Jun 12, 2023
@suda-morris
Copy link
Collaborator

@MrYanLK
This is a "well-known" issue. To drive an LED, usually it needs to transfer 24 words. So 40LEDs means 24*40=960words.
By default, one RMT TX channel can only support 64words in FIFO. To transmits all the 40LEDs, the driver will go into interrupt by around 960/64=15 times. The number will increase along with the LED numbers. The driver will prepare data in the interrupt, which also costs some time.

If the RMT interrupt doesn't respond in time, the data transmission will be wrong, thus the LED displaying unwanted colors. To mitigate the issue, you can increase the FIFO size, as you want to use 4 RMT channels, then you can set mem_block_num to 2. But to be fair, this cannot help you too much because the interruption is still too frequent.

This is a hardware limitation, not a software bug.

Alternatively, to drive the LED strip, you can try with the SPI peripheral (although it's an expensive solution because you sacrifice an SPI controller for one LED strip). FYI: https://github.com/espressif/esp-iot-solution/blob/master/components/led/lightbulb_driver/drivers/ws2812/ws2812.c

@MrYanLK
Copy link
Author

MrYanLK commented Jun 12, 2023

非常感谢您的回复,我感觉在rmt发数据的时候,被其它任务(蓝牙相关的)打断了,造成波形出错,除了蓝牙我没创建其它任务,或者是驱动io被干扰了,我现在想在发rmt的时候把其它任务和中断都屏蔽掉,不知是否可行?
我也曾经考虑过使用SPI-DMA来驱动WS2812,但是我查了资料,ESP32确实有4路SPI,但是SPI0专用于flash 缓存,SPI1 用于外部 flash 芯片,软件可用的SPI就2个,这样的话就无法实现控制4路WS2812了
另外想了解下如何能屏蔽掉所有任务以及中断功能呢,是否有相关的API?

@MrYanLK
Copy link
Author

MrYanLK commented Jun 12, 2023

@suda-morris

@suda-morris
Copy link
Collaborator

@MrYanLK can you try installing the RMT driver on CPU Core1 and install bt driver on CPU Core0? By installing a driver on CPUn, I mean to call the driver initialization in taskn where taskn is pinned to CPUn.

@MrYanLK
Copy link
Author

MrYanLK commented Jun 16, 2023

@suda-morris 我之前做过测试把bt设为core1没什么效果(还不知道怎么把rmt配置到core1)

@suda-morris
Copy link
Collaborator

@suda-morris 我之前做过测试把bt设为core1没什么效果(还不知道怎么把rmt配置到core1)

  1. use xTaskCreatePinnedToCore to create a task
  2. in that task, do RMT and led strip initialization

with the above steps, the RMT interrupt will be installed on the core that running by the task. If BT and RMT interrupt are running on different cores, RMT is less likey to be disturbed by the BT.

@caidamao
Copy link

caidamao commented Aug 1, 2023

你可以尝试更新IDF到5.0,驱动有修改过。增加缓冲块的大小,相当大程度的减轻了这种现象。但主频必须要在240Mhz以上。把所有的函数全部塞进IRAM里

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Aug 17, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: In Progress Work is in progress labels Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants