簡體   English   中英

ATTiny85 上的 ws2812b

[英]ws2812b on ATTiny85

我有 ATTiny,時鍾頻率為 1MHz。 我正在嘗試點亮一些 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_ */

我認為 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/

串聯電阻器和並聯電容器確實有助於降低導致莫名其妙行為的噪聲。 但你是對的,它不應該完全阻止 WS2812bs 工作。

我建議你在你的 attin 上嘗試另一個別針。 引腳 3 用於 USB 通信。 如果您通過連接到計算機的 USB 電纜為您的 attiny 供電,這將導致麻煩。 例如,嘗試引腳 5 和 6。

你可以試試 Adafruit_NeoPixel 庫。 我試過了,它沒有修改就編譯為attiny85。 我實際上並沒有嘗試運行它,因為我周圍沒有 attiny。

此外,易趣上一些便宜的 WS2812b LEDstrips 更換了 Din 和 Dout 標簽。 這意味着您必須將 Dout 引腳連接到您的 attiny。 這實際上發生在我身上一次。

我不知道 WS2812bs 中的脈沖長度,但如果這不是問題,我很確定它是我上面提到的三個之一。

希望有幫助。

[解決方案]

根據自述文件,我在主源代碼文件中的標頭之前包含了配置文件。 這是一個錯誤,因為這兩個文件是不同編譯單元的一部分,並且它們之間沒有共享 DEFINE。 它導致我的配置設置被忽略,程序使用默認值(在我的情況下不正確)。

要修復此錯誤,您應該在 light_ws2812.h 中包含您的 ws2812_config.h

你應該使用FASTLED庫,你可以在 arduino ide 上下載它。使用這個庫可以很容易地使用 ATTINY85 點亮 WS2812。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM