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.

Main features of the comparator are:

  • Input range from 0 V to VDD
  • Single-ended mode
    • Fully flexible hysteresis using a 64-level reference ladder
  • Differential mode
    • Configurable 50 mV hysteresis
  • Reference inputs (VREF):
    • VDD
    • External reference from AIN0 to AIN7 (between 0 V and VDD)
    • Internal references 1.2 V, 1.8 V and 2.4 V
  • Three speed/power consumption modes: low-power, normal and high-speed
  • Single-pin capacitive sensor support
  • Event generation on output changes
    • UP event on VIN- > VIN+
    • DOWN event on VIN- < VIN+
    • CROSS event on VIN+ and VIN- crossing
    • READY event on core and internal reference (if used) ready
Figure 1. Comparator overview

Once enabled (using the ENABLE register), the comparator is started by triggering the START task and stopped by triggering the STOP task. After a start-up time of tCOMP,START, the comparator will generate a READY event to indicate that it is ready for use and that its output is correct. 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, irregardless of the operation mode selected for the comparator. The source of VIN- depends on which operation mode is 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 Figure 4). This hysteresis is in the order of magnitude of 50 mV, and shall prevent noise on the signal to create unwanted events. See Figure 5 for 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.

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
Restriction: 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 HYST register is turned on while in this mode, the output of the comparator (and associated events) will change from ABOVE to BELOW whenever VIN+ becomes lower than VIN- - (VDIFFHYST / 2). It will also change from BELOW to ABOVE whenever VIN+ becomes higher than VIN- + (VDIFFHYST / 2). This behavior is illustrated in Figure 3.

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 illustrated in Figure 4. 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
Restriction: 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 Figure 5 and Figure 6.

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

Figure 6. Hysteresis example where VIN+ starts above VUP

Registers

Table 1. Instances
Base addressPeripheralInstanceDescriptionConfiguration
0x40013000COMPCOMPGeneral purpose comparator  
Table 2. 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 
SHORTS0x200Shortcut register 
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 
ISOURCE0x53CCurrent source select on analog input 

SHORTS

Address offset: 0x200

Shortcut register

Bit number313029282726252423222120191817161514131211109876543210
Id                           EDCBA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY_SAMPLE  

Shortcut between READY event and SAMPLE task

See EVENTS_READY and TASKS_SAMPLE

   Disabled0Disable shortcut
   Enabled1Enable shortcut
BRWREADY_STOP  

Shortcut between READY event and STOP task

See EVENTS_READY and TASKS_STOP

   Disabled0Disable shortcut
   Enabled1Enable shortcut
CRWDOWN_STOP  

Shortcut between DOWN event and STOP task

See EVENTS_DOWN and TASKS_STOP

   Disabled0Disable shortcut
   Enabled1Enable shortcut
DRWUP_STOP  

Shortcut between UP event and STOP task

See EVENTS_UP and TASKS_STOP

   Disabled0Disable shortcut
   Enabled1Enable shortcut
ERWCROSS_STOP  

Shortcut between CROSS event and STOP task

See EVENTS_CROSS and TASKS_STOP

   Disabled0Disable shortcut
   Enabled1Enable shortcut
 

INTEN

Address offset: 0x300

Enable or disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
Id                            DCBA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY  

Enable or disable interrupt for READY event

See EVENTS_READY

   Disabled0Disable
   Enabled1Enable
BRWDOWN  

Enable or disable interrupt for DOWN event

See EVENTS_DOWN

   Disabled0Disable
   Enabled1Enable
CRWUP  

Enable or disable interrupt for UP event

See EVENTS_UP

   Disabled0Disable
   Enabled1Enable
DRWCROSS  

Enable or disable interrupt for CROSS event

See EVENTS_CROSS

   Disabled0Disable
   Enabled1Enable
 

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
Id                            DCBA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY  

Write '1' to Enable interrupt for READY event

See EVENTS_READY

   Set1Enable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
BRWDOWN  

Write '1' to Enable interrupt for DOWN event

See EVENTS_DOWN

   Set1Enable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
CRWUP  

Write '1' to Enable interrupt for UP event

See EVENTS_UP

   Set1Enable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
DRWCROSS  

Write '1' to Enable interrupt for CROSS event

See EVENTS_CROSS

   Set1Enable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
 

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
Id                            DCBA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY  

Write '1' to Disable interrupt for READY event

See EVENTS_READY

   Clear1Disable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
BRWDOWN  

Write '1' to Disable interrupt for DOWN event

See EVENTS_DOWN

   Clear1Disable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
CRWUP  

Write '1' to Disable interrupt for UP event

See EVENTS_UP

   Clear1Disable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
DRWCROSS  

Write '1' to Disable interrupt for CROSS event

See EVENTS_CROSS

   Clear1Disable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
 

RESULT

Address offset: 0x400

Compare result

Bit number313029282726252423222120191817161514131211109876543210
Id                               A
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARRESULT  Result 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
Id                              AA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWENABLE  Enable or disable COMP
   Disabled0Disable
   Enabled2Enable
 

PSEL

Address offset: 0x504

Pin select

Bit number313029282726252423222120191817161514131211109876543210
Id                             AAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWPSEL  Analog 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
Id                             AAA
Reset 0x0000000400000000000000000000000000000100
IdRWFieldValue IdValueDescription
ARWREFSEL  Reference 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
   ARef7VREF = AREF (VDD >= VREF >= AREFMIN)
 

EXTREFSEL

Address offset: 0x50C

External reference select

Bit number313029282726252423222120191817161514131211109876543210
Id                             AAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWEXTREFSEL  External 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
Id                  BBBBBB  AAAAAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue 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
Id                       B      AA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWSP  Speed and power modes
   Low0Low-power mode
   Normal1Normal mode
   High2High-speed mode
BRWMAIN  Main operation modes
   SE0Single-ended mode
   Diff1Differential mode
 

HYST

Address offset: 0x538

Comparator hysteresis enable

Bit number313029282726252423222120191817161514131211109876543210
Id                               A
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWHYST  Comparator hysteresis
   NoHyst0Comparator hysteresis disabled
   Hyst50mV1Comparator hysteresis enabled
 

ISOURCE

Address offset: 0x53C

Current source select on analog input

Bit number313029282726252423222120191817161514131211109876543210
Id                              AA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWISOURCE  Comparator hysteresis
   Off0Current source disabled
   Ien2mA51Current source enabled (+/- 2.5 uA)
   Ien5mA2Current source enabled (+/- 5 uA)
   Ien10mA3Current source enabled (+/- 10 uA)
 

Electrical specification

COMP Electrical Specification

SymbolDescriptionMin.Typ.Max.Units
ICOMP,LPCore run current in low power mode2µA
ICOMP,NCore run current in normal mode5µA
ICOMP,HSCore run current in high-speed mode10µA
tPROPDLY,LPPropagation delay, low-power modea0.6µS
tPROPDLY,NPropagation delay, normal modea0.2µS
tPROPDLY,HSPropagation delay, high-speed modea0.1µS
VDIFFHYSTOptional hysteresis applied to differential input30mV
VVDD-VREFRequired difference between VDD and a selected VREF, VDD > VREF0.3V
IINT_REFCurrent used by the internal bandgap reference when selected as source for VREF13µA
tINT_REF,STARTStartup time for the internal bandgap reference5080µS
EINT_REFInternal bandgap reference error-33%
RLADDERReference ladder resistance, ILADDER = VREF / RLADDER550kΩ
VINPUTOFFSETInput offset-1010mV
DNLLADDERDifferential non-linearity of reference ladder<0.1LSB
tCOMP,STARTStartup time for the comparator core3µS

Total comparator run current must be calculated from the ICOMP, IINT_REF, and ILADDER values for a given reference voltage.

a Propagation delay is with 10 mV overdrive.