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

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

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

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

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
53/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go

調査の方向性

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.

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

説明

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.

主要言語
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 を短くまとめたダイジェスト。