Atmega32A Input Capture interrupt can't be cleared

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using Atmega32A to calculate the frequency from pressure sensor.

So I used the Input Capture function(TICIE1),but I can't clear the interrupt flag(ICF1) when the interrupt is trigered.

Also,I didn't enable the OCIE1A, OCIE1B, TOIE1,but they will be trigered when the I was debugging.

<#define TM1_CAP_INTR_EN()    { sbi(TIMSK, TICIE1); }
#define TM1_CAP_INTR_DIS()    { cbi(TIMSK, TICIE1); }

#define TM1_CAP_FLG_CLR()    { TIFR = _BV(ICF1); }

#define TM1_START()            { TCCR1B |= 0x03; }
#define TM1_STOP()            { TCCR1B &= 0xF8; }

ISR(TIMER1_CAPT_vect)
{
    if(!ucValCnt){
        TM1_START();
        ucValCnt++;
    }else{
        ucValCnt++;
        if(ucValCnt >= EVENT_CAP_CNT){
            ucValCnt = 0;
            uiEventCapVal = ICR1;
            TM1_STOP();
            TCNT1 = 0;
            ICR1 = 0;
            TM1_CAP_INTR_DIS();
            TM1_CAP_FLG_CLR();    //actually not needed
            F_INPUT_CAP_SW_END = ~F_INPUT_CAP_SW_END;
        }
    }
}

>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The capture flag should be cleared by the hardware when it vectors to the isr.
Why would you stop and start the timer? The negates any advantage of using input capture. Usually one would leave TCNT alone and calc the difference between two captures.