aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/timer.ts
diff options
context:
space:
mode:
authorUri Shaked2022-03-22 23:23:28 +0200
committerUri Shaked2022-03-22 23:24:07 +0200
commit67638ca55e73dc9e8795743788205cdaca49f3f5 (patch)
treeed526cf3c2a09576583cc76bdda3f9d3dfbb6dca /src/peripherals/timer.ts
parent0.18.9 (diff)
downloadavr8js-67638ca55e73dc9e8795743788205cdaca49f3f5.tar.gz
avr8js-67638ca55e73dc9e8795743788205cdaca49f3f5.tar.bz2
avr8js-67638ca55e73dc9e8795743788205cdaca49f3f5.zip
fix(timer): Phase Correct mode overruns #119
Diffstat (limited to '')
-rw-r--r--src/peripherals/timer.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/peripherals/timer.ts b/src/peripherals/timer.ts
index 6167394..93b9d19 100644
--- a/src/peripherals/timer.ts
+++ b/src/peripherals/timer.ts
@@ -496,6 +496,11 @@ export class AVRTimer {
}
}
+ /** Expose the raw value of TCNT, for use by the unit tests */
+ get debugTCNT() {
+ return this.tcnt;
+ }
+
private updateWGMConfig() {
const { config, WGM } = this;
const wgmModes = config.bits === 16 ? wgmModes16Bit : wgmModes8Bit;
@@ -637,7 +642,15 @@ export class AVRTimer {
};
private phasePwmCount(value: u16, delta: u8) {
- const { ocrA, ocrB, ocrC, hasOCRC, TOP, tcntUpdated } = this;
+ const { ocrA, ocrB, ocrC, hasOCRC, TOP, MAX, tcntUpdated } = this;
+ if (!value && !TOP) {
+ delta = 0;
+ if (this.ocrUpdateMode === OCRUpdateMode.Top) {
+ this.ocrA = this.nextOcrA;
+ this.ocrB = this.nextOcrB;
+ this.ocrC = this.nextOcrC;
+ }
+ }
while (delta > 0) {
if (this.countingUp) {
value++;
@@ -683,7 +696,7 @@ export class AVRTimer {
}
delta--;
}
- return value;
+ return value & MAX;
}
private timerUpdated(value: number, prevValue: number) {