ws2812: gaps between bytes on AVR latch the strip after the first LED

Đang mở
#927 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
arduino, go
Lĩnh vực
embedded-iot

Hướng nghiên cứu

Start with ws2812_avr.go and trace WriteByte, PortMaskSet, PortMaskClear, and writeColorsRGB to understand the AVR timing between bytes. Build the supplied reproducer for -target=arduino and compare its output with the working continuous-buffer bit loop described in the issue. Done means all 40 LEDs update correctly on the Uno without the byte gaps triggering a latch.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

On an Arduino Uno (ATmega328P, 16 MHz) with an Adafruit NeoPixel Shield (40 WS2812B LEDs on D6), WriteColors lights only the first LED, which flickers. The rest stay dark. The same shield works on a 48 MHz SAMD21 board.

The AVR WriteByte in ws2812_avr.go sends each byte from inline assembly, and the bit timing inside a byte is correct. Between bytes, the line stays low while Go code runs: the WriteByte call and return, the pin mask calculation in PortMaskSet and PortMaskClear, interrupt.Disable and Restore, and the loop and applyBrightness in writeColorsRGB. In the compiled example that comes to about 130 cycles (~8 µs) between bytes, and more between pixels. That's longer than the WS2812B latch time, so the strip latches after each byte and the next byte is written to the first LED again.

Results with the same Uno, shield and pin:

Sender Gap between bytes Result
ws2812.WriteColors (drivers v0.36.0) ~8 µs first LED flickers, the rest stay dark
The driver's bit loop inside an outer loop over the whole buffer (ld X+) ~0.4 µs all 40 LEDs correct

This is separate from #923. Nothing interrupts the write here, so keeping interrupts disabled for the whole frame does not help.

To reproduce, build this program for -target=arduino:

package main

import (
	"image/color"
	"machine"
	"time"

	"tinygo.org/x/drivers/ws2812"
)

func main() {
	pin := machine.D6
	pin.Configure(machine.PinConfig{Mode: machine.PinOutput})
	strip := ws2812.NewWS2812(pin)
	strip.SetBrightness(16)

	var pixels [40]color.RGBA
	for step := uint8(0); ; step++ {
		for i := range pixels {
			pixels[i] = color.RGBA{R: uint8(i*6) + step, G: 64, B: 255 - uint8(i*6), A: 255}
		}
		strip.WriteColors(pixels[:])
		time.Sleep(20 * time.Millisecond)
	}
}
Ngôn ngữ chính
Go
Star
756
Fork
251
Merge trung bình
7 ngày 12 giờ
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/drivers

Tất cả issue của tinygo-org/drivers

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.