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:

31.2 COMP main features

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

Detailed block diagram of the COMP (Comparator) unit showing Channel 1 and Channel 2 internal structures, including input multiplexers, comparators, output multiplexers, and interrupt logic.

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.

Detailed block diagram of the COMP (Comparator) unit showing Channel 1 and Channel 2 internal structures, including input multiplexers, comparators, output multiplexers, and interrupt logic.

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:

The comparator output can be routed simultaneously internally and to the I/O pins.

Table 232. COMP input/output internal signals

Signal nameSignal typeDescription
comp_x_inp[4:9]Analog inputInverting inputs for COMPx (x = 1 or 2)
comp1_inp[1:3]Analog inputNon-inverting inputs for COMP1
comp2_inp[1:2]Analog inputNon-inverting inputs for COMP2
VREFINT (1)Analog inputInternal reference voltage
comp_blk1Digital inputBlanking input source for both COMP channels: TIM1 OC5
comp_blk2Digital inputBlanking input source for both COMP channels: TIM2 OC3
comp_blk3Digital inputBlanking input source for both COMP channels: TIM3 OC3
comp_blk4Digital inputBlanking input source for both COMP channels: TIM3 OC4
comp_blk5Digital inputBlanking input source for both COMP channels: TIM8 OC5
comp_blk6Digital inputBlanking input source for both COMP channels: TIM15 OC1
comp_pclkDigital inputAPB clock for both COMP channels
comp1_wkupDigital outputCOMP1 channel 1 wakeup
comp1_outDigital outputCOMP1 channel 1 output
comp2_wkupDigital outputCOMP2 channel 2 wakeup
comp2_outDigital outputCOMP2 channel 2 output
comp_itDigital outputCOMP 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 nameSignal typeDescription
COMPx_INP[1:2]Analog inputInverting inputs for COMPx (x = 1 or 2)
COMP1_INM[6:7]Analog inputNon-inverting inputs for COMP1
COMP2_INM[6:7,9]Analog inputNon-inverting inputs for COMP2
COMP1_OUTDigital outputCOMP channel 1 output: see Section 31.3.8: Comparator output on GPIOs .
COMP2_OUTDigital outputCOMP channel 2 output: see Section 31.3.8: Comparator output on GPIOs .

Table 234. COMP interconnection

Signal nameSource/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_inm4DAC1 channel 1 (COMP1 and COMP2)
comp_x_inm5DAC1 channel 2 (COMP1 and COMP2)
comp1_inm6PB1
comp2_inm6PE10
comp1_inm7PC4
comp2_inm7PE7
comp1_inm8Temperature monitoring (COMP1)
comp2_inm8DAC2 channel 1 (COMP2)
comp1_inm9\( 1.4V_{BAT} \) (COMP1)
comp2_inm9\( V_{DDA} \) supply voltage (COMP2)
comp1_inp3DAC2 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

Figure 241. Comparator hysteresis. A graph showing the relationship between the non-inverting input (INP), the inverting input (INM), and the output (COMP_OUT). The INP signal is a sine-like wave. The INM signal is a constant reference voltage. The hysteresis is shown as a shaded area between the INM line and a lower threshold line (INM - V_hyst). The COMP_OUT signal is a digital output that transitions between high and low states based on the comparison of INP and INM, with 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.

Figure 241. Comparator hysteresis. A graph showing the relationship between the non-inverting input (INP), the inverting input (INM), and the output (COMP_OUT). The INP signal is a sine-like wave. The INM signal is a constant reference voltage. The hysteresis is shown as a shaded area between the INM line and a lower threshold line (INM - V_hyst). The COMP_OUT signal is a digital output that transitions between high and low states based on the comparison of INP and INM, with hysteresis.

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

Timing diagram showing PWM, Inverting input, Non-inverting input, cmp_out (before blanking gate), cmp_blk (blanking window), and comp_out (COMP output) waveforms. It includes a logic gate diagram at the bottom labeled 'Blanking gate' with inputs 'cmp_out' and 'cmp_blk' and output 'comp_out (to I/Os, TIM_BK ...)'.

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 ...)'.

Timing diagram showing PWM, Inverting input, Non-inverting input, cmp_out (before blanking gate), cmp_blk (blanking window), and comp_out (COMP output) waveforms. It includes a logic gate diagram at the bottom labeled 'Blanking gate' with inputs 'cmp_out' and 'cmp_blk' and output '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_OUTAlternate Function
PC5AF13
PE12AF13
PA6AF10, AF12 (can be used as timer break in)
PA8AF12 (can be used as timer break in)
PB12AF13 (can be used as timer break in)
PE6AF11 (can be used as timer break in)
PE15AF13 (can be used as timer break in)
PG2AF11 (can be used as timer break in)
PG3AF11 (can be used as timer break in)
PG4AF11 (can be used as timer break in)
Table 235. COMP1_OUT assignment to GPIOs (continued)
COMP1_OUTAlternate Function
PI1AF11 (can be used as timer break in)
PI4AF11 (can be used as timer break in)
PK2AF10, AF11 (can be used as timer break in)
Table 236. COMP2_OUT assignment to GPIOs
COMP2_OUTAlternate Function
PE8AF13
PE13AF13
PA6AF10, AF12 (can be used as timer break in)
PA8AF12 (can be used as timer break in)
PB12AF13 (can be used as timer break in)
PE6AF11 (can be used as timer break in)
PE15AF13 (can be used as timer break in)
PG2AF11 (can be used as timer break in)
PG3AF11 (can be used as timer break in)
PG4AF11 (can be used as timer break in)
PI1AF11 (can be used as timer break in)
PI4AF11 (can be used as timer break in)
PK2AF10, 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

Figure 243. Output redirection diagram

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.

Figure 243. Output redirection diagram

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:

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

Figure 244. Scaler block diagram. The diagram shows a dashed box containing an operational amplifier (op-amp) and a resistor bridge. The op-amp's non-inverting input (+) is connected to V_REFINT. Its inverting input (-) is connected to the output of the resistor bridge in a feedback loop. The op-amp's output is connected to V_REF_COMP. The resistor bridge consists of four resistors in series between V_REF_COMP and ground. Taps are taken from the junctions between the resistors to provide 3/4 V_REF_COMP, 1/2 V_REF_COMP, and 1/4 V_REF_COMP. Two OR gates are shown. The top OR gate has inputs SCALEN (ch.2) and SCALEN (ch.1) and its output enables the op-amp. The bottom OR gate has inputs BRGEN (ch.2) and BRGEN (ch.1) and its output controls a switch that can disconnect the resistor bridge from ground. The identifier MSv38379V1 is in the bottom right corner.
Figure 244. Scaler block diagram. The diagram shows a dashed box containing an operational amplifier (op-amp) and a resistor bridge. The op-amp's non-inverting input (+) is connected to V_REFINT. Its inverting input (-) is connected to the output of the resistor bridge in a feedback loop. The op-amp's output is connected to V_REF_COMP. The resistor bridge consists of four resistors in series between V_REF_COMP and ground. Taps are taken from the junctions between the resistors to provide 3/4 V_REF_COMP, 1/2 V_REF_COMP, and 1/4 V_REF_COMP. Two OR gates are shown. The top OR gate has inputs SCALEN (ch.2) and SCALEN (ch.1) and its output enables the op-amp. The bottom OR gate has inputs BRGEN (ch.2) and BRGEN (ch.1) and its output controls a switch that can disconnect the resistor bridge from ground. The identifier MSv38379V1 is in the bottom right corner.

31.4 COMP low-power modes

Table 237. Comparator behavior in the low-power modes

ModeDescription
SleepNo effect on the comparators.
Comparator interrupts cause the device to exit the Sleep mode.
StopNo 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. 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. 2. Configure and enable the NVIC IRQ channel mapped to the corresponding EXTI lines.
  3. 3. Enable the COMPx.

Table 238. Interrupt control bits

Interrupt eventEvent flagEnable control bitExit from Sleep modeExit from Stop modesExit from Standby mode
comp1_wkupthrough EXTIthrough EXTIyesyesN/A
comp2_wkupthrough EXTIthrough EXTIyesyesN/A

31.5.2 Interrupt through NVIC of the CPU

Sequence to enable the COMPx interrupt through NVIC of the CPU:

  1. 1. Configure and enable the NVIC IRQ channel mapped to the comp_it line.
  2. 2. Configure and enable the ITEN in COMP_CFGRx.
  3. 3. Enable the COMPx.

Table 239. Interrupt control bits

Interrupt eventInterrupt flagEnable control bitInterrupt clear bitExit from Sleep modeExit from Stop modes
comp_itC1IF inITEN in COMP_CFGR1CC1IFyes
(With APB clock)
no
comp_itC2IF inITEN in COMP_CFGR2CC2IFyes
(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

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.C2IFC1IF
rr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.C2VALC1VAL
rr

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

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC2IFCC1IF
rc_w1rc_w1
1514131211109876543210
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:

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OR15OR14OR13OR12OR11AFOP[10:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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:

31302928272625242322212019181716
OR31OR30OR29OR28OR27OR26OR25OR24OR23OR22OR21OR20OR19OR18OR17OR16
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
OR15OR14OR13OR12OR11AFOP[10:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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 10bit 9bit 8bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
PK2PI4PI1PG4PG3PG2PE15PE6PB12PA8PA6

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

31302928272625242322212019181716
LOCKRes.Res.Res.BLANKING[3:0]Res.INP2SELRes.INPSELINMSEL[3:0]
rwrwrwrwrwrwrwrwrwrwrw

1514131211109876543210
Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.Res.POLARITYSCAL ENBRG ENEN
rwrwrwrwrwrwrwrwrw

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

31302928272625242322212019181716
LOCKRes.Res.Res.BLANKING[3:0]Res.Res.Res.INPSELINMSEL[3:0]
rwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.WIN MODEPOLARITYSCALENBRGENEN
rwrwrwrwrwrwrwrwrwrw
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 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 bits

These 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 bit

This 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 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 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 2

These 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 bits

These 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 enable

This 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 bit

This 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 bit

This 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 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_CFGR1 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_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 bit

This 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

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00COMP_SRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.C2IFC1IFRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.C2VALRes.
Reset value0000
0x04COMP_ICFRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC2IFCC1IFRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value00
0x08COMP_OR
(OR_CFG=0)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OR15OR14OR13OR12OR11AFOP[10:0]
Reset value000000000000000
0x08COMP_OR
(OR_CFG=1)
OR31OR30OR29OR28OR27OR26OR25OR24OR23OR22OR21OR20OR19OR18OR17OR16OR15OR14OR13OR12OR11AFOP[10:0]
Reset value0000000000000000000000000000000
0x0CCOMP_CFG
R1
LOCKRes.Res.Res.BLANKING[3:0]Res.INP2SELRes.INPSELINMSEL[3:0]Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.Res.POLARITYSCALENBRGENEN
Reset value00000000000000000000
0x10COMP_CFG
R2
LOCKRes.Res.Res.BLANKING[3:0]Res.Res.Res.INPSELINMSEL[3:0]Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.WINMODEPOLARITYSCALENBRGENEN
Reset value0000000000000000000

Refer to Section 2.3 on page 131 for the register boundary addresses.