From 02e5b211c6e31ca8f9ec19ff6ec52d4f5bbef568 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 26 Dec 2020 00:24:54 +0200 Subject: fix(timer): Overflow interrupt fires twice #80 fix #80 --- src/peripherals/timer.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/peripherals/timer.ts') diff --git a/src/peripherals/timer.ts b/src/peripherals/timer.ts index 957aa78..6ea29e3 100644 --- a/src/peripherals/timer.ts +++ b/src/peripherals/timer.ts @@ -445,7 +445,7 @@ export class AVRTimer { // OCRUpdateMode.Bottom only occurs in Phase Correct modes, handled by phasePwmCount(). // Thus we only handle TOVUpdateMode.Top or TOVUpdateMode.Max here. if ( - (newVal === TOP || overflow) && + (newVal === TOP || (overflow && val < TOP)) && (this.tovUpdateMode == TOVUpdateMode.Top || TOP === this.MAX) ) { cpu.setInterruptFlag(this.OVF); @@ -453,7 +453,11 @@ export class AVRTimer { } } if (this.tcntUpdated) { + const { TOP } = this; this.tcnt = this.tcntNext; + if (this.tcnt === TOP && (this.tovUpdateMode == TOVUpdateMode.Top || TOP === this.MAX)) { + cpu.setInterruptFlag(this.OVF); + } this.tcntUpdated = false; } if (this.updateDivider) { -- cgit v1.2.3