You need to log in to create posts and topics.

ATmega328 Timer1 Input Capture issue

I am having trouble getting input capture working correctly when I toggle  ICES1 bit inside ISR.
Otherwise input capture working ok.

Goal: Measure Duty of 25khz PWM using Timer1 ICP
Using SimulIDE V1.2.0-RC1 & ATmega328

Possible SimulIDE ATmega328 Timer1 Input Capture issue

The following tests were performed on ICP1 (D8):
With 25khz, 20% Duty applied.

Rising-edge capture only: PASS
Falling-edge capture only: PASS
Serial.print = 0: 0 640

Alternating rising/falling by toggling ICES1 in the capture ISR: FAIL

Expected:
High time varies with duty.
Period remains constant.
Serial.print = 20: 320 640 (or close to)

Actual:
High time is always one complete period.
Measured period becomes two actual periods.
Serial.print = 50: 640 1280

Since both edge polarities work independently, the issue appears related to runtime switching of ICES1.

 

Uploaded files:

Hi and thanks for the detailed report.

I think that issue is already solved: https://simulide.com/p/forum/topic/the-hcsr04-doesnt-work-with-the-attiny2313/