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

Đang mở
#6,070 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
53/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.