23. Operational amplifiers (OPAMP)

23.1 Introduction

The devices embed one operational amplifier with two inputs and one output. The three I/Os can be connected to the external pins, thus enabling any type of external interconnections. The operational amplifiers can be configured internally in three possible ways:

Refer to Section 23.3.3: Signal routing for detailed information on OPAMP input and output connection to internal peripherals.

23.2 OPAMP main features

Note: Refer to the product datasheet for detailed OPAMP characteristics.

23.3 OPAMP functional description

The OPAMP has several modes.

Each OPAMP can be individually enabled, when disabled the output is high-impedance.

When enabled, it can be in calibration mode, all input, and output of the OPAMP are then disconnected, or in functional mode.

There are two functional modes, the high-speed mode and the normal mode. In functional mode, the inputs and output of the OPAMP are connected as described in Section 23.3.3: Signal routing.

23.3.1 OPAMP reset and clocks

The operational amplifier clock is necessary for accessing the registers. When the application does not need to have a read or write access to those registers, the clock can be switched off using the peripheral clock enable register. See OPAMPEN bit in Section 10.8.24: RCC APB1 peripheral clock register (RCC_APB1LENR).

The bit OPAEN enables and disables the OPAMP operation. The OPAMP registers configurations should be changed before enabling the OPAEN bit in order to avoid spurious effects on the output.

When the output of the operational amplifier is no more needed, the operational amplifier can be disabled to save power. All the configurations previously set (including the calibration) are maintained while OPAMP is disabled.

23.3.2 Initial configuration

The default configuration of the operational amplifier is a functional mode where the three input/outputs are connected to external pins. In the default mode, the operational amplifier uses the factory trimming values for its offset calibration. See electrical characteristics section of the datasheet for factory trimming conditions, usually the temperature is 30 °C and the voltage is 3 V. The trimming values can be adjusted. See Section 23.3.5: Calibration for changing the trimming values. The default configuration uses the normal mode, which provides the standard performance. The bit OPAHSM can be set in order to switch the operational amplifier to high-speed mode for a better slew rate. Both normal and high-speed mode characteristics are defined in section: Electrical characteristics of the datasheet.

As soon as the OPAEN bit in the OPAMPx_CSR register is set, the operational amplifier is functional. The two input pins and the output pin are connected as defined in Section 23.3.3: Signal routing and the default connection settings can be changed.

Note: The inputs and output pins must be configured in analog mode (default state) in the corresponding GPIOx_MODER register.

23.3.3 Signal routing

The OPAMPx_CSR register determines the routing for the operational amplifier pins.

The connections of the operational amplifier (OPAMP1) are described in the table below.

Table 149. Possible connections for OPAMP

SignalPinInternalcomment
OPAMP1_VINMPC5(INM0)
PB1(INM1)
ADC1_INP8
ADC1_INM4
ADC1_INP5
COMP1_INM6
OPAMP1_VOUT or
PGA
The bits PGA_GAIN and VM_SEL control this pin. ADC controls the ADC input.
OPAMP1_VINPPB0(INP0)
PA0(INP2)
dac1_out1 (INP1)
ADC1_INM5
ADC1_INP9
ADC1_INP0
ADC1_INM1
COMP1_INP1
The bit VP_SEL controls this pin. ADC controls the ADC input.
OPAMP1_VOUTPA7ADC1_INM3
ADC1_INP7
The pin is connected when the OPAMP is enabled. The ADC input is controlled by ADC.

23.3.4 OPAMP modes

The operational amplifier inputs and outputs are all accessible on terminals. The amplifiers can be used in multiple configuration environments:

Note: The amplifier output pin is directly connected to the output pad to minimize the output impedance. When the amplifier is enabled, it cannot be used as a general-purpose I/O, even if the amplifier is configured as a PGA and only connected to the internal channel.

The impedance of the signal must be maintained below a level that avoids the input leakage to create significant artifacts (due to a resistive drop in the source). Please refer to the electrical characteristics section in the datasheet for further details.

Standalone mode (external gain setting mode)

The procedure to use the OPAMP in standalone mode is presented below.

Starting from the default value of OPAMPx_CSR, and the default state of GPIOx_MODER, as soon as the OPAEN bit is set, the two input pins and the output pin are connected to the operational amplifier.

This default configuration uses the factory trimming values and operates in normal mode (highest performance). The behavior of the OPAMP can be changed as follows:

Figure 147. Standalone mode: external gain setting mode

Schematic diagram of Standalone mode: external gain setting mode. The diagram shows an STM32 block containing an operational amplifier. The non-inverting input (+) is connected to a multiplexer that can select between INP0 or 2 and dac_out1. The inverting input (-) is connected to a multiplexer that can select between INM0 or 1 and the output (VOUT). The output of the op-amp is labeled opamp_out. A feedback network consisting of a resistor and a capacitor is connected between the output and the inverting input. The VOUT pin is also connected to the inverting input through a resistor. The entire circuit is enclosed in a dashed box representing the STM32.

MSv68860V1

Schematic diagram of Standalone mode: external gain setting mode. The diagram shows an STM32 block containing an operational amplifier. The non-inverting input (+) is connected to a multiplexer that can select between INP0 or 2 and dac_out1. The inverting input (-) is connected to a multiplexer that can select between INM0 or 1 and the output (VOUT). The output of the op-amp is labeled opamp_out. A feedback network consisting of a resistor and a capacitor is connected between the output and the inverting input. The VOUT pin is also connected to the inverting input through a resistor. The entire circuit is enclosed in a dashed box representing the STM32.

Follower configuration mode

The procedure to use the OPAMP in follower mode is presented below.

Note: The pin corresponding to OPAMPx_VINM is free for another usage.
The signal on the OPAMP1 output is also seen as an ADC input. As a consequence, the OPAMP configured in follower mode can be used to perform impedance adaptation on input signals before feeding them to the ADC input, assuming the input signal frequency is compatible with the operational amplifier gain bandwidth specification.

Figure 148. Follower configuration

Schematic diagram of the Follower configuration within an STM32 microcontroller. The diagram shows an operational amplifier (opamp) with its non-inverting input (+) connected to a multiplexer selecting between INP0 or 2 and dac_out1. The inverting input (-) is connected to a feedback network consisting of a resistor and a variable resistor (potentiometer) in series, with the other end of the variable resistor connected to ground. The output of the opamp is connected to the opamp_out pin and is also fed back to the inverting input. A note indicates that the VOUT pin is always connected to the OPAMP output. The entire circuit is enclosed in a dashed box labeled STM32.

MSv68861V1

Schematic diagram of the Follower configuration within an STM32 microcontroller. The diagram shows an operational amplifier (opamp) with its non-inverting input (+) connected to a multiplexer selecting between INP0 or 2 and dac_out1. The inverting input (-) is connected to a feedback network consisting of a resistor and a variable resistor (potentiometer) in series, with the other end of the variable resistor connected to ground. The output of the opamp is connected to the opamp_out pin and is also fed back to the inverting input. A note indicates that the VOUT pin is always connected to the OPAMP output. The entire circuit is enclosed in a dashed box labeled STM32.

Programmable gain amplifier mode

The procedure to use the OPAMP as programmable gain amplifier is presented below.

As soon as the OPAEN bit is set, the selected gain amplifies the none-inverting input voltage, and it is visible on pin OPAMPx_VOUT.

Note: To avoid saturation, the input voltage should stay below \(V_{DDA}\) divided by the selected gain.

Figure 149. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input not used

Schematic diagram of the PGA mode in an STM32 microcontroller. The diagram shows an internal operational amplifier (opamp) with its non-inverting input (+) connected to a multiplexer. This multiplexer selects between INP0 or 2 and a DAC output (dac_out1). The inverting input (-) is connected to another multiplexer that selects between INM0 or 1 and the opamp output. The opamp output is connected to the external VOUT pin and is also fed back to the inverting input through a feedback network consisting of a variable resistor (potentiometer) and a fixed resistor in series to ground. The entire circuit is enclosed in a dashed box labeled STM32.

MSv68862V1

Schematic diagram of the PGA mode in an STM32 microcontroller. The diagram shows an internal operational amplifier (opamp) with its non-inverting input (+) connected to a multiplexer. This multiplexer selects between INP0 or 2 and a DAC output (dac_out1). The inverting input (-) is connected to another multiplexer that selects between INM0 or 1 and the opamp output. The opamp output is connected to the external VOUT pin and is also fed back to the inverting input through a feedback network consisting of a variable resistor (potentiometer) and a fixed resistor in series to ground. The entire circuit is enclosed in a dashed box labeled STM32.

Programmable gain amplifier mode with external filtering

The procedure to use the OPAMP to amplify the amplitude of an input signal, with an external filtering, is presented below.

Any external connection on INM can be used in parallel with the internal PGA. For example, a capacitor can be connected between opamp_out and INM for filtering purpose. Refer to the datasheet for the value of resistors used in the PGA resistor network.

Figure 150. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input used for filtering

Schematic diagram of the PGA mode showing the internal op-amp, feedback network, and external filtering options. It includes labels for STM32, INP0 or 2, dac_out1, INM0, opamp_out1, VOUT, and a note about optional low-pass filtering.
Schematic diagram of the PGA mode showing the internal op-amp, feedback network, and external filtering options. It includes labels for STM32, INP0 or 2, dac_out1, INM0, opamp_out1, VOUT, and a note about optional low-pass filtering.

1. The gain depends on the cut-off frequency.

Programmable gain amplifier, non-inverting with external bias or inverting mode

The procedure to use the OPAMP to amplify the amplitude of an input signal with bias voltage for non-inverting mode or inverting mode.

Figure 151. PGA mode, non-inverting gain setting (x2/x4/x8/x16) or inverting gain setting (x-1/x-3/x-7/x-15)

Schematic diagram of an OPAMP configuration within an STM32. The non-inverting input (+) is connected to a multiplexer selecting between INP0 or 2 and dac_outx. The inverting input (-) is connected to a feedback network consisting of a variable resistor and a fixed resistor. The output is labeled opamp_out. A note indicates that VOUT is always connected to the OPAMP output. The diagram is labeled MSv68864V1.
Schematic diagram of an OPAMP configuration within an STM32. The non-inverting input (+) is connected to a multiplexer selecting between INP0 or 2 and dac_outx. The inverting input (-) is connected to a feedback network consisting of a variable resistor and a fixed resistor. The output is labeled opamp_out. A note indicates that VOUT is always connected to the OPAMP output. The diagram is labeled MSv68864V1.

Figure 152. Example configuration

Two example circuit configurations for an OPAMP. The left configuration shows a non-inverting setup with VINP at the non-inverting input, a bias voltage at INM0, and a feedback network with a variable resistor and a fixed resistor connected to INM1. It is labeled 'Gain: x2, x4, x8, x16'. The right configuration shows an inverting setup with a bias voltage at VINP, an input signal through a resistor to the inverting input (INM0), and a feedback network with a variable resistor and a fixed resistor connected to INM1. It is labeled 'Gain: x-1, x-3, x-7, x-15'. The word 'or' is placed between the two diagrams. The diagram is labeled MSv68866V1.
Two example circuit configurations for an OPAMP. The left configuration shows a non-inverting setup with VINP at the non-inverting input, a bias voltage at INM0, and a feedback network with a variable resistor and a fixed resistor connected to INM1. It is labeled 'Gain: x2, x4, x8, x16'. The right configuration shows an inverting setup with a bias voltage at VINP, an input signal through a resistor to the inverting input (INM0), and a feedback network with a variable resistor and a fixed resistor connected to INM1. It is labeled 'Gain: x-1, x-3, x-7, x-15'. The word 'or' is placed between the two diagrams. The diagram is labeled MSv68866V1.

Programmable gain amplifier, non-inverting with external bias or inverting mode with filtering

The procedure to use the OPAMP to amplify the amplitude of an input signal with bias voltage for non-inverting mode or inverting mode with filtering

Any external connection on VM1 can be used in parallel with the internal PGA. For example, a capacitor can be connected between opamp_out and VM1 for filtering purposes. See datasheet for the value of resistors used in the PGA resistor network.

Figure 153. PGA mode, non-inverting gain setting (x2/x4/x8/x16) or inverting gain setting (x-1/x-3/x-7/x-15) with filtering

Figure 153: Block diagram showing PGA mode with filtering in STM32, depicting input multiplexers, internal op-amp, feedback network, filtering capacitor, and equivalent RC circuit connection.
Figure 153: Block diagram showing PGA mode with filtering in STM32, depicting input multiplexers, internal op-amp, feedback network, filtering capacitor, and equivalent RC circuit connection.

MSv68865V1

Figure 154. Example configuration

Figure 154: Example configurations for OPAMP showing non-inverting mode with bias voltage (Gain: x2, x4, x8, x16) and inverting mode with bias voltage (Gain: x-1, x-3, x-7, x-15).
Figure 154: Example configurations for OPAMP showing non-inverting mode with bias voltage (Gain: x2, x4, x8, x16) and inverting mode with bias voltage (Gain: x-1, x-3, x-7, x-15).

23.3.5 Calibration

The OPAMP interface continuously sends trimmed offset values to the operational amplifiers. At startup, the trimming values are initialized with the preset 'factory' trimming value.

The user can trim each operational amplifier. Specific registers allow the user to have different trimming values for normal mode and for high-speed mode.

The aim of the calibration is to cancel as much as possible the OPAMP inputs offset voltage. The calibration circuitry allows the user to reduce the input offset voltage to less than +/- 1.5 mV within stable voltage and temperature conditions.

For each operational amplifier and each mode two trimming value needs to be trimmed, one for N differential pair and one for P differential pair.

There are two registers for trimming the offsets for each operational amplifier, one for normal mode (OPAMPx_OTR) and one high-speed mode (OPAMPx_HSOTR). Each register is composed of five bits for P differential pair trimming and five bits for N differential pair trimming. These are the 'user' values.

The user is able to switch from 'factory' values to 'user' trimmed values using the USERTRIM bit in the OPAMPx_CSR register. This bit is reset at startup and so the 'factory' value are applied by default to the OPAMP option registers.

User is liable to change the trimming values in calibration or in functional mode.

The offset trimming registers are typically configured after the calibration operation is initialized by setting bit CALON to 1. When CALON = 1 the inputs of the operational amplifier are disconnected from the functional environment.

When CALON = 1, the bit CALOUT reflects the influence of the trimming value selected by CALSEL and OPAHSM. The software should increment the TRIMOFFSETN bits in the OPAMP control register from 0x00 to the first value that causes the CALOUT bit to change from 1 to 0 in the OPAMP register. If the CALOUT bit is reset, the offset is calibrated correctly and the corresponding trimming value must be stored. The CALOUT flag needs up to 1 ms after the trimming value is changed to become steady (see \(t_{OFFTRIM}\) max delay specification in the electrical characteristics section of the datasheet).

Note: The closer the trimming value is to the optimum trimming value, the longer it takes to stabilize. The maximum stabilization time remains below 1 ms in any case.

Table 150. Operating modes and calibration

ModeControl bitsOutput
OPAENOPAHSMCALONCALSELVOUTCALOUT flag
Normal operating mode100Xanalog0
High-speed mode110Xanalog0
Power down0XXXZ0

Table 150. Operating modes and calibration (continued)

ModeControl bitsOutput
OPAENOPAHSCALONCALSELVOUTCALOUT flag
Offset calibration N difference for normal mode10111analogX
Offset calibration P difference for normal mode10101analogX
Offset calibration N difference for high-speed mode11111analogX
Offset calibration P difference for high-speed mode11101analogX

Calibration procedure

Here are the steps to perform a full calibration of either one of the operational amplifiers:

  1. 1. Set the OPAEN bit in OPAMPx_CSR to 1 to enable the operational amplifier.
  2. 2. Set the USERTRIM bit in the OPAMPx_CSR register to 1.
  3. 3. Choose a calibration mode (refer to Table 150: Operating modes and calibration). The steps 3 to 4 must be repeated four times. For the first iteration, select the following:
    • – Normal mode and N differential pair

    The above calibration mode corresponds to OPAHS=0 and CALSEL=11 in the OPAMPx_CSR register.

  4. 4. Increment TRIMOFFSETN[4:0] in OPAMPx_OTR starting from 00000b until CALOUT changes to 0 in OPAMPx_CSR.

Note: Between the write to the OPAMPx_OTR register and the read of the CALOUT value, make sure to wait for the \(t_{OFFTRIM}^{max}\) delay specified in the electrical characteristics section of the datasheet, to get the correct CALOUT value.

Repeat steps 3 to 4 for:

If a mode is not used, it is not necessary to perform the corresponding calibration.

Note: During the whole calibration phase the external connection of the operational amplifier output must not pull up or down currents higher than 500 µA.

23.4 OPAMP low-power modes

Table 151. Effect of low-power modes on the OPAMP

ModeDescription
SleepNo effect.
StopNo effect, OPAMP registers content is kept.
StandbyThe OPAMP registers are powered down and must be reinitialized after exiting Standby.

23.5 OPAMP PGA gain

When OPAMP is configured as PGA mode, it can select the gain of x2, x4, x8, x16 for non-inverting mode and x-1, x-3, x-7, x-15 for inverting mode.

When OPAMP is configured as non-inverting mode, the gain error is specified in the product datasheet. When it is configured as inverting mode, the gain factor is defined not only the on chip feedback resistor but also the signal source output impedance. If the signal source output impedance is not negligible compare to the input feedback resistance of PGA, it creates the gain error. Please refer to the PGA resistance value in the product datasheet.

23.6 OPAMP registers

The registers of this peripheral can only be accessed by-word (32-bit).

23.6.1 OPAMP1 control/status register (OPAMP1_CSR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.CAL OUTTST REFRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.USER TRIMPGA_GAIN[3:2]
rrwrwrwrw
1514131211109876543210
PGA_GAIN[1:0]CALSEL[1:0]CALONRes.Res.OPA HSMRes.VM_SEL[1:0]Res.VP_SEL[1:0]FORCE_VPOPAEN
rwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 Reserved, must be kept at reset value.

Bit 30 CALOUT: Operational amplifier calibration output

OPAMP output status flag. During the calibration mode, OPAMP is used as comparator.

0: Non-inverting < inverting

1: Non-inverting > inverting

Bit 29 TSTREF: OPAMP calibration reference voltage output control (reserved for test)

0: INTVREF of OPAMP is not output

1: INTVREF of OPAMP is output

Bits 28:19 Reserved, must be kept at reset value.

Bit 18 USERTRIM: User trimming enable

This bit allows to switch from 'factory' AOP offset trimmed values to 'user' AOP offset trimmed values

This bit is active for both mode normal and high-power.

0: 'factory' trim code used

1: 'user' trim code used

Bits 17:14 PGA_GAIN[3:0]: Programmable gain amplifier gain setting

0000: Non-inverting internal gain 2, VREF-referenced

0001: Non-inverting internal gain 4, VREF-referenced

0010: Non-inverting internal gain 8, VREF-referenced

0011: Non-inverting internal gain 16, VREF-referenced

0100: Non-inverting internal gain 2 with filtering on INM0, VREF-referenced

0101: Non-inverting internal gain 4 with filtering on INM0, VREF-referenced

0110: Non-inverting internal gain 8 with filtering on INM0, VREF-referenced

0111: Non-inverting internal gain 16 with filtering on INM0, VREF-referenced

1000: Inverting gain=-1/ Non-inverting gain =2 with INM0 node for input or bias

1001: Inverting gain=-3/ Non-inverting gain =4 with INM0 node for input or bias

1010: Inverting gain=-7/ Non-inverting gain =8 with INM0 node for input or bias

1011: Inverting gain=-15/ Non-inverting gain =16 with INM0 node for input or bias

1100: Inverting gain=-1/ Non-inverting gain =2 with INM0 node for input or bias, INM1 node for filtering

1101: Inverting gain=-3/ Non-inverting gain =4 with INM0 node for input or bias, INM1 node for filtering

1110: Inverting gain=-7/ Non-inverting gain =8 with INM0 node for input or bias, INM1 node for filtering

1111: Inverting gain=-15/ Non-inverting gain =16 with INM0 node for input or bias, INM1 node for filtering

Bits 13:12 CALSEL[1:0]: Calibration selection

It is used to select the offset calibration bus used to generate the internal reference voltage when CALON = 1 or FORCE_VP= 1.

00: 0.033*VDDA applied on OPAMP inputs

01: 0.1*VDDA applied on OPAMP inputs (for PMOS calibration)

10: 0.5*VDDA applied on OPAMP inputs

11: 0.9*VDDA applied on OPAMP inputs (for NMOS calibration)

Bit 11 CALON: Calibration mode enabled

0: Normal mode

1: Calibration mode (all switches opened by HW)

Bits 10:9 Reserved, must be kept at reset value.

Bit 8 OPAHSM: Operational amplifier high-speed mode

The operational amplifier must be disabled to change this configuration.

0: operational amplifier in normal mode

1: operational amplifier in high-speed mode

Bit 7 Reserved, must be kept at reset value.

23.6.2 OPAMP1 trimming register in normal mode (OPAMP1_OTR)

Address offset: 0x04

Reset value: 0x0000 XXXX (factory trimmed values)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.TRIMOFFSETP[4:0]Res.Res.Res.TRIMOFFSETN[4:0]
rwrwrwrwrwrwrwrwrwrw

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

Bits 12:8 TRIMOFFSETP[4:0]: Trim for PMOS differential pairs

Bits 7:5 Reserved, must be kept at reset value.

Bits 4:0 TRIMOFFSETN[4:0]: Trim for NMOS differential pairs

23.6.3 OPAMP1 trimming register in high-speed mode (OPAMP1_HSOTR)

Address offset: 0x08

Reset value: 0x0000 XXXX (factory trimmed values)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.TRIMHSOFFSETP[4:0]Res.Res.Res.TRIMHSOFFSETN[4:0]
rwrwrwrwrwrwrwrwrwrw

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

Bits 12:8 TRIMHSOFFSETP[4:0]: High-speed mode trim for PMOS differential pairs

Bits 7:5 Reserved, must be kept at reset value.

Bits 4:0 TRIMHSOFFSETN[4:0]: High-speed mode trim for NMOS differential pairs

23.6.4 OPAMP register map

Table 152. OPAMP register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00OPAMP1_CSRRes.CALOUTTSTREFRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.USERTRIMPGA_GAINCALSELCALONRes.Res.OPAHSRes.Res.Res.Res.Res.Res.Res.Res.
Reset value0000000000000
0x04OPAMP1_OTRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TRIM OFFSETP[4:0]Res.Res.Res.Res.Res.TRIM OFFSETN[4:0]
Reset value(1)(1)
0x08OPAMP1_HSOTRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TRIMHS OFFSETP[4:0]Res.Res.Res.Res.Res.TRIMHS OFFSETN[4:0]
Reset value(1)(1)

1. Factory trimmed values.

Refer to Section 2.2 on page 70 for the register boundary addresses.