• AVR Freaks

Hot!Input Capture - single unexpected interrupt after enabling ICx (w/ no input event)

Author
ElwoodBlues
Junior Member
  • Total Posts : 40
  • Reward points : 0
  • Joined: 2015/10/26 11:00:37
  • Location: 0
  • Status: offline
2019/02/01 15:04:29 (permalink)
0

Input Capture - single unexpected interrupt after enabling ICx (w/ no input event)

I am observing an unexpected behavior with a simple input capture code.
static void init_HW ( bool init )
{
   IEC0CLR = IEC0_IC4_BIT; // disable ICx interrupt
   IC4CONCLR = 1<<15; // disable ICx module
   
   if( init )
   { // configure/enable Input Capture...
      IC4CON =
           ( 0b0<<15 ) // ON=0, ICx disabled
         + ( 0b1<< 8 ) // C32=1, use 32-bit timer
         + ( 0b00<< 5 ) // ICI<1:0>=00, interrupt on every capture event
         + (0b011<< 0 );// ICM<2:0>=011, capture on every rising edge
      IPC4CLR = (0b111<<10) + (0b11<<8); // clear ICx priority and subpriority
      IPC4SET = ( 6u<<10) + ( 1u<<8); // Set ICx priority = 6, subpriority = 1
      IFS0CLR = IFS0_IC4_BIT; // clear ICx interrupt flag
      IEC0SET = IEC0_IC4_BIT; // enable ICx interrupt
      IC4CONSET = 1<<15; // enable ICx module
// while( IC4CONbits.ICBNE ) IC4BUF; // flush ICxBUF
   }
}


void __ISR(_INPUT_CAPTURE_4_VECTOR, IPL6SOFT) IRin_ISR ( void )
{
  // do stuff
   IRL_IF_clr(); // clear interrupt flag
}

 
The issue is, in IRin_init_HW() just after the ICx module is enabled, (1) single interrupt always occurs, even though the ICx input pin is stable and not changing.

Why? Every time this function is called, always there is (1) single interrupt occurrence shortly after enabling the module.  

According to the PIC32MX docs, the ICxBUF should be cleared when the module is disabled/enabled, yes?  Even so, I tried intentionally flushin ICxBUF in case it was not empty (see commented-out line of code), but there is no change... still the (1) single (spurious?) interrupt occurs.

Any thoughts? 
#1

0 Replies Related Threads

    Jump to:
    © 2019 APG vNext Commercial Version 4.5