AVR8 - Input Capture at ICP1 Pin

Quote from KerimF on April 18, 2025, 5:22 pmSimulIDE_1.1.0-R2055_Win32, W7
ATmega8ACSR
Bit_2 [ACIC]: enables the Input Capture functionTIMSK
Bit_5 [TICIE1]: enables Input Capture InterruptTCCR1B
Bit_7 [ICNC1]: Input Capture Noise Canceler for ICP1 input [delayed by four Oscillator cycles]
Bit_6 [ICES1]: Input Capture Edge Select for ICP1 input [0= falling edge, 1= rising edge]TIFR
Bit_5 [ICF1]: Input Capture Flag [cleared by writing a logic one to its bit location]============================================================
In the attached code, PowerAC_v1.zip:
ACSR, Bit_2 [ACIC] = 1, the Input Capture function enabled
TIMSK, Bit_5 [TICIE1] = 0, the Input Capture Interrupt disabled
TCCR1B, Bit_7 [ICNC1 = 1, the Input Capture Noise Canceler for ICP1 input enabled
TCCR1B, Bit_6 [ICES1] = 1, the Input Capture Edge Select for ICP1 input [rising edge]
TIFR, Bit_5 [ICF1]: BUG, the Input Capture Flag is not setPlease see in the attached test code:
1961 CHCK_Hz: 1962 SBIS Hz_In ; ICP1 1963 RJMP END_act 1964 1965 NOP ; [breakpoint is reached when ICP1=high] 1966 NOP 1967 NOP 1968 NOP 1969 NOP 1970 NOP 1971 1972 ; if ICF1=0, goto END_act: 1973 IN r17, TIFR 1974 SBRS r17, ICF1 1975 RJMP END_act 1976 1977 NOP ; [breakpoint is not reached]
Thank you.
Kerim
SimulIDE_1.1.0-R2055_Win32, W7
ATmega8
ACSR
Bit_2 [ACIC]: enables the Input Capture function
TIMSK
Bit_5 [TICIE1]: enables Input Capture Interrupt
TCCR1B
Bit_7 [ICNC1]: Input Capture Noise Canceler for ICP1 input [delayed by four Oscillator cycles]
Bit_6 [ICES1]: Input Capture Edge Select for ICP1 input [0= falling edge, 1= rising edge]
TIFR
Bit_5 [ICF1]: Input Capture Flag [cleared by writing a logic one to its bit location]
============================================================
In the attached code, PowerAC_v1.zip:
ACSR, Bit_2 [ACIC] = 1, the Input Capture function enabled
TIMSK, Bit_5 [TICIE1] = 0, the Input Capture Interrupt disabled
TCCR1B, Bit_7 [ICNC1 = 1, the Input Capture Noise Canceler for ICP1 input enabled
TCCR1B, Bit_6 [ICES1] = 1, the Input Capture Edge Select for ICP1 input [rising edge]
TIFR, Bit_5 [ICF1]: BUG, the Input Capture Flag is not set
Please see in the attached test code:
1961 CHCK_Hz:
1962 SBIS Hz_In ; ICP1
1963 RJMP END_act
1964
1965 NOP ; [breakpoint is reached when ICP1=high]
1966 NOP
1967 NOP
1968 NOP
1969 NOP
1970 NOP
1971
1972 ; if ICF1=0, goto END_act:
1973 IN r17, TIFR
1974 SBRS r17, ICF1
1975 RJMP END_act
1976
1977 NOP ; [breakpoint is not reached]
Thank you.
Kerim


Quote from KerimF on April 19, 2025, 2:44 amQuote from arcachofo on April 18, 2025, 8:23 pmHi.
I will have a look as soon as possible
Very sorry, by checking again, it seems that the line of ACSR was erased by mistake (that is the Input Capture function is not enabled).
I will restore it and test the code again.
Quote from arcachofo on April 18, 2025, 8:23 pmHi.
I will have a look as soon as possible
Very sorry, by checking again, it seems that the line of ACSR was erased by mistake (that is the Input Capture function is not enabled).
I will restore it and test the code again.

Quote from KerimF on April 19, 2025, 3:15 amI restored it:
LDI r16, (1<<ACIC) OUT ACSR, r16
But again, ICF1 flag is not set when ICP1 is high.
I restored it:
LDI r16, (1<<ACIC)
OUT ACSR, r16
But again, ICF1 flag is not set when ICP1 is high.
Uploaded files:

Quote from arcachofo on April 21, 2025, 9:52 amSeems that IC Unit is not activated in Atmega8.
To fix it open file: data/AVR/mega8/mega8_perif.xml
And add this line in Timer1:<icunit name="IC1" pin="PORTB0" icreg="ICR1L,ICR1H" bits="ICES1,ICNC1" interrupt="T1CAP" />
It should look like this:
<timer name="TIMER1" type="160" configregsA="TCCR1A" configregsB="TCCR1B" counter="TCNT1L,TCNT1H" clockpin="PORTD5" interrupt="T1_OVF" prescalers="0,1,8,64,256,1024,EXT_F,EXT_R" prselect="CS10,CS11,CS12" > <ocunit name="OC1A" pin="PORTB1" ocreg="OCR1AL,OCR1AH" bits="COM1A0,COM1A1" interrupt="T1COA" /> <ocunit name="OC1B" pin="PORTB2" ocreg="OCR1BL,OCR1BH" bits="COM1B0,COM1B1" interrupt="T1COB" /> <icunit name="IC1" pin="PORTB0" icreg="ICR1L,ICR1H" bits="ICES1,ICNC1" interrupt="T1CAP" /> </timer>
Seems that IC Unit is not activated in Atmega8.
To fix it open file: data/AVR/mega8/mega8_perif.xml
And add this line in Timer1:
<icunit name="IC1" pin="PORTB0" icreg="ICR1L,ICR1H" bits="ICES1,ICNC1" interrupt="T1CAP" />
It should look like this:
<timer name="TIMER1" type="160" configregsA="TCCR1A" configregsB="TCCR1B"
counter="TCNT1L,TCNT1H"
clockpin="PORTD5"
interrupt="T1_OVF"
prescalers="0,1,8,64,256,1024,EXT_F,EXT_R"
prselect="CS10,CS11,CS12" >
<ocunit name="OC1A" pin="PORTB1" ocreg="OCR1AL,OCR1AH" bits="COM1A0,COM1A1" interrupt="T1COA" />
<ocunit name="OC1B" pin="PORTB2" ocreg="OCR1BL,OCR1BH" bits="COM1B0,COM1B1" interrupt="T1COB" />
<icunit name="IC1" pin="PORTB0" icreg="ICR1L,ICR1H" bits="ICES1,ICNC1" interrupt="T1CAP" />
</timer>


Quote from KerimF on May 28, 2025, 12:20 pmSimulIDE_1.1.0-R2069_Win32, W7
ATmega8I am very sorry. Only now, while working on a new project/code, I discovered that I was wrong from the beginning about ACIC flag.
ACSR
Bit_2 [ACIC]: enables the Input Capture function via ICP1 or ACO (the comparator output).Actually, ACIC=0, not 1, to enable the Input Capture at ICP1 pin.
SimulIDE_1.1.0-R2069_Win32, W7
ATmega8
I am very sorry. Only now, while working on a new project/code, I discovered that I was wrong from the beginning about ACIC flag.
ACSR
Bit_2 [ACIC]: enables the Input Capture function via ICP1 or ACO (the comparator output).
Actually, ACIC=0, not 1, to enable the Input Capture at ICP1 pin.