From 0f2a3b0abf058d04f5368d7c1ce55131d5e319a0 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Mon, 21 Feb 2022 17:49:10 +0200 Subject: fix(timer): OCRH masking #117 --- src/peripherals/timer.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/peripherals/timer.spec.ts') diff --git a/src/peripherals/timer.spec.ts b/src/peripherals/timer.spec.ts index 27ef7fb..9330168 100644 --- a/src/peripherals/timer.spec.ts +++ b/src/peripherals/timer.spec.ts @@ -1245,6 +1245,17 @@ describe('timer', () => { expect(cpu.readData(R19)).toEqual(0x5); expect(cpu.readData(R20)).toEqual(0x3); }); + + it('should mask the unused bits of OCR1A when using fixed top values', () => { + const cpu = new CPU(new Uint16Array(0x1000)); + new AVRTimer(cpu, timer1Config); + cpu.writeData(TCCR1A, WGM10 | WGM11); // WGM: FastPWM, top 0x3ff + cpu.writeData(TCCR1B, WGM12); + cpu.writeData(OCR1AH, 0xff); + cpu.writeData(OCR1A, 0xff); + expect(cpu.readData(OCR1A)).toEqual(0xff); + expect(cpu.readData(OCR1AH)).toEqual(0x03); + }); }); describe('External clock', () => { -- cgit v1.2.3