Skip to content

fix(emulator): drive the timer 1 PWM waveform of the ATtiny85 - #341

Merged
ttbombadil merged 3 commits into
feature/browser-emulationfrom
fix/p6-2-attiny85-timer1-pwm
Oct 24, 2026
Merged

ttbombadil merged 3 commits into
feature/browser-emulationfrom
fix/p6-2-attiny85-timer1-pwm

Conversation

@ttbombadil

Copy link
Copy Markdown
Collaborator

Worum es geht

Offener Fund aus M3 (#334, #337): avr8js 0.21.1 erzeugt beim ATtiny85 in der PWM-Konfiguration, die ATTinyCore für analogWrite auf PB1/PB4 verwendet (CTC1 + PWM1x, OCR1C = 255), kein Signal an OC1A/OC1B. Ohne CTC1 zählt es außerdem phasenkorrekt, der Chip zählt aber in jedem Fall als Sägezahn von 0 bis OCR1C (Datenblatt 12.2.2; ATTinyCore: „this module doesn't have a 8bit PWM mode“).

Änderung

  • mcu/attiny85.ts: correctTimer1Pwm treibt OC1A/OC1B aus dem Zählerstand (HIGH von 0 bis zum Vergleich mit OCR1x, mit COM1x = 11 invertiert). Bei CTC1 zählt avr8js schon richtig, es fehlte nur das Signal. Ohne CTC1 ersetzt die Korrektur die phasenkorrekte Zählung durch den Sägezahn samt Flags (TOV1 beim Sprung auf 0).
  • Die Korrektur ersetzt private Methoden als einfache Eigenschaften. Ein erster Ansatz mit einem Accessor auf der Instanz (Object.defineProperty) bremste die ganze ATtiny-Emulation in V8 von 11 × auf 8 × Echtzeit; das steht jetzt im Kommentar.
  • Nicht modelliert: die invertierten Ausgänge an PB0/PB3 bei COM1x = 01 (ATTinyCore nutzt sie nicht).

Tests

  • Neu in attiny85-profile.test.ts: Signal an PB4 aus tiny_probe (analogWrite(4, 200) → 200/256 HIGH) sowie drei taktgenaue Registertests (Periode OCR1C + 1 mit CTC1, Sägezahn ohne CTC1, invertiert mit TOV1). Gegenprobe: ohne Korrektur sind alle vier rot.
  • Bestehende Tests: unverändert. Aus einem Test ist nur der Kommentar entfallen, der das fehlende Signal als bekannte Abweichung beschrieb.
  • npm run test:unit:emulator: 34 Dateien, 685 Tests grün, Korpus eingeschlossen (attiny_pwm_duty unverändert grün).
  • Leistung (npm run emulate -- … --board attiny85 --ms 1500 --repeat 7, M2 Pro): tiny_serial 10,9 × (vorher 10,9–11,3 ×), tiny_probe 10,8 ×.

Dokumentation

README des Pakets (Abschnitt avr8js-Korrekturen), Plan P6.2, M3-Bericht (Fund behoben statt Restpunkt), Statusdatei.

🤖 Generated with Claude Code

ttbombadil and others added 3 commits October 24, 2026 10:45
avr8js 0.21.1 drives no OC1A/OC1B signal when CTC1 is set, as ATTinyCore
configures analogWrite on PB1/PB4, and counts phase-correct without CTC1. On
the chip the counter runs from 0 to OCR1C in PWM mode and OC1x is high until
the match with OCR1x (datasheet 12.2.2). The profile now drives both outputs
from the counter and counts that sawtooth. Members are replaced as plain
properties: an accessor on the instance slowed the emulation from 11x to 8x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… title

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ttbombadil
ttbombadil merged commit 65c7b98 into feature/browser-emulation Oct 24, 2026
6 checks passed
@ttbombadil
ttbombadil deleted the fix/p6-2-attiny85-timer1-pwm branch October 24, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant