29. Comparator (COMP)

29.1 Introduction

The device embeds two ultra-low-power comparator channels (COMP1 and COMP2). They can be used for a variety of functions including:

29.2 COMP main features

29.3 COMP functional description

29.3.1 COMP block diagram

The block diagram of the comparators is shown in Figure 221: Comparator functional block diagram .

Figure 221. Comparator functional block diagram

Figure 221. Comparator functional block diagram. The diagram shows two comparator channels, Channel 1 and Channel 2, within a COMP block. Each channel contains an input multiplexer (INPSEL), a comparator (Cmp), a polarity control, and an output multiplexer. Channel 2 includes a window mode (WINMODE) and a blanking circuit (BLANKING). Both channels have a reference voltage generator (SCALEN, BRGEN) and a scaler (Scaler). The outputs are connected to GPIO alternate functions (COMP1_OUT, COMP2_OUT) and to interrupt logic (ITEN, DFF, CLR). The diagram also shows various internal signals like cmp1_inp, cmp1_inm, cmp2_inp, cmp2_inm, and external pins like COMP1_INP1, COMP1_INP2, COMP2_INP1, COMP2_INP2, COMP1_INM1, COMP1_INM2, COMP2_INM1, COMP2_INM2, comp_inm1, comp_inm2, V_REFINT, comp_blk1..comp_blk6, comp_pclk, and APB bus. The diagram is labeled MSv38377V3.
Figure 221. Comparator functional block diagram. The diagram shows two comparator channels, Channel 1 and Channel 2, within a COMP block. Each channel contains an input multiplexer (INPSEL), a comparator (Cmp), a polarity control, and an output multiplexer. Channel 2 includes a window mode (WINMODE) and a blanking circuit (BLANKING). Both channels have a reference voltage generator (SCALEN, BRGEN) and a scaler (Scaler). The outputs are connected to GPIO alternate functions (COMP1_OUT, COMP2_OUT) and to interrupt logic (ITEN, DFF, CLR). The diagram also shows various internal signals like cmp1_inp, cmp1_inm, cmp2_inp, cmp2_inm, and external pins like COMP1_INP1, COMP1_INP2, COMP2_INP1, COMP2_INP2, COMP1_INM1, COMP1_INM2, COMP2_INM1, COMP2_INM2, comp_inm1, comp_inm2, V_REFINT, comp_blk1..comp_blk6, comp_pclk, and APB bus. The diagram is labeled MSv38377V3.

29.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 239. COMP input/output internal signals

Signal nameSignal typeDescription
comp_inm1Analog inputInverting input source for both COMP channels: DAC ch.1
comp_inm2Analog inputInverting input source for both COMP channels: DAC ch.2
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 outputCOMP channel 1 wakeup out
comp1_outDigital outputCOMP channel 1 out
comp2_wkupDigital outputCOMP channel 2 wakeup out
comp2_outDigital outputCOMP channel 2 out
comp_itDigital outputCOMP interrupt out

Table 240. COMP input/output pins

Signal nameSignal typeDescription
COMP1_INM1Analog inputCOMP channel 1 inverting input source 1 (PB1)
COMP1_INM2Analog inputCOMP channel 1 inverting input source 2 (PC4)
COMP1_INP1Analog inputCOMP channel 1 non-inverting input source 1 (PB0)
COMP1_INP2Analog inputCOMP channel 1 non-inverting input source 2 (PB2)
COMP2_INM1Analog inputCOMP channel 2 inverting input source 1 (PE10)
COMP2_INM2Analog inputCOMP channel 2 inverting input source 2 (PE7)
COMP2_INP1Analog inputCOMP channel 2 non-inverting input source 1 (PE9)
COMP2_INP2Analog inputCOMP channel 2 non-inverting input source 2 (PE11)
COMP1_OUTDigital outputCOMP channel 1 output: see Section 29.3.8: Comparator output on GPIOs .
COMP2_OUTDigital outputCOMP channel 2 output: see Section 29.3.8: Comparator output on GPIOs .

29.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.

29.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.

29.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 221: Comparator functional block diagram .

29.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 222. Comparator hysteresis

Figure 222: Comparator hysteresis diagram. The top graph shows the INP input signal (a sine-like wave) and the INM reference signal (a dashed line). The hysteresis is indicated by the difference between the INM and INM - V_hyst lines. The bottom graph shows the COMP_OUT signal, which is a square wave that toggles between high and low states based on the comparison of INP and INM. The output is high when INP > INM and low when INP < INM - V_hyst. The output is low when INM - V_hyst < INP < INM. The diagram is labeled MS19984V1.
Figure 222: Comparator hysteresis diagram. The top graph shows the INP input signal (a sine-like wave) and the INM reference signal (a dashed line). The hysteresis is indicated by the difference between the INM and INM - V_hyst lines. The bottom graph shows the COMP_OUT signal, which is a square wave that toggles between high and low states based on the comparison of INP and INM. The output is high when INP > INM and low when INP < INM - V_hyst. The output is low when INM - V_hyst < INP < INM. The diagram is labeled MS19984V1.

29.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 223 (the COMP channel number is not represented).

Figure 223. Comparator output blanking

Figure 223: Comparator output blanking diagram. The diagram shows five waveforms over time. 1. PWM: A periodic square wave. 2. Inverting input (represents current limit): A sawtooth-like waveform that increases linearly and then drops sharply. 3. Non-inverting input (represents current): A sawtooth-like waveform that increases linearly and then drops sharply, with a sharp spike labeled 'current spike'. 4. cmp_out (before blanking gate): A square wave that toggles based on the comparison of the inputs. It shows a 'spurious pulse' corresponding to the current spike. 5. cmp_blk (blanking window): A square wave that is high during the initial part of each PWM period. 6. comp_out (COMP output): The final output, which is the AND of cmp_out and cmp_blk. It is low during the blanking window, effectively removing the spurious pulse. Below the waveforms, a logic diagram shows a 2-input AND gate labeled 'Blanking gate'. The inputs are cmp_out and cmp_blk (with a bubble indicating inversion). The output is comp_out (to I/Os, TIM_BK ...). The diagram is labeled MS30964V2.
Figure 223: Comparator output blanking diagram. The diagram shows five waveforms over time. 1. PWM: A periodic square wave. 2. Inverting input (represents current limit): A sawtooth-like waveform that increases linearly and then drops sharply. 3. Non-inverting input (represents current): A sawtooth-like waveform that increases linearly and then drops sharply, with a sharp spike labeled 'current spike'. 4. cmp_out (before blanking gate): A square wave that toggles based on the comparison of the inputs. It shows a 'spurious pulse' corresponding to the current spike. 5. cmp_blk (blanking window): A square wave that is high during the initial part of each PWM period. 6. comp_out (COMP output): The final output, which is the AND of cmp_out and cmp_blk. It is low during the blanking window, effectively removing the spurious pulse. Below the waveforms, a logic diagram shows a 2-input AND gate labeled 'Blanking gate'. The inputs are cmp_out and cmp_blk (with a bubble indicating inversion). The output is comp_out (to I/Os, TIM_BK ...). The diagram is labeled MS30964V2.

29.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 241. 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)
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 242. 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.

29.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 224 . For that end, the COMP channel output is connected to one of GPIOs programmable in alternate function as timer break input. See Table 241 and Table 242 . 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 224. Output redirection

Figure 224. Output redirection diagram showing the internal logic of the comparator output redirection. The diagram includes a comparator (COMP) with inputs + and -, an output AFO connected to a PAD, and an AF input AFI connected to a TIMx_BKINy input. The AFI input is connected to a multiplexer (MUX) with BKINP = 1. The MUX output is labeled 'To the timer break input (active high)'. The AFI input is also labeled 'AF input enabled (active low)'. The AFO output is labeled 'AF output configured as open drain'. The TIMx_BKINy input is labeled '(x=1,8 ; y=...2)'. The diagram is labeled MSv38378V1.
Figure 224. Output redirection diagram showing the internal logic of the comparator output redirection. The diagram includes a comparator (COMP) with inputs + and -, an output AFO connected to a PAD, and an AF input AFI connected to a TIMx_BKINy input. The AFI input is connected to a multiplexer (MUX) with BKINP = 1. The MUX output is labeled 'To the timer break input (active high)'. The AFI input is also labeled 'AF input enabled (active low)'. The AFO output is labeled 'AF output configured as open drain'. The TIMx_BKINy input is labeled '(x=1,8 ; y=...2)'. The diagram is labeled MSv38378V1.

29.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:

29.4 COMP low-power modes

Table 243. 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.

29.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.

29.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 244. 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

29.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 245. 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.

29.6 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 225. Scaler block diagram

Figure 225. Scaler block diagram. The diagram shows a dashed box containing an operational amplifier and a resistor bridge. The non-inverting input (+) of the op-amp is connected to V_REFINT. The inverting input (-) is connected to the output of the op-amp and to the top of a resistor bridge. The op-amp output is labeled V_REF_COMP. The resistor bridge consists of four resistors in series, connected between V_REF_COMP and ground. Taps are taken from the bridge to provide reference voltages: 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 is connected to the non-inverting input (+) of the op-amp. The bottom OR gate has inputs BRGEN (ch.2) and BRGEN (ch.1) and its output is connected to a switch that can disconnect the bottom resistor of the bridge from ground. The identifier MSV38379V1 is in the bottom right corner.
Figure 225. Scaler block diagram. The diagram shows a dashed box containing an operational amplifier and a resistor bridge. The non-inverting input (+) of the op-amp is connected to V_REFINT. The inverting input (-) is connected to the output of the op-amp and to the top of a resistor bridge. The op-amp output is labeled V_REF_COMP. The resistor bridge consists of four resistors in series, connected between V_REF_COMP and ground. Taps are taken from the bridge to provide reference voltages: 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 is connected to the non-inverting input (+) of the op-amp. The bottom OR gate has inputs BRGEN (ch.2) and BRGEN (ch.1) and its output is connected to a switch that can disconnect the bottom resistor of the bridge from ground. The identifier MSV38379V1 is in the bottom right corner.

29.7 COMP registers

29.7.1 Comparator 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.

29.7.2 Comparator 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.

29.7.3 Comparator option register (COMP_OR)

The COMP_OR is the Comparator option register.

Address offset: 0x08

System reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.AFOP
rw

Bits 31:11 Reserved, must be kept at reset value.

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

29.7.4 Comparator 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.Res.Res.INPSELRes.INMSEL[2:0]
rwrwrwrw
1514131211109876543210
Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.Res.POLARITYSCALENBRGENEN
rwrwrwrwrwrwrw

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

Bits 23: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)

Bit 19 Reserved, must be kept at reset value.

Bits 18:16 INMSEL[2: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.

000 = 1/4 V REF_COMP

001 = 1/2 V REF_COMP

010 = 3/4 V REF_COMP

011 = V REF_COMP

100 = comp_inm1 (DAC channel 1 output)

101 = comp_inm2 (DAC channel 2 output)

110 = COMP1_INM1 (PB1)

111 = COMP1_INM2 (PC4)

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.

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.

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.

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.

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.

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.

29.7.5 Comparator 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.INPSELRes.INMSEL[2:0]
rwrwrwrw
1514131211109876543210
Res.Res.PWRMODE[1:0]Res.Res.HYST[1:0]Res.ITENRes.WINMODEPOLARITYSCALENBRGENEN
rwrwrwrwrwrwrwrw

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

All other values: 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)

Bit 19 Reserved, must be kept at reset value.

Bits 18:16 INMSEL[2: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.

000 = 1/4 V REF _COMP

001 = 1/2 V REF _COMP

010 = 3/4 V REF _COMP

011 = V REF _COMP

100 = comp_inm1 (DAC channel 1 output)

101 = comp_inm2 (DAC channel 2 output)

110 = COMP2_INM1 (PE10)

111 = COMP2_INM2 (PE7)

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.

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.

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:

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.

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.

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.

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.

29.7.6 COMP register map

The following table summarizes the comparator registers.

Table 246. 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.C2VALC1VAL
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
Reset value0000000000000000
0x08COMP_OR
(OR_CFG=1)
OR31OR30OR29OR28OR27OR26OR25OR24OR23OR22OR21OR20OR19OR18OR17OR16OR15OR14OR13OR12OR11AFOP
Reset value00000000000000000000000000000000
0x0CCOMP_CFG
R1
LOCKRes.Res.Res.BLANKINGRes.Res.Res.INPSELRes.INMSELRes.Res.PWRMODERes.Res.HYSTRes.ITENRes.Res.POLARITYSCALENBRGENEN
Reset value000000000000000000
0x10COMP_CFG
R2
LOCKRes.Res.Res.BLANKINGRes.Res.Res.INPSELRes.INMSELRes.Res.PWRMODERes.Res.HYSTRes.ITENRes.WINMODEPOLARITYSCALENBRGENEN
Reset value000000000000000000

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