0

我有 1MHz 时钟的 ATtiny。我正在尝试点亮一些 ws2812b LED 灯条。我在没有任何电阻器和电容器的情况下连接了所有东西。我认为一切都应该有效,但它没有:) 我正在使用 light_ws2812 库https://github.com/cpldcpu/light_ws2812。下面是示例代码。我在配置文件中只挂了 F_CPU 频率、输出引脚数和复位时间。你能帮我找到问题并建议我该如何解决吗?

主要的

#define F_CPU 1000000

#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "ws2812_config.h"
#include "light_ws2812.h"

struct cRGB led[2];

int main(void)
{

    uint8_t pos=0;
    uint8_t direction=1;
    uint8_t i;

    #ifdef __AVR_ATtiny10__
    CCP=0xD8;       // configuration change protection, write signature
    CLKPSR=0;       // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
    #endif

    led[0].r=255;led[0].g=00;led[0].b=00;       // LED 0 is red
    led[1].r=255;led[1].g=16;led[1].b=16;       // LED 1 is White

    while(1)
    {

        for (i=0; i<pos; i++)
        ws2812_sendarray((uint8_t *)&led[0],3);         // Repeatedly send "red" to the led string.
        // No more than 1-2µs should pass between calls
        // to avoid issuing a reset condition.
        for (i=0; i<(16-pos); i++)
        ws2812_sendarray((uint8_t *)&led[1],3);         // white

        _delay_ms(50);                                      // Issue reset and wait for 50 ms.

        pos+=direction;
        if ((pos==16)||(pos==0)) direction=-direction;
    }

}

配置

/*
 * light_ws2812_config.h
 *
 * v2.4 - Nov 27, 2016
 *
 * User Configuration file for the light_ws2812_lib
 *
 */ 


#ifndef WS2812_CONFIG_H_
#define WS2812_CONFIG_H_

///////////////////////////////////////////////////////////////////////
// Define Reset time in µs. 
//
// This is the time the library spends waiting after writing the data.
//
// WS2813 needs 300 µs reset time
// WS2812 and clones only need 50 µs
//
///////////////////////////////////////////////////////////////////////

#define ws2812_resettime  50

///////////////////////////////////////////////////////////////////////
// Define I/O pin
///////////////////////////////////////////////////////////////////////


#define ws2812_port B     // Data port 
#define ws2812_pin  3     // Data out pin

#endif /* WS2812_CONFIG_H_ */
4

4 回答 4

1

我认为 1Mhz 太慢了,无法生成 WS2812B 所需的信号。

最关键的 WS2812B 信号 - TH0 脉冲 - 宽度必须小于 500ns,在 1Mhz 时,每个 MCU 周期为 1000ns。

有关 WS2812B 时序约束的更多信息,请点击此处...

https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/

于 2019-11-30T17:46:08.793 回答
0

串联电阻器和并联电容器确实有助于减少导致莫名其妙行为的噪声。但你是对的,它不应该阻止 WS2812bs 完全工作。

我建议你在你的衣服上试试另一个别针。引脚 3 用于 USB 通信。如果您通过连接到计算机的 USB 电缆为您的服装供电,这将导致麻烦。例如,尝试引脚 5 和 6。

你可以试试 Adafruit_NeoPixel 库。我试过了,它未经修改就为 attiny85 编译。我实际上并没有尝试运行它,因为我周围没有服装。

此外,ebay 上的一些便宜的 WS2812b ledstrip 更换了它们的 Din 和 Dout 标签。这意味着您必须将 Dout 引脚连接到您的服装。这实际上发生在我身上一次。

我不知道 WS2812bs 中的脉冲长度,但如果这不是问题,我很确定它是我上面提到的三个之一。

希望有帮助。

于 2019-11-30T23:50:32.937 回答
0

[解决方案]

根据 README,我在 MAIN 源代码文件的标头之前包含了配置文件。这是一个错误,因为这两个文件是不同编译单元的一部分,并且它们之间没有共享 DEFINE。这导致我的配置设置被忽略并且程序使用了默认设置(在我的情况下不正确)。

要修复此错误,您应该在 light_ws2812.h 中包含您的 ws2812_config.h

于 2019-12-04T05:41:39.147 回答
0

你应该使用这个库FASTLED,你可以在 arduino ide 上下载它。使用这个库很容易用 ATTINY85 点亮 WS2812。

于 2020-05-19T03:32:39.880 回答