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 in Launchpad TM4C123GXL

I've been testing the cool comparator feature, where you can directly forward the ADC result to a comparator and get an interrupt based on predefined condition.

There are several options like

ADC_COMP_INT_LOW_ALWAYS

ADC_COMP_INT_HIGH_ONCE

ADC_COMP_INT_MID_ALWAYS ...


But for my application I would need to get an interrupt every time the value goes OUT of the region specified by

ADCComparatorRegionSet(ADC0_BASE, 0, 300, 400);

It is a simplest control loop, where you want to flip a transistor the other way every time voltage goes outside of the allowed range. I don't see a way how to do that with TM4C comparator- am I missing something?

  • Hello Michal,

    That would require you to use two comparators. One set to HIGH ONCE and another set to LOW ONCE. This way you can know based on the interrupt from the comparator which side the result was.

    Regards
    Amit
  • This is a swag - but in the past we achieved this, "Window comparator" feature with just a single comparator - by changing the "trip set-point voltage" and the sense (then) of the comparator's output. I've not reviewed the "fine detail" but suspect - if that level of control is enabled w/in the MCU - you may eliminate the need for the 2nd analog comparator.

    Basically - you're trading ease of set-up/config analog comparator programming for the "saving" of those 3 additional comparator inputs.

    As an aside - we've never found the internal analog comparator's voltage selection levels to be fine enough for our operation.  Thus we inject via a DAC - or other quickly/easily controllable source. If you need those 3 spare pins this may warrant your trial/examination...

  • Thanks, guys!
    I'll try both variants to see what works for me better. It's a bit silly that we have an option to get interrupts when signal is in the area, but not the other way around :)
  • There's a reserved value for the interrupt register config between MID are interrupt and HIGH area interrupt. Maybe something for future versions?
  • Michal Elias said:
    It's a bit silly that we have an option to get interrupts when signal is in the area, but not the other way around :)

    Mon ami - that "silliness" may prove your salvation!

    Consider - set your comparator to trip when the signal "just" drops below your lower threshold. 

    And then - periodically (speed you must determine) set it to trip when the signal "just" rises above your upper threshold. 

    Yes - "monkey motion is "in play" - yet your achieving a fully functional "Window Comparator" (as Amit confirmed) classically demands two comparators.  And the methods I've proposed "trade" far more intensive SW "activity" for the saving of 3 (additional) analog comparator pins.  (which you may not have - or may not wish to employ in such manner...)

    Should yours be a highly critical signal - with no tolerance for slight system response delay - suggested tradeoff, "fails."  But - in the real world - when parts & space are at premium - such "dynamic change" of ports/pins has long been recognized as best/brightest practice.   (we used such on world's top selling, "Set Top Box!")