avr: Timer0 overflow interrupt uses about one third of the CPU time

Aperta
#6,072 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
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Start by reading the AVR Timer0 clock and PWM code, then inspect the changes described in linked issues #6070 and #6071, which this proposal depends on. Reproduce the timing measurements on an ATmega328P if hardware is available, and check how prescaler changes affect ticks() and short sleeps. Done means Timer0 uses the proposed prescaler while maintaining the intended time resolution, with the reported flash and runtime costs understood.

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

Descrizione

On ATmega328P and ATmega1280/2560, the runtime sets Timer0 to prescaler 1 for the monotonic clock. The overflow interrupt then fires every 256 CPU cycles (16 µs at 16 MHz), and each interrupt does a 64-bit add. On an ATmega328P this takes about one third of the CPU time.

Measurements

ATmega328P (Freetronics Eleven, Uno clone) at 16 MHz, TinyGo 0.44.0. A loop wrote 32768 bytes to the SPI0 registers at 8 MHz:

Timer0 overflow interrupt Time
on (default) 126 ms
off 83 ms

Both builds used -opt=2. With the default -opt=z the times were 196 ms and 126 ms.

On a SparkFun MicroView (ATmega328P), a Lorenz attractor demo on the OLED ran 13.4 frames per second with the default timer, and 20.8 frames per second with prescaler 64.

Proposal

Use prescaler 64, as the Arduino core does. The interrupt then fires every 1024 µs. To keep a fine time resolution, ticks() can add TCNT0 times the time per count, which gives 4 µs steps. Sleeps shorter than one tick can busy wait.

Cost, measured: blinky1 for arduino grows by 320 bytes of flash. RAM stays the same.

This change depends on #6071 and #6070, because the PWM code can change the Timer0 prescaler at run time.

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.