aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/timer.ts
diff options
context:
space:
mode:
authorUri Shaked2020-12-26 00:24:54 +0200
committerUri Shaked2020-12-26 00:24:54 +0200
commit02e5b211c6e31ca8f9ec19ff6ec52d4f5bbef568 (patch)
tree67a624b2baf932d2dfe7ef709ac32ead8e423ff8 /src/peripherals/timer.ts
parent0.14.6 (diff)
downloadavr8js-02e5b211c6e31ca8f9ec19ff6ec52d4f5bbef568.tar.gz
avr8js-02e5b211c6e31ca8f9ec19ff6ec52d4f5bbef568.tar.bz2
avr8js-02e5b211c6e31ca8f9ec19ff6ec52d4f5bbef568.zip
fix(timer): Overflow interrupt fires twice #80
fix #80
Diffstat (limited to '')
-rw-r--r--src/peripherals/timer.ts6
1 files changed, 5 insertions, 1 deletions
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) {