28. Comparator (COMP)

28.1 Introduction

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

28.2 COMP main features

28.3 COMP functional description

28.3.1 COMP block diagram

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

Figure 216. Comparator functional block diagram

Figure 216. Comparator functional block diagram. The diagram shows two comparator channels, Channel 1 and Channel 2, within a COMP block. Each channel has an INPSEL multiplexer for positive inputs (COMPx_INP1, COMPx_INP2), an INMSEL multiplexer for negative inputs (COMPx_INM1, COMPx_INM2), a SCALERN/BRGEN block for reference voltages (1/4 VREF_COMP, 1/2 VREF_COMP, 3/4 VREF_COMP), and a BLANKING block. The core comparator (Cmp) compares the inputs. Output logic includes POLARITY, ITEN (interrupt enable), DFF (d flip-flop) with CLR, and CCxIF (capture/compare interrupt flags). External outputs include compx_wkup, compx_out, and GPIO alternate functions (COMPx_OUT).

The diagram illustrates the internal architecture of the COMP block, which contains two independent comparator channels, Channel 1 and Channel 2. Each channel consists of an input selection multiplexer (INPSEL) for the non-inverting input and another (INMSEL) for the inverting input. The inverting input can be connected to external pins (COMPx_INM1, COMPx_INM2) or to internal reference voltages generated by a SCALERN/BRGEN block. This block takes VREFINT and a 6-bit input (comp_blk1..comp_blk6) to produce reference levels of 1/4, 1/2, and 3/4 of VREF_COMP. A BLANKING block is used to filter out short-duration noise. The core comparator (Cmp) compares the two inputs. The output of the comparator is passed through a POLARITY block and then combined with an interrupt enable signal (ITEN) via an AND gate. This signal is then latched by a D flip-flop (DFF) with a clear (CLR) input. The DFF output is used to generate the interrupt signal (compx_it) and to set the capture/compare interrupt flag (CCxIF). The output of the DFF is also connected to the external output pins (compx_out) and to the GPIO alternate functions (COMPx_OUT). The diagram also shows the APB bus interface and the internal signals (cmpx_inp, cmpx_inm, cmpx_out, cmpx_wkup, cmpx_it) used within the block.

Figure 216. Comparator functional block diagram. The diagram shows two comparator channels, Channel 1 and Channel 2, within a COMP block. Each channel has an INPSEL multiplexer for positive inputs (COMPx_INP1, COMPx_INP2), an INMSEL multiplexer for negative inputs (COMPx_INM1, COMPx_INM2), a SCALERN/BRGEN block for reference voltages (1/4 VREF_COMP, 1/2 VREF_COMP, 3/4 VREF_COMP), and a BLANKING block. The core comparator (Cmp) compares the inputs. Output logic includes POLARITY, ITEN (interrupt enable), DFF (d flip-flop) with CLR, and CCxIF (capture/compare interrupt flags). External outputs include compx_wkup, compx_out, and GPIO alternate functions (COMPx_OUT).

28.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 235. 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 236. 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 28.3.8: Comparator output on GPIOs .
COMP2_OUTDigital outputCOMP channel 2 output: see Section 28.3.8: Comparator output on GPIOs .

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

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

28.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 216: Comparator functional block diagram .

28.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 217. Comparator hysteresis

Figure 217: Comparator hysteresis diagram. The top graph shows the INP input signal as a sine-like wave. The INM reference level is shown as a dashed line, and INM - V_hyst as another dashed line below it. The bottom graph shows the COMP_OUT signal as a square wave that toggles based on the INP signal crossing the hysteresis levels. The diagram is labeled MS19984V1.
Figure 217: Comparator hysteresis diagram. The top graph shows the INP input signal as a sine-like wave. The INM reference level is shown as a dashed line, and INM - V_hyst as another dashed line below it. The bottom graph shows the COMP_OUT signal as a square wave that toggles based on the INP signal crossing the hysteresis levels. The diagram is labeled MS19984V1.

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

Figure 218. Comparator output blanking

Figure 218: Comparator output blanking diagram. It shows five timing diagrams: PWM, Inverting input (represents current limit), Non-inverting input (represents current), cmp_out (before blanking gate), and cmp_out (COMP output). A 'current spike' is shown on the non-inverting input, causing a 'spurious pulse' on the cmp_out signal. The cmp_blk signal defines a 'blanking window' during which the spurious pulse is ignored. At the bottom, a logic diagram shows a NAND gate labeled 'Blanking gate' with inputs cmp_out and cmp_blk, and output comp_out (to I/Os, TIM_BK ...). The diagram is labeled MS30964V2.
Figure 218: Comparator output blanking diagram. It shows five timing diagrams: PWM, Inverting input (represents current limit), Non-inverting input (represents current), cmp_out (before blanking gate), and cmp_out (COMP output). A 'current spike' is shown on the non-inverting input, causing a 'spurious pulse' on the cmp_out signal. The cmp_blk signal defines a 'blanking window' during which the spurious pulse is ignored. At the bottom, a logic diagram shows a NAND gate labeled 'Blanking gate' with inputs cmp_out and cmp_blk, and output comp_out (to I/Os, TIM_BK ...). The diagram is labeled MS30964V2.

28.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 237. 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 238. 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.

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

Figure 219. Output redirection diagram showing the internal logic of the comparator output redirection. A comparator (COMP) has its output connected to an AF output (AFO) configured as open drain, which is connected to a PAD. The AFO is also connected to an AF input (AFI) enabled (active low). The AFI is connected to a multiplexer (MUX) with BKINP = 1. The MUX output is connected to the timer break input (active high). The MUX is also connected to TIMx_BKINy (x=1,8 ; y=...,2).

The diagram illustrates the internal circuitry for output redirection. At the bottom, a comparator labeled 'COMP' has its output connected to a node labeled 'AFO'. This node is connected to a PAD (represented by a square with an 'X') and also to an AF input labeled 'AFI'. The 'AFI' node is connected to a multiplexer. The multiplexer has two inputs: one from the 'AFO' node and another from a signal labeled 'TIMx_BKINy (x=1,8 ; y=...,2)'. The multiplexer is controlled by a signal 'BKINP = 1'. The output of the multiplexer is labeled 'To the timer break input (active high)'. Above the multiplexer, there is a label 'AF input enabled (active low)' with an arrow pointing to the 'AFI' node. The 'AFO' node is also labeled 'AF output configured as open drain' and is connected to ground through an open-drain transistor symbol. The diagram is signed 'MSv38378V1' in the bottom right corner.

Figure 219. Output redirection diagram showing the internal logic of the comparator output redirection. A comparator (COMP) has its output connected to an AF output (AFO) configured as open drain, which is connected to a PAD. The AFO is also connected to an AF input (AFI) enabled (active low). The AFI is connected to a multiplexer (MUX) with BKINP = 1. The MUX output is connected to the timer break input (active high). The MUX is also connected to TIMx_BKINy (x=1,8 ; y=...,2).

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

28.4 COMP low-power modes

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

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

28.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 240. 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

28.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 241. 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.

28.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 220. Scaler block diagram

Scaler block diagram showing an operational amplifier with V_REFINT at its non-inverting input. The output of the amplifier feeds a resistor ladder. The amplifier is enabled by an OR gate with SCALEN (ch.1) and SCALEN (ch.2) inputs. The resistor ladder is connected to ground through a switch controlled by an OR gate with BRGEN (ch.1) and BRGEN (ch.2) inputs. The ladder provides output taps for 3/4 V_REF_COMP, 1/2 V_REF_COMP, and 1/4 V_REF_COMP. The top of the ladder is V_REF_COMP.

MSV38379V1

Scaler block diagram showing an operational amplifier with V_REFINT at its non-inverting input. The output of the amplifier feeds a resistor ladder. The amplifier is enabled by an OR gate with SCALEN (ch.1) and SCALEN (ch.2) inputs. The resistor ladder is connected to ground through a switch controlled by an OR gate with BRGEN (ch.1) and BRGEN (ch.2) inputs. The ladder provides output taps for 3/4 V_REF_COMP, 1/2 V_REF_COMP, and 1/4 V_REF_COMP. The top of the ladder is V_REF_COMP.

28.7 COMP registers

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

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

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

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

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

28.7.6 COMP register map

The following table summarizes the comparator registers.

Table 242. 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.C2VAL
Reset value000
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 value0000000000000000000000000000000
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 129 for the register boundary addresses.