COMP — Comparator

The comparator peripheral (COMP) compares one input voltage (VIN+) against another input voltage (VIN-). VIN+ can be derived from an analog input pin (AIN0 to 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. COMP overview

START and STOP tasks

Once enabled through register ENABLE, COMP is started by triggering the START task and stopped by triggering the STOP task. COMP 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 when an internal reference is selected, or t COMP,START if an external reference is used. When the COMP peripheral is started, events will be generated every time VIN+ crosses VIN-.

Operation modes

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

Use register PSEL to select any of the AIN[0..7] pins as the VIN+ input. The COMP operation mode does not matter. The source of VIN- depends on which operation mode is used.

  • Differential mode – Derived directly from pins AIN[0..7].
  • Single-ended mode – Derived from VREF. VREF can be derived from AIN[0..7], or internal 1.2 V reference.

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 register HYST. 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 prevents 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 register RESULT by triggering the SAMPLE task.

Current source on analog input

A selectable current can be applied through register ISOURCE on the selected AIN[n] line. Enabling the block creates a feedback path around the comparator, forming a relaxation oscillator. The circuit will sink current from VIN+ when the comparator output is high, and source current into VIN+ when the comparator output is low. The frequency of the oscillator is dependent on the capacitance at the analog input pin, the reference voltages, and the value of the current source. In this mode, only a capacitive sensor needs to be attached between the analog input pin and ground. With a selected current of 10 μA, VUP-VDOWN equal to 1 V, and an external capacity of typically 10 pF, the resulting oscillation frequency is around 500 kHz.

The frequency of the oscillator can be calculated as follows:
f_OSC = I_SOURCE / (2C∙(VUP-VDOWN) )

Shared resources

The COMP shares analog resources with other analog peripherals.

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 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 Hysteresis enabled in differential mode.

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 Comparator in single-ended mode . 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 Hysteresis example where VIN+ starts below VUP and Hysteresis example where VIN+ starts above VUP.

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

InstanceDomainBase addressTrustZoneSplit accessDescription
MapAttDMA

COMP : S
COMP : NS

GLOBAL

0x50106000
0x40106000

USSNANo

Comparator COMP

Register overview

RegisterOffsetTZDescription
TASKS_START0x000

Start comparator

TASKS_STOP0x004

Stop comparator

TASKS_SAMPLE0x008

Sample comparator value. This task requires that COMP has been started by the START Task.

SUBSCRIBE_START0x080

Subscribe configuration for task START

SUBSCRIBE_STOP0x084

Subscribe configuration for task STOP

SUBSCRIBE_SAMPLE0x088

Subscribe configuration for task SAMPLE

EVENTS_READY0x100

COMP is ready and output is valid

EVENTS_DOWN0x104

Downward crossing

EVENTS_UP0x108

Upward crossing

EVENTS_CROSS0x10C

Downward or upward crossing

PUBLISH_READY0x180

Publish configuration for event READY

PUBLISH_DOWN0x184

Publish configuration for event DOWN

PUBLISH_UP0x188

Publish configuration for event UP

PUBLISH_CROSS0x18C

Publish configuration for event CROSS

SHORTS0x200

Shortcuts between local events and tasks

INTEN0x300

Enable or disable interrupt

INTENSET0x304

Enable interrupt

INTENCLR0x308

Disable interrupt

INTPEND0x30C

Pending interrupts

RESULT0x400

Compare result

ENABLE0x500

COMP enable

PSEL0x504

Pin select

REFSEL0x508

Reference source select for single-ended mode

EXTREFSEL0x50C

External reference select

TH0x530

Threshold configuration for hysteresis unit

MODE0x534

Mode configuration

HYST0x538

Comparator hysteresis enable

ISOURCE0x53C

Current source select on analog input

TASKS_START

Address offset: 0x000

Start comparator

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

W

TASKS_START

Start comparator

Trigger

1

Trigger task

TASKS_STOP

Address offset: 0x004

Stop comparator

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

W

TASKS_STOP

Stop comparator

Trigger

1

Trigger task

TASKS_SAMPLE

Address offset: 0x008

Sample comparator value. This task requires that COMP has been started by the START Task.

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

W

TASKS_SAMPLE

Sample comparator value. This task requires that COMP has been started by the START Task.

Trigger

1

Trigger task

SUBSCRIBE_START

Address offset: 0x080

Subscribe configuration for task START

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that task START will subscribe to

B

RW

EN

Disabled

0

Disable subscription

Enabled

1

Enable subscription

SUBSCRIBE_STOP

Address offset: 0x084

Subscribe configuration for task STOP

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that task STOP will subscribe to

B

RW

EN

Disabled

0

Disable subscription

Enabled

1

Enable subscription

SUBSCRIBE_SAMPLE

Address offset: 0x088

Subscribe configuration for task SAMPLE

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that task SAMPLE will subscribe to

B

RW

EN

Disabled

0

Disable subscription

Enabled

1

Enable subscription

EVENTS_READY

Address offset: 0x100

COMP is ready and output is valid

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

EVENTS_READY

COMP is ready and output is valid

NotGenerated

0

Event not generated

Generated

1

Event generated

EVENTS_DOWN

Address offset: 0x104

Downward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

EVENTS_DOWN

Downward crossing

NotGenerated

0

Event not generated

Generated

1

Event generated

EVENTS_UP

Address offset: 0x108

Upward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

EVENTS_UP

Upward crossing

NotGenerated

0

Event not generated

Generated

1

Event generated

EVENTS_CROSS

Address offset: 0x10C

Downward or upward crossing

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

EVENTS_CROSS

Downward or upward crossing

NotGenerated

0

Event not generated

Generated

1

Event generated

PUBLISH_READY

Address offset: 0x180

Publish configuration for event READY

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that event READY will publish to

B

RW

EN

Disabled

0

Disable publishing

Enabled

1

Enable publishing

PUBLISH_DOWN

Address offset: 0x184

Publish configuration for event DOWN

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that event DOWN will publish to

B

RW

EN

Disabled

0

Disable publishing

Enabled

1

Enable publishing

PUBLISH_UP

Address offset: 0x188

Publish configuration for event UP

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that event UP will publish to

B

RW

EN

Disabled

0

Disable publishing

Enabled

1

Enable publishing

PUBLISH_CROSS

Address offset: 0x18C

Publish configuration for event CROSS

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

CHIDX

[0..255]

DPPI channel that event CROSS will publish to

B

RW

EN

Disabled

0

Disable publishing

Enabled

1

Enable publishing

SHORTS

Address offset: 0x200

Shortcuts between local events and tasks

Bit number313029282726252423222120191817161514131211109876543210
IDEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

READY_SAMPLE

Shortcut between event READY and task SAMPLE

Disabled

0

Disable shortcut

Enabled

1

Enable shortcut

B

RW

READY_STOP

Shortcut between event READY and task STOP

Disabled

0

Disable shortcut

Enabled

1

Enable shortcut

C

RW

DOWN_STOP

Shortcut between event DOWN and task STOP

Disabled

0

Disable shortcut

Enabled

1

Enable shortcut

D

RW

UP_STOP

Shortcut between event UP and task STOP

Disabled

0

Disable shortcut

Enabled

1

Enable shortcut

E

RW

CROSS_STOP

Shortcut between event CROSS and task STOP

Disabled

0

Disable shortcut

Enabled

1

Enable shortcut

INTEN

Address offset: 0x300

Enable or disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

READY

Enable or disable interrupt for event READY

Disabled

0

Disable

Enabled

1

Enable

B

RW

DOWN

Enable or disable interrupt for event DOWN

Disabled

0

Disable

Enabled

1

Enable

C

RW

UP

Enable or disable interrupt for event UP

Disabled

0

Disable

Enabled

1

Enable

D

RW

CROSS

Enable or disable interrupt for event CROSS

Disabled

0

Disable

Enabled

1

Enable

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW
W1S

READY

Write '1' to enable interrupt for event READY

Set

1

Enable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

B

RW
W1S

DOWN

Write '1' to enable interrupt for event DOWN

Set

1

Enable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

C

RW
W1S

UP

Write '1' to enable interrupt for event UP

Set

1

Enable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

D

RW
W1S

CROSS

Write '1' to enable interrupt for event CROSS

Set

1

Enable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW
W1C

READY

Write '1' to disable interrupt for event READY

Clear

1

Disable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

B

RW
W1C

DOWN

Write '1' to disable interrupt for event DOWN

Clear

1

Disable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

C

RW
W1C

UP

Write '1' to disable interrupt for event UP

Clear

1

Disable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

D

RW
W1C

CROSS

Write '1' to disable interrupt for event CROSS

Clear

1

Disable

Disabled

0

Read: Disabled

Enabled

1

Read: Enabled

INTPEND

Address offset: 0x30C

Pending interrupts

Bit number313029282726252423222120191817161514131211109876543210
IDDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

R

READY

Read pending status of interrupt for event READY

NotPending

0

Read: Not pending

Pending

1

Read: Pending

B

R

DOWN

Read pending status of interrupt for event DOWN

NotPending

0

Read: Not pending

Pending

1

Read: Pending

C

R

UP

Read pending status of interrupt for event UP

NotPending

0

Read: Not pending

Pending

1

Read: Pending

D

R

CROSS

Read pending status of interrupt for event CROSS

NotPending

0

Read: Not pending

Pending

1

Read: Pending

RESULT

Address offset: 0x400

Compare result

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

R

RESULT

Result of last compare. Decision point SAMPLE task.

Below

0

Input voltage is below the threshold (VIN+ < VIN-)

Above

1

Input voltage is above the threshold (VIN+ > VIN-)

ENABLE

Address offset: 0x500

COMP enable

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

ENABLE

Enable or disable COMP

Disabled

0

Disable

Enabled

2

Enable

PSEL

Address offset: 0x504

Pin select

The pin is selected based on PSEL.PORT

Bit number313029282726252423222120191817161514131211109876543210
IDBBBBAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

PIN

Analog pin select

B

RW

PORT

GPIO Port selection

REFSEL

Address offset: 0x508

Reference source select for single-ended mode

Bit number313029282726252423222120191817161514131211109876543210
IDAAA
Reset 0x0000000400000000000000000000000000000100
IDR/WFieldValue IDValueDescription
A

RW

REFSEL

Reference select

Int1V2

0

VREF = internal 1.2 V reference

ARef

5

VREF = AREF

EXTREFSEL

Address offset: 0x50C

External reference select

The external reference pin is selected based on EXTREFSEL.PORT

Bit number313029282726252423222120191817161514131211109876543210
IDBBBBAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

PIN

External analog reference pin select

B

RW

PORT

GPIO Port selection

TH

Address offset: 0x530

Threshold configuration for hysteresis unit

Bit number313029282726252423222120191817161514131211109876543210
IDBBBBBBAAAAAA
Reset 0x0000202000000000000000000010000000100000
IDR/WFieldValue IDValueDescription
A

RW

THDOWN

[63:0]

VDOWN = (THDOWN+1)/64*VREF

B

RW

THUP

[63:0]

VUP = (THUP+1)/64*VREF

MODE

Address offset: 0x534

Mode configuration

Bit number313029282726252423222120191817161514131211109876543210
IDBAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

SP

Speed and power modes

Low

0

Low-power mode

Normal

1

Normal mode

High

2

High-speed mode

B

RW

MAIN

Main operation modes

SE

0

Single-ended mode

Diff

1

Differential mode

HYST

Address offset: 0x538

Comparator hysteresis enable

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

HYST

Comparator hysteresis

NoHyst

0

Comparator hysteresis disabled

Hyst40mV

1

Comparator hysteresis enabled

ISOURCE

Address offset: 0x53C

Current source select on analog input

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A

RW

ISOURCE

Current source select on analog input

Off

0

Current source disabled

Ien2uA5

1

Current source enabled (+/- 2.5 uA)

Ien5uA

2

Current source enabled (+/- 5 uA)

Ien10uA

3

Current source enabled (+/- 10 uA)