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?

Parents
  • Very interesting post; we would like the same functionality for a similar purpose. Given that the crossing event (being edge-triggered) may be missed, is it possible to connect the Compare Result register (0x400) to the PPI, or is that denied to it not being within the Events register groupings? My suggestion is based on the fact that the PPI link could in theory be set to any register, but I haven't tried this. The datasheet states Pointer to event register. Accepts only addresses to registers from the Event group but that might be misleading and any register address could perhaps work .. The Compare Result register register looks like t is the direct comparator output without any edge detection involved.

  • I'm now wondering about the PPI 16MHz sample clock, which is effectively a synchronous sample of an asynchronous event (the comparator output transition) and is therefore subject to metastable issues. From the documentation:

    On each PPI channel, the signals are synchronized to the 16 MHz clock, to avoid any internal violation of setup and hold timings. As a consequence, events that are synchronous to the 16 MHz clock will be delayed by one clock period, while other asynchronous events will be delayed by up to one 16 MHz clock period. Note that shortcuts (as defined in the SHORTS register in each peripheral) are not affected by this 16 MHz synchronization, and are therefore not delayed.

    The shortcut register might be a useful alternative, but it's not immediately clear how that can be used on the comparator. It provides a fast (non-PPI) access to Start, Stop and Sample Tasks on the comparator. This implies a better way of updating the Result register without using the PPI:

    The immediate value of the comparator can be sampled to RESULT register by triggering the SAMPLE task.

    Worth trying the SHORTS, methinks; I see no link from Output so we can only try the Up, Down and Cross events to trigger Sample and hence bypass the PPI and potential metastable condition.

  • The SHORTS can be seen as an internal PPI system for each peripheral. You still need the COMP to generate the events for the SHORT to work, i.e. there must be a valid crossing on the pin that is detected by the COMP.

Reply Children
No Data
Related