Analog comparator

You can configure the MCA ADC lines to act as an analog window comparator and generate an IRQ depending on the voltage level in the input. This feature allows applications to be notified of this event instead of needing to periodically poll the input for its value.

Since this is an extension on the ADC driver, reading the input is also possible by using the same sysfs entry. The same formulas, channel mapping, and voltage reference also apply.

The comparator can be seen as a digital output that depends on two limits or thresholds: when the input is between the two limits the comparator's output will be 1, and 0 when it is outside of the limits. If only one limit is needed, then the higher threshold should be set above the maximum (4096) and use the lower one.

The image below helps to understand when the edges are generated, basically, entering the window will generate a rising edge and leaving it will generate a falling one, regardless from which threshold it was (upper or lower). This means that it is likely to be necessary an extra read to the analog input to determine in which of the two zones outside the window the voltage is.

Device tree bindings and customization

The MCA ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/digi,mca-cc6ul-adc.txt.

You can specify the list of channels you want to use as comparators with property digi,comparator-ch-list.

CAUTION! Both adc-ch-list and comparator-ch-list are exclusive, if a channel is mistakenly included in both, adc-ch-list would have priority and a warning would be logged in the kernel.

MCA-enabled ADC channels and voltage reference

This example shows how to enable the analog comparator on MCA ADC channel 3 using the property digi,comparator-ch-list. Channels 0 and 4 are used as normal ADC channels. The voltage reference property is the same for both ADCs and Comparators, refer to the ADC configuration chapter for more details on how to configure this property.

&mca_adc {
    digi,adc-ch-list = <0 4>;
    digi,comparator-ch-list = <3>;
    digi,adc-vref = <3000000>;
};

Using the comparators

The comparator driver is designed on top of the standard Industrial I/O (IIO) device drivers that can be accessed from the sysfs or from user applications.

Sysfs access

When configured as analog comparator, the MCA ADC driver (MCA and i.MX6UL) will create the corresponding device entries in the IIO sysfs directory (/sys/bus/iio/devices). Find the IIO sysfs path that corresponds to the MCA ADC (the one whose name is mca-cc6ul-adc):

~# cat /sys/bus/iio/devices/iio\:device0/name
mca-cc6ul-adc
~# cat /sys/bus/iio/devices/iio\:device1/name
2198000.adc

In this example, device0 corresponds to the MCA ADC.

The driver creates the following file entries per analog comparator channel, where X is the channel number:

Sample configuration

The following script configures channel 3 analog comparator as follows:

Sample application

An example application called adc_cmp_sample is included in the dey-examples package of meta-digi layer. This application shows how to subscribe for comparator IRQs and decode them.

To see the syntax of the application, run:

Sample application
~# adc_cmp_sample --help

Find the source code of the application under ${DEY_INSTALL_DIR}/sources/meta-digi/meta-digi-dey/dey-examples/files/adc_cmp_sample/ and the recipe at ${DEY_INSTALL_DIR}/sources/meta-digi-dey/recipes-digi/dey-examples/dey-examples-adc-cmp.bb.