This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Comparator issue with Tiva series

These are the code sections relevant to comparator:
Configuration:
    SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP1);                // enable comparator 1
    GPIOPinTypeComparator(GPIO_PORTC_BASE, GPIO_PIN_4);         // Comparator input on pin PC4
    ComparatorRefSet(COMP_BASE,COMP_REF_2_371875V);
    ComparatorIntRegister(COMP_BASE,1,INTCOMP0Handler);
    ComparatorConfigure(COMP_BASE,1,COMP_TRIG_NONE|COMP_INT_HIGH|COMP_ASRCP_REF|COMP_OUTPUT_NORMAL);
    ComparatorIntDisable(COMP_BASE,1);
And interrupt handler:
void INTCOMP0Handler()
{
ROM_IntMasterDisable();
UARTprintf("comp value:%d\n", ComparatorValueGet(COMP_BASE, 1));
ComparatorIntClear(COMP_BASE,1);
SysCtlDelay(SysCtlClockGet()/10/3);
UARTprintf("Comparator Interrupt\n");
SysCtlDelay(SysCtlClockGet()/10/3);
ROM_IntMasterEnable();
}
All we are trying is that an input is given to a comparator Pin PC4. This is compared to internal reference. If at any point the value on PC4 is higher than the internal reference then interrupt should be raised. But somehow this code is continuously generating interrupts. 
Any help is appreciated.
Thanks,
3.14
  • Reading the driverlib manual, I get the impression that you should expect continuous interrupts with COMP_INT_HIGH (when the compare pin is over the reference, that is). If you want to only trigger one interrupt when the value *goes* over the reference, maybe COMP_INT_RISE is what you want.

    Also, please use the code formatting tool (can be found under 'Use rich formatting' if not visible otherwise, look for the symbol '</>' - makes it much easier to read code. I decided some time ago to not reply to anyone who doesn't do this, but you "met me halfway" by discarding all the non-essential code, so I made an exception.

  • Hi Veikko,

    I will make sure the code is correct in future.

    And you were on dot with your answer. It works as we required now.

    Thanks for your help
    3.14
  • Veikko Immonen said:
    decided...not to reply (those who don't format code), but you "met me halfway"...  discarded all non-essential code,

    Had to "Like" that commentary, Veikko!   Great minds think alike.  (at least yours qualifies...)

    There's so much "good" about this forum - yet the complete & total ABSENCE of any Forum GUIDELINES wreaks its usual - and most predictable HAVOC!

    Great power - unexplained - is unlikely to be used!    And each/every day such reveals - and remains, "Duly Noted."   (and uncorrected...)