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

Aperta
#6,070 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
53/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
17.8k
Fork
1.1k
Merge medio
1g 4h
PR unite (30g)
380

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tinygo-org/tinygo

Tutte le issue di tinygo-org/tinygo

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.