•
Select the desired hysteresis with COMPCTRLx.HYSTEN and COMPCTRLx.HYST. See
•
Select the comparator speed versus power with COMPCTRLx.SPEED. See
for more details.
•
Select the interrupt source with COMPCTRLx.INTSEL.
•
Select the positive and negative input sources with the COMPCTRLx.MUXPOS and
COMPCTRLx.MUXNEG bits. See
for more details.
•
Select the filtering option with COMPCTRLx.FLEN.
•
Select standby operation with Run in Standby bit (COMPCTRLx.RUNSTDBY).
The individual comparators are enabled by writing a '1' to the Enable bit in the Comparator x Control
registers (COMPCTRLx.ENABLE). The individual comparators are disabled by writing a '0' to
COMPCTRLx.ENABLE. Writing a '0' to CTRLA.ENABLE will also disable all the comparators, but will not
clear their COMPCTRLx.ENABLE bits.
42.6.2.4. Starting a Comparison
Each comparator channel can be in one of two different measurement modes, determined by the Single
bit in the Comparator x Control register (COMPCTRLx.SINGLE):
•
Continuous measurement
•
Single-shot
After being enabled, a start-up delay is required before the result of the comparison is ready. This start-up
time is measured automatically to account for environmental changes, such as temperature or voltage
supply level, and is specified in
Electrical Characteristics
. During the start-up time, the COMP output is
not available.
The comparator can be configured to generate interrupts when the output toggles, when the output
changes from '0' to '1' (rising edge), when the output changes from '1' to '0' (falling edge) or at the end of
the comparison. An end-of-comparison interrupt can be used with the single-shot mode to chain further
events in the system, regardless of the state of the comparator outputs. The interrupt mode is set by the
Interrupt Selection bit group in the Comparator Control register (COMPCTRLx.INTSEL). Events are
generated using the comparator output state, regardless of whether the interrupt is enabled or not.
Related Links
on page 1147
Continuous Measurement
Continuous measurement is selected by writing COMPCTRLx.SINGLE to zero. In continuous mode, the
comparator is continuously enabled and performing comparisons. This ensures that the result of the latest
comparison is always available in the Current State bit in the Status A register (STATUSA.STATEx).
After the start-up time has passed, a comparison is done and STATUSA is updated. The Comparator x
Ready bit in the Status B register (STATUSB.READYx) is set, and the appropriate peripheral events and
interrupts are also generated. New comparisons are performed continuously until the
COMPCTRLx.ENABLE bit is written to zero. The start-up time applies only to the first comparison.
In continuous operation, edge detection of the comparator output for interrupts is done by comparing the
current and previous sample. The sampling rate is the GCLK_AC frequency. An example of continuous
measurement is shown in the
Atmel SAM L22G / L22J / L22N [DATASHEET]
Atmel-42402E-SAM L22G / L22J / L22N_Datasheet_Complete-07/2016
1034