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

Abierto
#927 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
arduino, go
Área
embedded-iot

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
	}
}
Lenguaje dominante
Go
Estrellas
756
Forks
251
Merge medio
7 d 12 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tinygo-org/drivers

Todos los issues de tinygo-org/drivers

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.