COMP — Comparator

The comparator (COMP) compares an input voltage (VIN+) against a second input voltage (VIN-). VIN+ can be derived from an analog input pin (AIN0-AIN7). VIN- can be derived from multiple sources depending on the operation mode of the comparator.

The main features of COMP are the following:

Figure 1. Comparator overview
Diagram: Comparator overview

Once enabled (using the ENABLE register), the comparator is started by triggering the START task and stopped by triggering the STOP task. The comparator will generate a READY event to indicate when it is ready for use and the output is correct. The delay between START and READY is tINT_REF,START if an internal reference is selected, or t COMP,START if an external reference is used. When the COMP module is started, events will be generated every time VIN+ crosses VIN-.

Operation modes

The comparator can be configured to operate in two main operation modes: differential mode and single-ended mode. See the MODE register for more information. In both operation modes, the comparator can operate in different speed and power consumption modes (low-power, normal and high-speed). High-speed mode will consume more power compared to low-power mode, and low-power mode will result in slower response time compared to high-speed mode.

Use the PSEL register to select any of the AIN0-AIN7 pins as VIN+ input, regardless of the operation mode selected for the comparator. The source of VIN- depends on which of the following operation mode are used:

  • Differential mode - Derived directly from AIN0 to AIN7
  • Single-ended mode - Derived from VREF. VREF can be derived from VDD, AIN0-AIN7 or internal 1.2 V, 1.8 V and 2.4 V references.

The selected analog pins will be acquired by the comparator once it is enabled.

An optional hysteresis on VIN+ and VIN- can be enabled when the module is used in differential mode through the HYST register. In single-ended mode, VUP and VDOWN thresholds can be set to implement a hysteresis using the reference ladder (see Comparator in single-ended mode ). This hysteresis is in the order of magnitude of VDIFFHYST, and shall prevent noise on the signal to create unwanted events. See Hysteresis example where VIN+ starts below VUP for an illustration of the effect of an active hysteresis on a noisy input signal.

An upward crossing will generate an UP event and a downward crossing will generate a DOWN event. The CROSS event will be generated every time there is a crossing, independent of direction.

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

Shared resources

The COMP shares analog resources with other analog peripherals.

While it is possible to use the SAADC at the same time as the COMP, selecting the same analog input pin for both peripherals is not supported.

Additionally, COMP shares registers and other resources with other peripherals that have the same ID as the COMP. See Peripherals with shared ID for more information.

The COMP peripheral shall not be disabled (by writing to the ENABLE register) before the peripheral has been stopped. Failing to do so may result in unpredictable behavior.

Differential mode

In differential mode, the reference input VIN- is derived directly from one of the AINx pins.

Before enabling the comparator via the ENABLE register, the following registers must be configured for the differential mode:

Figure 2. Comparator in differential mode
Comparator in differential mode
Note: Depending on the device, not all the analog inputs may be available for each MUX. See definitions for PSEL and EXTREFSEL for more information about which analog pins are available on a particular device.

When the HYST register is turned on during this mode, the output of the comparator and associated events do the following:

This behavior is illustrated in the following figure.

Figure 3. Hysteresis enabled in differential mode

Single-ended mode

In single-ended mode, VIN- is derived from the reference ladder.

Before enabling the comparator via the ENABLE register, the following registers must be configured for the single-ended mode:

The reference ladder uses the reference voltage (VREF) to derive two new voltage references, VUP and VDOWN. VUP and VDOWN are configured using THUP and THDOWN respectively in the TH register. VREF can be derived from any of the available reference sources, configured using the EXTREFSEL and REFSEL registers as shown in the following figure. When AREF is selected in the REFSEL register, the EXTREFSEL register is used to select one of the AIN0-AIN7 analog input pins as reference input. The selected analog pins will be acquired by the comparator once it is enabled.

Figure 4. Comparator in single-ended mode
Diagram: Comparator in single-ended mode
Note: Depending on the device, not all the analog inputs may be available for each MUX. See definitions for PSEL and EXTREFSEL for more information about which analog pins are available on a particular device.

When the comparator core detects that VIN+ > VIN-, i.e. ABOVE as per the RESULT register, VIN- will switch to VDOWN. When VIN+ falls below VIN- again, VIN- will be switched back to VUP. By specifying VUP larger than VDOWN, a hysteresis can be generated as illustrated in the following figures.

Writing to HYST has no effect in single-ended mode, and the content of this register is ignored.

Figure 5. Hysteresis example where VIN+ starts below VUP
Hysteresis example where VIN+ starts below VUP
Figure 6. Hysteresis example where VIN+ starts above VUP
Hysteresis example where VIN+ starts above VUP

Registers

Instances

InstanceBase addressDescription
COMP0x40013000General purpose comparator

Register overview

RegisterOffsetDescription
TASKS_START0x000Start comparator
TASKS_STOP0x004Stop comparator
TASKS_SAMPLE0x008Sample comparator value
EVENTS_READY0x100COMP is ready and output is valid
EVENTS_DOWN0x104Downward crossing
EVENTS_UP0x108Upward crossing
EVENTS_CROSS0x10CDownward or upward crossing
SHORTS0x200Shortcuts between local events and tasks
INTEN0x300Enable or disable interrupt
INTENSET0x304Enable interrupt
INTENCLR0x308Disable interrupt
RESULT0x400Compare result
ENABLE0x500COMP enable
PSEL0x504Pin select
REFSEL0x508Reference source select for single-ended mode
EXTREFSEL0x50CExternal reference select
TH0x530Threshold configuration for hysteresis unit
MODE0x534Mode configuration
HYST0x538Comparator hysteresis enable

TASKS_START

Address offset: 0x000

Start comparator

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STARTStart comparator
Trigger1Trigger task

TASKS_STOP

Address offset: 0x004

Stop comparator

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STOPStop comparator
Trigger1Trigger task

TASKS_SAMPLE

Address offset: 0x008

Sample comparator value

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_SAMPLESample comparator value
Trigger1Trigger task

EVENTS_READY

Address offset: 0x100

COMP is ready and output is valid

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_READYCOMP is ready and output is valid
NotGenerated0Event not generated
Generated1Event generated

EVENTS_DOWN

Address offset: 0x104

Downward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_DOWNDownward crossing
NotGenerated0Event not generated
Generated1Event generated

EVENTS_UP

Address offset: 0x108

Upward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_UPUpward crossing
NotGenerated0Event not generated
Generated1Event generated

EVENTS_CROSS

Address offset: 0x10C

Downward or upward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_CROSSDownward or upward crossing
NotGenerated0Event not generated
Generated1Event generated

SHORTS

Address offset: 0x200

Shortcuts between local events and tasks

Bit number313029282726252423222120191817161514131211109876543210
IDEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWREADY_SAMPLEShortcut between event READY and task SAMPLE
Disabled0Disable shortcut
Enabled1Enable shortcut
BRWREADY_STOPShortcut between event READY and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
CRWDOWN_STOPShortcut between event DOWN and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
DRWUP_STOPShortcut between event UP and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
ERWCROSS_STOPShortcut between event CROSS and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut

INTEN

Address offset: 0x300

Enable or disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWREADYEnable or disable interrupt for event READY
Disabled0Disable
Enabled1Enable
BRWDOWNEnable or disable interrupt for event DOWN
Disabled0Disable
Enabled1Enable
CRWUPEnable or disable interrupt for event UP
Disabled0Disable
Enabled1Enable
DRWCROSSEnable or disable interrupt for event CROSS
Disabled0Disable
Enabled1Enable

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWREADYWrite '1' to enable interrupt for event READY
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWDOWNWrite '1' to enable interrupt for event DOWN
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
CRWUPWrite '1' to enable interrupt for event UP
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCROSSWrite '1' to enable interrupt for event CROSS
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWREADYWrite '1' to disable interrupt for event READY
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWDOWNWrite '1' to disable interrupt for event DOWN
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
CRWUPWrite '1' to disable interrupt for event UP
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCROSSWrite '1' to disable interrupt for event CROSS
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled

RESULT

Address offset: 0x400

Compare result

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARRESULTResult of last compare. Decision point SAMPLE task.
Below0Input voltage is below the threshold (VIN+ < VIN-)
Above1Input voltage is above the threshold (VIN+ > VIN-)

ENABLE

Address offset: 0x500

COMP enable

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWENABLEEnable or disable COMP
Disabled0Disable
Enabled2Enable

PSEL

Address offset: 0x504

Pin select

Bit number313029282726252423222120191817161514131211109876543210
IDAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWPSELAnalog pin select
AnalogInput00AIN0 selected as analog input
AnalogInput11AIN1 selected as analog input
AnalogInput22AIN2 selected as analog input
AnalogInput33AIN3 selected as analog input
AnalogInput44AIN4 selected as analog input
AnalogInput55AIN5 selected as analog input
AnalogInput66AIN6 selected as analog input
AnalogInput77AIN7 selected as analog input

REFSEL

Address offset: 0x508

Reference source select for single-ended mode

Bit number313029282726252423222120191817161514131211109876543210
IDAAA
Reset 0x0000000400000000000000000000000000000100
IDR/WFieldValue IDValueDescription
ARWREFSELReference select
Int1V20VREF = internal 1.2 V reference (VDD >= 1.7 V)
Int1V81VREF = internal 1.8 V reference (VDD >= VREF + 0.2 V)
Int2V42VREF = internal 2.4 V reference (VDD >= VREF + 0.2 V)
VDD4VREF = VDD
ARef5VREF = AREF

EXTREFSEL

Address offset: 0x50C

External reference select

Bit number313029282726252423222120191817161514131211109876543210
IDAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEXTREFSELExternal analog reference select
AnalogReference00Use AIN0 as external analog reference
AnalogReference11Use AIN1 as external analog reference
AnalogReference22Use AIN2 as external analog reference
AnalogReference33Use AIN3 as external analog reference
AnalogReference44Use AIN4 as external analog reference
AnalogReference55Use AIN5 as external analog reference
AnalogReference66Use AIN6 as external analog reference
AnalogReference77Use AIN7 as external analog reference

TH

Address offset: 0x530

Threshold configuration for hysteresis unit

Bit number313029282726252423222120191817161514131211109876543210
IDBBBBBBAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWTHDOWN[63:0]VDOWN = (THDOWN+1)/64*VREF
BRWTHUP[63:0]VUP = (THUP+1)/64*VREF

MODE

Address offset: 0x534

Mode configuration

Bit number313029282726252423222120191817161514131211109876543210
IDBAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWSPSpeed and power modes
Low0Low-power mode
Normal1Normal mode
High2High-speed mode
BRWMAINMain operation modes
SE0Single-ended mode
Diff1Differential mode

HYST

Address offset: 0x538

Comparator hysteresis enable

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWHYSTComparator hysteresis
NoHyst0Comparator hysteresis disabled
Hyst50mV1Comparator hysteresis enabled

Electrical specification

COMP Electrical Specification

SymbolDescriptionMin.Typ.Max.Units
tPROPDLY,LPPropagation delay, Low-power mode10.6µs
tPROPDLY,NPropagation delay, Normal mode10.2µs
tPROPDLY,HSPropagation delay, High-speed mode10.1µs
VDIFFHYSTOptional hysteresis applied to differential input103090mV
VVDD-VREFRequired difference between VDD and a selected VREF, VDD > VREF0.3V
tINT_REF,STARTStartup time for the internal bandgap reference5080µs
EINT_REFInternal bandgap reference error-33%
VINPUTOFFSETInput offset-1515mV
tCOMP,STARTStartup time for the comparator core3µs
1 Propagation delay is with 10 mV overdrive.