31. Comparator (COMP)
31.1 Introduction
The device embeds two ultra-low-power comparator channels (COMP1 and COMP2). They can be used for a variety of functions including:
- • wake up from low-power mode triggered by an analog signal
- • analog signal conditioning
- • cycle-by-cycle current control loop when combined with a PWM output from a timer
31.2 COMP main features
- • Selectable inverting analog inputs:
- – Two I/O pins (different for either channel)
- – DAC1 channel 1 and channel 2 outputs
- – DAC2 channel 1 output
- – Internal reference voltage and three sub multiple values (1/4, 1/2, 3/4) provided by scaler (buffered voltage divider)
- – \( V_{BAT}/4 \) and \( V_{DDA} \) supplies
- – Temperature monitoring
- • Selectable as non-inverting analog inputs:
- – Two I/O pins per channel (different for either channel)
- – DAC2 channel 1 output
- • Programmable hysteresis
- • Programmable speed / consumption
- • Mapping of outputs to I/Os
- • Redirection of outputs to timer inputs for triggering:
- – capture events
- – OCREF_CLR events (for cycle-by-cycle current control)
- – break events for fast PWM shutdowns
- • Blanking of comparator outputs
- • Window comparator
- • Interrupt generation capability with wake up from Sleep and Stop modes (through the EXTI controller)
- • Direct interrupt output to the CPU
31.3 COMP functional description
31.3.1 COMP block diagram
The block diagram of the comparators is shown in Figure 240: Comparator block diagram .
Figure 240. Comparator block diagram

The diagram illustrates the internal architecture of the COMP unit, divided into two main channels: Channel 1 and Channel 2. Each channel contains a comparator (Cmp), input multiplexers (INPSEL, INMSEL), a reference voltage generator (Scaler), a blanking unit, and interrupt logic (DFF, CLR, ITEN). Channel 2's output is connected to GPIO alternate functions (COMP2_OUT, COMP1_OUT / COMP2_OUT) and interrupt logic. Channel 1's output is connected to GPIO alternate functions (COMP1_OUT) and interrupt logic. The APB bus is connected to the control registers. The diagram also shows various input signals such as COMP1_INP1, COMP1_INP2, COMP1_INP3, COMP2_INP1, COMP2_INP2, and various INM signals, as well as control signals like WINMODE, POLARITY, SCALLEN, BRGEN, and BLANKING. The overall output includes comp2_wkup, comp2_out, COMP2_OUT, COMP1_OUT / COMP2_OUT, COMP1_OUT, comp1_wkup, comp1_out, and comp_it. The diagram is labeled MSV50672V3.
31.3.2 COMP pins and internal signals
The I/Os used as comparator inputs must be configured in analog mode in the GPIO registers.
The comparator outputs can be connected to the I/Os through their alternate functions. Refer to the product datasheet.
The outputs can also be internally redirected to a variety of timer inputs for the following purposes:
- • emergency shut-down of PWM signals, using BKIN and BKIN2 inputs
- • cycle-by-cycle current control, using ETR inputs of timers
- • input capture for timing measurements
The comparator output can be routed simultaneously internally and to the I/O pins.
Table 232. COMP input/output internal signals
| Signal name | Signal type | Description |
|---|---|---|
| comp_x_inp[4:9] | Analog input | Inverting inputs for COMPx (x = 1 or 2) |
| comp1_inp[1:3] | Analog input | Non-inverting inputs for COMP1 |
| comp2_inp[1:2] | Analog input | Non-inverting inputs for COMP2 |
| VREFINT (1) | Analog input | Internal reference voltage |
| comp_blk1 | Digital input | Blanking input source for both COMP channels: TIM1 OC5 |
| comp_blk2 | Digital input | Blanking input source for both COMP channels: TIM2 OC3 |
| comp_blk3 | Digital input | Blanking input source for both COMP channels: TIM3 OC3 |
| comp_blk4 | Digital input | Blanking input source for both COMP channels: TIM3 OC4 |
| comp_blk5 | Digital input | Blanking input source for both COMP channels: TIM8 OC5 |
| comp_blk6 | Digital input | Blanking input source for both COMP channels: TIM15 OC1 |
| comp_pclk | Digital input | APB clock for both COMP channels |
| comp1_wkup | Digital output | COMP1 channel 1 wakeup |
| comp1_out | Digital output | COMP1 channel 1 output |
| comp2_wkup | Digital output | COMP2 channel 2 wakeup |
| comp2_out | Digital output | COMP2 channel 2 output |
| comp_it | Digital output | COMP interrupt |
1. 1/4V REF_COMP , 1/2V REF_COMP , 3/4V REF_COMP and V REF_COMP voltage levels are generated from V REFINT .
Table 233. COMP input/output pins
| Signal name | Signal type | Description |
|---|---|---|
| COMPx_INP[1:2] | Analog input | Inverting inputs for COMPx (x = 1 or 2) |
| COMP1_INM[6:7] | Analog input | Non-inverting inputs for COMP1 |
| COMP2_INM[6:7,9] | Analog input | Non-inverting inputs for COMP2 |
| COMP1_OUT | Digital output | COMP channel 1 output: see Section 31.3.8: Comparator output on GPIOs . |
| COMP2_OUT | Digital output | COMP channel 2 output: see Section 31.3.8: Comparator output on GPIOs . |
Table 234. COMP interconnection
| Signal name | Source/destination |
|---|---|
| VREFINT | \( 1/4V_{REF\_comp} \) (COMP1 and COMP2) |
| \( 1/2V_{REF\_comp} \) (COMP1 and COMP2) | |
| \( 3/4V_{REF\_comp} \) (COMP1 and COMP2) | |
| \( V_{REF\_comp} \) (COMP1 and COMP2) | |
| comp_x_inm4 | DAC1 channel 1 (COMP1 and COMP2) |
| comp_x_inm5 | DAC1 channel 2 (COMP1 and COMP2) |
| comp1_inm6 | PB1 |
| comp2_inm6 | PE10 |
| comp1_inm7 | PC4 |
| comp2_inm7 | PE7 |
| comp1_inm8 | Temperature monitoring (COMP1) |
| comp2_inm8 | DAC2 channel 1 (COMP2) |
| comp1_inm9 | \( 1.4V_{BAT} \) (COMP1) |
| comp2_inm9 | \( V_{DDA} \) supply voltage (COMP2) |
| comp1_inp3 | DAC2 channel 1 (COMP1) |
31.3.3 COMP reset and clocks
The clock
comp_pclk
provided by the clock controller is synchronous with the APB clock.
Note:
Important:
The polarity selection logic and the output redirection to the port works independently from the APB clock. This allows the comparator to work even in Stop mode. The interrupt line, connected to the NVIC of CPU, requires the APB clock (
comp_pclk
) to work. In absence of the APB clock, the interrupt signal
comp_it
cannot be generated.
31.3.4 Comparator LOCK mechanism
The comparators can be used for safety purposes, such as over-current or thermal protection. For applications with specific functional safety requirements, the comparator
configuration can be protected against undesired alteration that could happen, for example, at program counter corruption.
For this purpose, the comparator configuration registers can be write-protected (read-only).
Upon configuring a comparator channel, its LOCK bit is set to 1. This causes the whole register set of the comparator channel, as well as the common COMP_OR register, to become read-only, the LOCK bit inclusive.
The write protection can only be removed through the MCU reset.
The COMP_OR register is locked by the LOCK bit of COMP_CFGR1 OR COMP_CFGR2.
31.3.5 Window comparator
The purpose of the window comparator is to monitor the analog voltage and check that it is comprised within the specified voltage range defined by lower and upper thresholds.
The window comparator requires both COMP channels. The monitored analog voltage is connected to their non-inverting (plus) inputs and the upper and lower threshold voltages are connected to the inverting (minus) input of either comparator, respectively. The non-inverting input of the COMP channel 2 can be connected internally with the non-inverting input of the COMP channel 1 by enabling WINMODE bit. This can save the input pins of COMP channel 2 for other purposes. See Figure 240: Comparator block diagram .
31.3.6 Hysteresis
The comparator includes a programmable hysteresis to avoid spurious output transitions in case of noisy signals. The hysteresis can be disabled if it is not needed (for instance when exiting from low-power mode) to be able to force the hysteresis value using external components.
Figure 241. Comparator hysteresis

The figure illustrates the hysteresis effect in a comparator. The top graph shows the non-inverting input (INP) as a sinusoidal-like waveform. The inverting input (INM) is a constant reference voltage. The hysteresis is represented by a shaded area between the INM line and a lower threshold line labeled INM - V hyst . The bottom graph shows the output (COMP_OUT) as a digital signal that transitions between high and low states. The output transitions occur at different input voltage levels due to the hysteresis, preventing spurious transitions when the input signal is noisy or near the threshold.
31.3.7 Comparator output blanking function
The purpose of the blanking function is to prevent the current regulation to trip upon short current spikes at the beginning of the PWM period (typically the recovery current in power switches anti parallel diodes). It uses a blanking window defined with a timer output compare signal. Refer to the register description for selectable blanking signals. The
blanking signal gates the internal comparator output such as to clean the
comp_out
from spurious pulses due to current spikes, as depicted in Figure 242 (the COMP channel number is not represented).
Figure 242. Comparator output blanking

The diagram illustrates the timing for comparator output blanking. The top waveform is a PWM signal. Below it, the 'Inverting input (represents current limit)' is a constant reference voltage. The 'Non-inverting input (represents current)' is a sawtooth-like waveform that ramps up and then drops abruptly. A 'current spike' is indicated on the non-inverting input. The 'cmp_out (before blanking gate)' shows a narrow 'spurious pulse' coinciding with the current spike. The 'cmp_blk (blanking window)' is a rectangular pulse that is high during the spike. The final 'comp_out (COMP output)' is the result of an AND gate (labeled 'Blanking gate') that takes 'cmp_out' and the inverted 'cmp_blk' as inputs. This effectively suppresses the spurious pulse when the blanking window is active. The output is labeled 'comp_out (to I/Os, TIM_BK ...)'.
31.3.8 Comparator output on GPIOs
The COMP1_OUT and COMP2_OUT outputs of the comparator channels are mapped to GPIOs through the AFOP field of the COMP_OR register, bits [10:0], and through the GPIO alternate function.
Table 235. COMP1_OUT assignment to GPIOs
| COMP1_OUT | Alternate Function |
|---|---|
| PC5 | AF13 |
| PE12 | AF13 |
| PA6 | AF10, AF12 (can be used as timer break in) |
| PA8 | AF12 (can be used as timer break in) |
| PB12 | AF13 (can be used as timer break in) |
| PE6 | AF11 (can be used as timer break in) |
| PE15 | AF13 (can be used as timer break in) |
| PG2 | AF11 (can be used as timer break in) |
| PG3 | AF11 (can be used as timer break in) |
| PG4 | AF11 (can be used as timer break in) |
| COMP1_OUT | Alternate Function |
|---|---|
| PI1 | AF11 (can be used as timer break in) |
| PI4 | AF11 (can be used as timer break in) |
| PK2 | AF10, AF11 (can be used as timer break in) |
| COMP2_OUT | Alternate Function |
|---|---|
| PE8 | AF13 |
| PE13 | AF13 |
| PA6 | AF10, AF12 (can be used as timer break in) |
| PA8 | AF12 (can be used as timer break in) |
| PB12 | AF13 (can be used as timer break in) |
| PE6 | AF11 (can be used as timer break in) |
| PE15 | AF13 (can be used as timer break in) |
| PG2 | AF11 (can be used as timer break in) |
| PG3 | AF11 (can be used as timer break in) |
| PG4 | AF11 (can be used as timer break in) |
| PI1 | AF11 (can be used as timer break in) |
| PI4 | AF11 (can be used as timer break in) |
| PK2 | AF10, AF11 (can be used as timer break in) |
The assignment to GPIOs for both comparator channel outputs must be done before locking registers of any channel, because the common COMP_OR register is locked when locking the registers of either comparator channel.
31.3.9 Comparator output redirection
The outputs of either COMP channel can be redirected to timer break inputs (TIMx_BKIN or TIMx_BKIN2), as shown in Figure 243 . For that end, the COMP channel output is connected to one of GPIOs programmable in alternate function as timer break input. See Table 235 and Table 236 . The selected GPIO(s) must be set in open drain mode. The COMP output passes through the GPIO to the timer break input. With a pull-up resistor, the selected GPIO can be used as timer break input logic OR-ed with the comparator output.
Figure 243. Output redirection

The diagram illustrates the output redirection logic for a comparator (COMP). At the top, a multiplexer is shown with its select input labeled BKINP = 1. The multiplexer has two inputs: one from TIMx_BKINy (where x=1,8 ; y=...2) and another from an inverter. The output of the multiplexer is connected to the AFI (AF input) pin. The AFI pin is labeled 'AF input enabled (active low)'. Below the multiplexer, a comparator (COMP) is shown with its non-inverting input (+) and inverting input (-). The output of the comparator is connected to the AFO (AF output) pin. The AFO pin is labeled 'AF output configured as open drain' and is connected to a PAD. The diagram also includes a ground symbol and the identifier MSV38378V1 in the bottom right corner.
31.3.10 COMP power and speed modes
The power consumption of the COMP channels versus propagation delay can be adjusted to have the optimum trade-off for a given application.
The bits PWRMODE[1:0] in COMP_CFGRx registers can be programmed as follows:
- 00: High speed / full power
- 01: Medium speed / medium power
- 10: Medium speed / medium power
- 11: Very-low speed / ultra-low-power
31.3.11 Scaler function
The scaler block is available to provide the different voltage reference levels to the comparator inputs. It is based on an amplifier driving a resistor bridge. The amplifier input is connected to the internal voltage reference.
The amplifier and the resistor bridge can be enabled separately. The amplifier is enabled by the SCALEN bits of the COMP_CFGRx registers. The resistor bridge is enabled by the BRGEN bits of the COMP_CFGRx registers.
When the resistor divided voltage is not used, the resistor bridge can be disconnected in order to reduce the consumption. When it is disconnected, the \( 1/4 V_{REF\_COMP} \) , \( 1/2 V_{REF\_COMP} \) and \( 3/4 V_{REF\_COMP} \) levels are equal to \( V_{REF\_COMP} \) .
Figure 244. Scaler block diagram

31.4 COMP low-power modes
Table 237. Comparator behavior in the low-power modes
| Mode | Description |
|---|---|
| Sleep | No effect on the comparators. Comparator interrupts cause the device to exit the Sleep mode. |
| Stop | No effect on the comparators. Comparator interrupts cause the device to exit the Stop mode. |
Note: The comparators cannot be used to exit the device from Sleep or Stop mode when the internal reference voltage is switched off.
31.5 COMP interrupts
There are two ways to use the comparator as interrupt source.
The comparator outputs are internally connected to the Extended interrupt and event controller. Each comparator has its own EXTI line and can generate either interrupts or events to make the device exit low-power modes.
The comparators also provide an interrupt line to the NVIC of CPU. This functionality is used when the CPU is active to handle low latency interrupt. It requires APB clock running.
31.5.1 Interrupt through EXTI block
Refer to Interrupt and events section for more details.
Sequence to enable the COMPx interrupt through EXTI block:
- 1. Configure the EXTI line, receiving the comp_wkup signal, in interrupt mode, select the rising, falling or either-edge sensitivity and enable the EXTI line.
- 2. Configure and enable the NVIC IRQ channel mapped to the corresponding EXTI lines.
- 3. Enable the COMPx.
Table 238. Interrupt control bits
| Interrupt event | Event flag | Enable control bit | Exit from Sleep mode | Exit from Stop modes | Exit from Standby mode |
|---|---|---|---|---|---|
| comp1_wkup | through EXTI | through EXTI | yes | yes | N/A |
| comp2_wkup | through EXTI | through EXTI | yes | yes | N/A |
31.5.2 Interrupt through NVIC of the CPU
Sequence to enable the COMPx interrupt through NVIC of the CPU:
- 1. Configure and enable the NVIC IRQ channel mapped to the comp_it line.
- 2. Configure and enable the ITEN in COMP_CFGRx.
- 3. Enable the COMPx.
Table 239. Interrupt control bits
| Interrupt event | Interrupt flag | Enable control bit | Interrupt clear bit | Exit from Sleep mode | Exit from Stop modes |
|---|---|---|---|---|---|
| comp_it | C1IF in | ITEN in COMP_CFGR1 | CC1IF | yes (With APB clock) | no |
| comp_it | C2IF in | ITEN in COMP_CFGR2 | CC2IF | yes (With APB clock) | no |
Note: It is mandatory to enable APB clock to use this interrupt. If clock is not enabled, interrupt is not generated.
31.6 COMP registers
31.6.1 COMP status register (COMP_SR)
The COMP_SR is the comparator status register.
Address offset: 0x00
System reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | C2IF | C1IF |
| r | r | ||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | C2VAL | C1VAL |
| r | r | ||||||||||||||
Bits 31:18 Reserved, must be kept at reset value.
Bit 17
C2IF
: COMP channel 2 Interrupt Flag
This bit is set by hardware when the COMP channel 2 output is set
This bit is cleared by software writing 1 the CC2IF bit in the COMP_ICFR register.
Bit 16
C1IF
: COMP channel 1 Interrupt Flag
This bit is set by hardware when the COMP channel 1 output is set
This bit is cleared by software writing 1 the CC1IF bit in the COMP_ICFR register.
Bits 15:2 Reserved, must be kept at reset value.
Bit 1
C2VAL
: COMP channel 2 output status bit
This bit is read-only. It reflects the current COMP channel 2 output taking into account POLARITY and BLANKING bits effect.
Bit 0
C1VAL
: COMP channel 1 output status bit
This bit is read-only. It reflects the current COMP channel 1 output taking into account POLARITY and BLANKING bits effect.
31.6.2 COMP interrupt clear flag register (COMP_ICFR)
The COMP_ICFR is the Comparator interrupt clear flag register.
Address offset: 0x04
System reset value: 0x0000 0004
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CC2IF | CC1IF |
| rc_w1 | rc_w1 | ||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
Bits 31:18 Reserved, must be kept at reset value.
Bit 17 CC2IF : Clear COMP channel 2 Interrupt Flag
Writing 1 clears the C2IF flag in the COMP_SR register.
Bit 16 CC1IF : Clear COMP channel 1 Interrupt Flag
Writing 1 clears the C1IF flag in the COMP_SR register.
Bits 15:0 Reserved, must be kept at reset value.
31.6.3 COMP option register [alternate] (COMP_OR)
The COMP_OR is the Comparator option register.
Address offset: 0x08
System reset value: 0x0000 0000
When OR_CFG=0:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OR15 | OR14 | OR13 | OR12 | OR11 | AFOP[10:0] | ||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:11 OR : Option register (when OR_CFG=0)
Bits 10:0 AFOP[10:0] : Selection of source for alternate function of output ports
Bits of this field are set and cleared by software (only if LOCK not set).
Output port (GPIO) correspondence:
bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
PK2 PI4 PI1 PG4 PG3 PG2 PE15 PE6 PB12 PA8 PA6
For each bit:
0: COMP1_OUT is selected for the alternate function of the corresponding GPIO
1: COMP2_OUT is selected for the alternate function of the corresponding GPIO
When OR_CFG=1:
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OR31 | OR30 | OR29 | OR28 | OR27 | OR26 | OR25 | OR24 | OR23 | OR22 | OR21 | OR20 | OR19 | OR18 | OR17 | OR16 |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OR15 | OR14 | OR13 | OR12 | OR11 | AFOP[10:0] | ||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:11 OR : Option register (when OR_CFG=1)
Bits 10:0 AFOP[10:0] : Selection of source for alternate function of output ports
Bits of this field are set and cleared by software (only if LOCK not set).
Output port (GPIO) correspondence:
| bit 10 | bit 9 | bit 8 | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
| PK2 | PI4 | PI1 | PG4 | PG3 | PG2 | PE15 | PE6 | PB12 | PA8 | PA6 |
For each bit:
0: COMP1_OUT is selected for the alternate function of the corresponding GPIO
1: COMP2_OUT is selected for the alternate function of the corresponding GPIO
31.6.4 COMP configuration register 1 (COMP_CFGR1)
The COMP_CFGR1 is the COMP channel 1 configuration register.
Address offset: 0x0C
System reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| LOCK | Res. | Res. | Res. | BLANKING[3:0] | Res. | INP2SEL | Res. | INPSEL | INMSEL[3:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | PWRMODE[1:0] | Res. | Res. | HYST[1:0] | Res. | ITEN | Res. | Res. | POLARITY | SCAL EN | BRG EN | EN | ||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||||
Bit 31 LOCK : Lock bit
This bit is set by software and cleared by a hardware system reset. It locks the whole content of the COMP channel 1 configuration register COMP_CFGR1[31:0], and COMP_OR register
0: COMP_CFGR1[31:0] register is read/write
1: COMP_CFGR1[31:0] and COMP_OR registers are read-only
Bits 30:28 Reserved, must be kept at reset value.
Bits 27:24 BLANKING[3:0] : COMP channel 1 blanking source selection bits
Bits of this field are set and cleared by software (only if LOCK not set).
The field selects the input source for COMP channel 1 output blanking:
0000: No blanking
0001: comp_blk1
0010: comp_blk2
0011: comp_blk3
0100: comp_blk4
0101: comp_blk5
0110: comp_blk6
All other values: reserved
Bit 23 Reserved, must be kept at reset value.
Bit 22 INP2SEL : COMP channel 1 non-inverting input 2 selection bit
This bit is set and cleared by software (only if LOCK not set).
0: DAC2 channel 1 input disabled
1: DAC2 channel 1 input enabled
Note: To avoid conflicts between INPLUS and INPLUS2, COMP1_INP1 and COMP1_INP2 automatically become floating when INP2SEL is set.
Bit 21 Reserved, must be kept at reset value.
Bit 20 INPSEL : COMP channel 1 non-inverting input selection bit
This bit is set and cleared by software (only if LOCK not set).
0: COMP1_INP1 (PB0)
1: COMP1_INP2 (PB2)
Bits 19:16 INMSEL[3:0] : COMP channel 1 inverting input selection field
These bits are set and cleared by software (only if LOCK not set). They select which input is connected to the input minus of COMP channel 1.
0000 = 1/4 V REF_COMP
0001 = 1/2 V REF_COMP
0010 = 3/4 V REF_COMP
0011 = V REF_COMP
0100 = COMP1_INM4 (DAC1 channel 1)
0101 = COMP1_INM5 (DAC1 channel 2)
0110 = COMP1_INM6 (PB1)
0111 = COMP1_INM7 (PC4)
1000 = COMP1_INM8 (temperature monitoring)
1001 = COMP1_INM9 (V BAT /4)
Other configurations: Reserved
Bits 15:14 Reserved, must be kept at reset value.
Bits 13:12 PWRMODE[1:0] : Power Mode of the COMP channel 1
These bits are set and cleared by software (only if LOCK not set). They control the power/speed of the COMP channel 1.
00: High speed / full power
01: Medium speed / medium power
10: Medium speed / medium power
11: Ultra low power / ultra-low-power
Bits 11:10 Reserved, must be kept at reset value.
Bits 9:8 HYST[1:0] : COMP channel 1 hysteresis selection bits
These bits are set and cleared by software (only if LOCK not set). They select the Hysteresis voltage of the COMP channel 1.
00: No hysteresis
01: Low hysteresis
10: Medium hysteresis
11: High hysteresis
Bit 7 Reserved, must be kept at reset value.
Bit 6 ITEN : COMP channel 1 interrupt enable
This bit is set and cleared by software (only if LOCK not set). This bit enable the interrupt generation of the COMP channel 1.
0: Interrupt generation disabled for COMP channel 1
1: Interrupt generation enabled for COMP channel 1
Bits 5:4 Reserved, must be kept at reset value.
Bit 3 POLARITY : COMP channel 1 polarity selection bit
This bit is set and cleared by software (only if LOCK not set). It inverts COMP channel 1 polarity.
0: COMP channel 1 output is not inverted
1: COMP channel 1output is inverted
Bit 2 SCALEN : Voltage scaler enable bit
This bit is set and cleared by software (only if LOCK not set). This bit enables the \( V_{REFINT} \) scaler for the COMP channels.
0: \( V_{REFINT} \) scaler disabled (if SCALEN bit of COMP_CFGR2 register is also low)
1: \( V_{REFINT} \) scaler enabled
Bit 1 BRGEN : Scaler bridge enable
This bit is set and cleared by software (only if LOCK not set). This bit enables the bridge of the scaler.
0: Scaler resistor bridge disabled (if BRGEN bit of COMP_CFGR2 register is also low)
1: Scaler resistor bridge enabled
If SCALEN is set and BRGEN is reset, all four scaler outputs provide the same level \( V_{REF\_COMP} \) (similar to \( V_{REFINT} \) ).
If SCALEN and BRGEN are set, the four scaler outputs provide \( V_{REF\_COMP} \) , \( 3/4 V_{REF\_COMP} \) , \( 1/2 V_{REF\_COMP} \) and \( 1/4 V_{REF\_COMP} \) levels, respectively.
Bit 0 EN : COMP channel 1 enable bit
This bit is set and cleared by software (only if LOCK not set). It enables the COMP channel 1.
0: Disable
1: Enable
31.6.5 COMP configuration register 2 (COMP_CFGR2)
The COMP_CFGR2 is the COMP channel 2 configuration register.
Address offset: 0x10
System reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| LOCK | Res. | Res. | Res. | BLANKING[3:0] | Res. | Res. | Res. | INPSEL | INMSEL[3:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | PWRMODE[1:0] | Res. | Res. | HYST[1:0] | Res. | ITEN | Res. | WIN MODE | POLARITY | SCALEN | BRGEN | EN | ||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||||
This bit is set by software and cleared by a hardware system reset. It locks the whole content of the COMP channel 2 configuration register COMP_CFGR2[31:0], and COMP_OR register
0: COMP_CFGR2[31:0] register is read/write
1: COMP_CFGR2[31:0] and COMP_OR registers are read-only
Bits 30:28 Reserved, must be kept at reset value.
Bits 27:24 BLANKING[3:0] : COMP channel 2 blanking source selection bitsThese bits are set and cleared by software (only if LOCK not set). These bits select which timer output controls the COMP channel 2 output blanking.
0000: No blanking
0001: TIM1_OC5 selected as blanking source
0010: TIM2_OC3 selected as blanking source
0011: TIM3_OC3 selected as blanking source
0100: TIM3_OC4 selected as blanking source
0101: TIM8_OC5 selected as blanking source
0110: TIM15_OC1 selected as blanking source
Other configurations: Reserved
Bits 23:21 Reserved, must be kept at reset value.
Bit 20 INPSEL : COMP channel 2 non-inverting input selection bitThis bit is set and cleared by software (only if LOCK not set).
0: COMP2_INP1 (PE9)
1: COMP2_INP2 (PE11)
Bits 19:16 INMSEL[3:0] : COMP channel 2 inverting input selection fieldThese bits are set and cleared by software (only if LOCK not set). They select which input is connected to the input minus of COMP channel 2.
0000 = 1/4 V REF_COMP
0001 = 1/2 V REF_COMP
0010 = 3/4 V REF_COMP
0011 = V REF_COMP
0100 = COMP2_INM4 (DAC1 channel 1)
0101 = COMP2_INM5 (DAC1 channel 2)
0110 = COMP2_INM6 (PE10)
0111 = COMP2_INM7 (PE7)
1000 = COMP2_INM8 (DAC2 channel 1)
1001 = COMP2_INM9 (V DDA )
Other configurations: Reserved
Bits 15:14 Reserved, must be kept at reset value.
Bits 13:12 PWRMODE[1:0] : Power Mode of the COMP channel 2These bits are set and cleared by software (only if LOCK not set). They control the power/speed of the COMP channel 2.
00: High speed / full power
01: Medium speed / medium power
10: Medium speed / medium power
11: Ultra low power / ultra-low-power
Bits 11:10 Reserved, must be kept at reset value.
Bits 9:8 HYST[1:0]: COMP channel 2 hysteresis selection bitsThese bits are set and cleared by software (only if LOCK not set). They select the Hysteresis voltage of the COMP channel 2.
00: No hysteresis
01: Low hysteresis
10: Medium hysteresis
11: High hysteresis
Bit 7 Reserved, must be kept at reset value.
Bit 6 ITEN: COMP channel 2 interrupt enableThis bit is set and cleared by software (only if LOCK not set). This bit enable the interrupt generation of the COMP channel 2.
0: Interrupt generation disabled for COMP channel 2
1: Interrupt generation enabled for COMP channel 2
Bit 5 Reserved, must be kept at reset value.
Bit 4 WINMODE: Window comparator mode selection bitThis bit is set and cleared by software (only if LOCK not set). This bit selects the window mode of the comparators. If set, the non-inverting input of COMP channel 2 is connected to the non-inverting input of the COMP channel 1.
Depending on the bit value, the non-inverting input of COMP channel 2 is connected to:
0: COMP2_INP input selector
1: Non-inverting input comp1_inp of COMP channel 1
Bit 3 POLARITY: COMP channel 2 polarity selection bitThis bit is set and cleared by software (only if LOCK not set). It inverts COMP channel 2 polarity.
0: COMP channel 2 output is not inverted
1: COMP channel 2 output is inverted
Bit 2 SCALEN: Voltage scaler enable bitThis bit is set and cleared by software (only if LOCK not set). This bit enables the \( V_{REFINT} \) scaler for the COMP channels.
0: \( V_{REFINT} \) scaler disabled (if SCALEN bit of COMP_CFGR1 register is also low)
1: \( V_{REFINT} \) scaler enabled
Bit 1 BRGEN: Scaler bridge enableThis bit is set and cleared by software (only if LOCK not set). This bit enables the bridge of the scaler.
0: Scaler resistor bridge disabled (if BRGEN bit of COMP_CFGR1 register is also low)
1: Scaler resistor bridge enabled
If SCALEN is set and BRGEN is reset, all four scaler outputs provide the same level \( V_{REF\_COMP} \) (similar to \( V_{REFINT} \) ).
If SCALEN and BRGEN are set, the four scaler outputs provide \( V_{REF\_COMP} \) , \( 3/4 V_{REF\_COMP} \) , \( 1/2 V_{REF\_COMP} \) and \( 1/4 V_{REF\_COMP} \) levels, respectively.
Bit 0 EN: COMP channel 2 enable bitThis bit is set and cleared by software (only if LOCK not set). It enables the COMP channel 2.
0: Disable
1: Enable
31.6.6 COMP register map
The following table summarizes the comparator registers.
Table 240. COMP register map and reset values
| Offset | Register name | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x00 | COMP_SR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | C2IF | C1IF | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | C2VAL | Res. |
| Reset value | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||||||
| 0x04 | COMP_ICFR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CC2IF | CC1IF | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| Reset value | 0 | 0 | ||||||||||||||||||||||||||||||||
| 0x08 | COMP_OR (OR_CFG=0) | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OR15 | OR14 | OR13 | OR12 | OR11 | AFOP[10:0] | |||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||
| 0x08 | COMP_OR (OR_CFG=1) | OR31 | OR30 | OR29 | OR28 | OR27 | OR26 | OR25 | OR24 | OR23 | OR22 | OR21 | OR20 | OR19 | OR18 | OR17 | OR16 | OR15 | OR14 | OR13 | OR12 | OR11 | AFOP[10:0] | |||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||
| 0x0C | COMP_CFG R1 | LOCK | Res. | Res. | Res. | BLANKING[3:0] | Res. | INP2SEL | Res. | INPSEL | INMSEL[3:0] | Res. | Res. | PWRMODE[1:0] | Res. | Res. | HYST[1:0] | Res. | ITEN | Res. | Res. | POLARITY | SCALEN | BRGEN | EN | |||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||
| 0x10 | COMP_CFG R2 | LOCK | Res. | Res. | Res. | BLANKING[3:0] | Res. | Res. | Res. | INPSEL | INMSEL[3:0] | Res. | Res. | PWRMODE[1:0] | Res. | Res. | HYST[1:0] | Res. | ITEN | Res. | WINMODE | POLARITY | SCALEN | BRGEN | EN | |||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
Refer to Section 2.3 on page 131 for the register boundary addresses.