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

オープン
#6,072 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
17.8k
フォーク
1.1k
平均マージ
1日 4時間
マージ済み PR(30日)
380

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tinygo-org/tinygo のほかの issue

tinygo-org/tinygo の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。