avr: time can jump when machine.Timer0.Configure changes the prescaler

Abierto
#6,070 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
53/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Start by reading the AVR implementation of machine.Timer0.Configure and adjustMonotonicTimer, along with the Timer0 overflow interrupt handler. Check how the prescaler register update and tick length update interact when an overflow occurs between them. Done means the register and tick length changes cannot leave an overflow accounted at the wrong rate; the issue suggests doing both with interrupts off.

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

Descripción

On ATmega328P and ATmega1280/2560, the runtime monotonic clock uses Timer0. machine.Timer0.Configure writes the new prescaler to TCCR0B, then it calls adjustMonotonicTimer to update the tick length. Interrupts stay on between the two.

If Timer0 overflows in that window, the overflow interrupt adds a tick with the old length, but the overflow came at the new rate. For example, after a change from prescaler 256 to prescaler 1, each overflow in the window adds 4096 µs where it must add 16 µs.

The window is short, so the error does not occur often. But when it occurs, the error can be several milliseconds, and code that changes the PWM period often collects these errors.

At the moment a larger bug hides this one: currentNanosecondsInTick gives the wrong tick length for all prescalers other than 1, so time after a prescaler change is already wrong by a factor of 16 to 5120. This issue shows after that bug is fixed.

A possible fix: write the Timer0 registers and update the tick length together, with interrupts off.

Lenguaje dominante
Go
Estrellas
17.8k
Forks
1.1k
Merge medio
1 d 4 h
PR fusionados (30 d)
380

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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/tinygo

Todos los issues de tinygo-org/tinygo

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.