From 14dfcef719d06eec1dec34219607f84406f7e02b Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Mon, 21 Dec 2020 17:07:04 +0200 Subject: fix(timer): Output Compare issue #74 output compare doesn't work when the OCR register (OCRnA/OCRnB) equals to 0 fix #74 --- src/peripherals/timer.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/peripherals/timer.ts') diff --git a/src/peripherals/timer.ts b/src/peripherals/timer.ts index f10a49b..71c1982 100644 --- a/src/peripherals/timer.ts +++ b/src/peripherals/timer.ts @@ -299,7 +299,9 @@ export class AVRTimer { this.countingUp = true; this.tcntUpdated = true; this.cpu.updateClockEvent(this.count, 0); - this.timerUpdated(); + if (this.divider) { + this.timerUpdated(); + } }; this.cpu.writeHooks[config.OCRA] = (value: u8) => { this.nextOcrA = (this.highByteTemp << 8) | value; @@ -498,14 +500,13 @@ export class AVRTimer { private timerUpdated() { const value = this.tcnt; - - if (this.ocrA && value === this.ocrA) { + if (value === this.ocrA) { this.cpu.setInterruptFlag(this.OCFA); if (this.compA) { this.updateCompPin(this.compA, 'A'); } } - if (this.ocrB && value === this.ocrB) { + if (value === this.ocrB) { this.cpu.setInterruptFlag(this.OCFB); if (this.compB) { this.updateCompPin(this.compB, 'B'); -- cgit v1.2.3