This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Comparator External Connections

I am attempting to use the COMP section to build a relaxation oscillator. There appear to be a number of interactions between sections, some of which are subtly documented and some for which I find no documentation. For instance, the inability to set a GPIO output once a task is connected to a pin is documented but well-hidden. The fact that enabling a pin as a comparator input completely disables both digital inputs and digital outputs is not documented anywhere that I can find.

Bottom line is that I have everything working nicely as it should, except that the comparator sometimes appears to miss a transition and thereafter is hung. I fundamentally just need to be able to place the comparator output on a digital output pin, but the only way I can find to do that is via the crossing events from the comparator, feeding set and clr tasks of GPIOTE. This causes the same sort of problems as the early IBM PCs using edge-triggered interrupts: If you miss one, you're dead forever. Is there a better way to get the comparator output to appear on a pin? If not, how best can I initialize things to ensure that I don't miss a transition?

  • Careful on the clamp diodes they'll take very little. You should never see 5V on a scope as the pin will be Vcc+0.3v max otherwise it's passing current to Vcc through the ESD diode. 5V will be a big current and will blow them. Use a resistor ;)

    "I need to set up the comparator to use an external reference"

    I think you've already got what I was about to say which is do it the other way around, internal reference and external input, single ended, and adjust the lower&upper limits (these are basically acting as configurable hysteresis).

    I can't really understand what you're trying to do. If the input is 3v+ then refsel 0-3 won't work. Vdd will work if the chip is getting more than 3v. Same with Adc pin but remember Vdd must be greater than Adc pin voltage.

    Of course Vdd might be noisy, that's the whole point to the Adc ref pin. Maybe you should just do the normal thing of using refsel 0-2 and dropping the 3v+ down with a voltage divider (aka two resistors). Any reason why you haven't? For sure you need to if it gives to 5v!

    * I have guessed you're using an NRF52 series.

  • Slight misunderstanding on the 5V. I have no intention of running there. This was just an accidental, momentary, and current-limited blip to 5V that caused an unexpected event. After it happened it, I reported it as a potential troubleshooting clue.

    Likewise RefSel 3V was a coincidental discovery as I tried all values of REFSEL. Again no intention of using it.

    COMP works just as documented for all values of REFSEL except the one I really need to use, which is 7 - ExtRef. I'm also thinking there's something I'm not understanding correctly, in that the hysteresis using the other reference choices works only if I keep the limits near min & max; i.e. UP at 0x38 or above, and DN at 0x04 or below. Also why it doesn't work when I set ExtRef (on Ain7) to the same 3.3V as Vdd. REFSEL = 4 works, REFSEL = 7 does not, regardless of TH settings.

  • I just discovered this erratum. So, Nordic is just going to throw up their hands and say I bought a pig in a poke?!? I'm glad I didn't actually lay out a board based on the chip working as advertised!

    3.33 [113] COMP: Single-ended mode with external
    reference is not functional
    This anomaly applies to Revision 2, build codes CIAA-Ex0, QFAA-Ex0, QFAB-Ex0.
    It was inherited from the previous IC revision Revision 1.
    Symptoms
    COMP output is not correct.
    Conditions
    COMP is used in single-ended mode with external reference.
    Consequences
    COMP cannot be used in this mode.
    Workaround
    None.

  • I've not used external reference so haven't hit that.

    All you need is two resistors to limit the input voltage to a value lower than an internal reference then you can use that. Standard practice.

  • BTW I don't know what you're detecting but it's starting to sound like a high and low signal. Use GPIOTE for that. 

Related