Atmega32A Input Capture interrupt can't be cleared

Go To Last Post
4 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.

  • 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.

It was my first time to use AVR MCU. I didn't have any idea about input capture mudule of AVR MCU.

I was finished other functions and now I'll have a try with what you advised.

Thanks.

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

fatcasper wrote:
So I used the Input Capture function(TICIE1),but I can't clear the interrupt flag(ICF1) when the interrupt is trigered.
fatcasper wrote:
TM1_CAP_FLG_CLR(); //actually not needed

Now, I realize that you have other paths to follow with kartman's suggestions.  But your thread title and text say "can't be cleared".  What led you to this conclusion?

 

Also, please post a complete test program.  Tell AVR model, clock speed, Vcc level.  Tell fuse settings.  Tell language, toolchain, version, and optimization settings.  Ideally post a complete schematic but at least tell what is connected to the pertinent pins.  Tell the voltage levels >>right at those pins<< when testing.  Tell how you are testing; tell what you expect to happen; tell what >>is<< happening.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Nov 30, 2017 - 02:05 PM