18. Operational amplifiers (OPAMP)

18.1 Introduction

The device embeds an operational amplifier with two inputs and one output. The three I/Os can be connected to the external pins. This enables any type of external interconnections. The operational amplifier can be configured internally as a follower or as an amplifier with a noninverting gain ranging from 2 to 16.

The positive input can be connected to the internal DAC.

The output can be connected to the internal ADC.

18.2 OPAMP main features

18.3 OPAMP functional description

The OPAMP has several modes.

When the OPAMP is disabled, the output is high-Z.

When it is enabled, it can be in calibration mode (where any OPAMP input and output is disconnected), or in functional mode.

There are two functional modes: the low-power mode or the normal mode. In functional mode, the OPAMP inputs and output of the OPAMP are connected as described in the Section 18.3.3: Signal routing .

18.3.1 OPAMP reset and clocks

The operational amplifier clock is necessary for accessing the registers. The clock can be switched off using the peripheral clock enable register when the application does not need to have read or write access to those registers. See OPAMPEN bit in Section 5.4.15: APB peripheral clock enable register 1 (RCC_APBENR1) .

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.

18.3.2 Initial configuration

The default configuration of the operational amplifier is a functional mode where the three I/Os are connected to external pins. In the default mode, the operational amplifier uses the factory trimming values. 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 18.3.5: Calibration for changing the trimming values. The default configuration uses the normal mode, which provides the highest performance. Bit OPALPM can be set in order to switch the operational amplifier to low-power mode and reduced performance. Both normal and low-power mode characteristics are defined in the section “electrical characteristics” of the datasheet. Before utilization, the bit OPA_RANGE of OPAMP_CSR must be set to 1 if \( V_{DDA} \) is above 2.4V, or kept at 0 otherwise.

As soon as the OPAEN bit in the OPAMP_CSR register is set, the operational amplifier is functional. The two input pins and the output pin are connected as defined in Section 18.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.

18.3.3 Signal routing

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

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

Table 96. Operational amplifier possible connections

SignalPinInternalcomment
OPAMP1_VINMPA1OPAMP1_OUT or PGAcontrolled by bits OPAMODE and VM_SEL.
OPAMP1_VINPPA0DAC1_OUT1controlled by bit VP_SEL.
OPAMP1_VOUTPA3ADC1_IN8 (through the GPIO)The pin is connected when the OPAMP is enabled. The ADC input is controlled by ADC.

18.3.4 OPAMP modes

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

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

Note: 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 OPAMP_CSR, and the default state of GPIOx_MODER, configure bit OPA_RANGE according to the \( V_{DDA} \) voltage. 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 70. Standalone mode: external gain setting mode

Circuit diagram of an operational amplifier (OPAMP) in standalone mode with external gain setting. The diagram shows an STM32 microcontroller (dashed box) containing an OPAMP. The non-inverting input (+) of the OPAMP is connected via a multiplexer to either a GPIO pin or DAC_OUT. The inverting input (-) is connected via another multiplexer to either a GPIO pin or a feedback path. Externally, there are resistors and capacitors connected to the GPIO pins to form a gain-setting network. The output of the OPAMP is connected to an internal ADC and also brought out to a pin. Labeled MS35324V1.
Circuit diagram of an operational amplifier (OPAMP) in standalone mode with external gain setting. The diagram shows an STM32 microcontroller (dashed box) containing an OPAMP. The non-inverting input (+) of the OPAMP is connected via a multiplexer to either a GPIO pin or DAC_OUT. The inverting input (-) is connected via another multiplexer to either a GPIO pin or a feedback path. Externally, there are resistors and capacitors connected to the GPIO pins to form a gain-setting network. The output of the OPAMP is connected to an internal ADC and also brought out to a pin. Labeled MS35324V1.

Follower configuration mode

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

Note: The pin corresponding to OPAMP_VINM is free for another usage.

Note: The signal on the operational amplifier 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 71. Follower configuration

Circuit diagram of an operational amplifier (OPAMP) in a follower configuration connected to an STM32 microcontroller. The non-inverting input (+) is connected to a DAC_OUT pin via a buffer. The inverting input (-) is connected to the OPAMP output in a unity-gain feedback loop. The output is connected to an ADC and a variable resistor circuit. A debug pin is also connected to the output.

The diagram illustrates a follower configuration for an operational amplifier (OPAMP) within an STM32 microcontroller. The microcontroller is represented by a dashed box labeled 'STM32'. Inside, the non-inverting input (+) of the OPAMP is connected to a 'DAC_OUT' pin through a buffer. The inverting input (-) is connected to the OPAMP's output in a unity-gain feedback loop. The output is connected to an 'ADC' and a circuit consisting of a variable resistor and a fixed resistor connected to ground. A debug pin, labeled 'Always connected to OPAMP output (can be used during debug)', is also connected to the output. The diagram is labeled 'MS35325V1' in the bottom right corner.

Circuit diagram of an operational amplifier (OPAMP) in a follower configuration connected to an STM32 microcontroller. The non-inverting input (+) is connected to a DAC_OUT pin via a buffer. The inverting input (-) is connected to the OPAMP output in a unity-gain feedback loop. The output is connected to an ADC and a variable resistor circuit. A debug pin is also connected to the output.

Programmable Gain Amplifier mode

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

As soon as the OPAEN bit is set, the selected gain amplifies the signal on the OPAMP_VINP pin. This is visible on the OPAMP_VOUT pin.

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

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

Circuit diagram of an operational amplifier (OPAMP) in Programmable Gain Amplifier (PGA) mode. The diagram shows the internal structure of the OPAMP within an STM32 microcontroller. The non-inverting input (+) is connected to a GPIO pin and a DAC_OUT pin. The inverting input (-) is connected to the output in a unity-gain feedback configuration. The output is connected to an ADC and a variable resistor (potentiometer) which is also connected to ground. A note indicates that the output is 'Always connected to OPAMP output (can be used during debug)'. The diagram is labeled MS35326V1.

The diagram illustrates the internal configuration of an OPAMP within an STM32 microcontroller for PGA mode. The non-inverting input (+) is connected to a GPIO pin and a DAC_OUT pin. The inverting input (-) is connected to the output in a unity-gain feedback configuration. The output is connected to an ADC and a variable resistor (potentiometer) which is also connected to ground. A note indicates that the output is 'Always connected to OPAMP output (can be used during debug)'. The diagram is labeled MS35326V1.

Circuit diagram of an operational amplifier (OPAMP) in Programmable Gain Amplifier (PGA) mode. The diagram shows the internal structure of the OPAMP within an STM32 microcontroller. The non-inverting input (+) is connected to a GPIO pin and a DAC_OUT pin. The inverting input (-) is connected to the output in a unity-gain feedback configuration. The output is connected to an ADC and a variable resistor (potentiometer) which is also connected to ground. A note indicates that the output is 'Always connected to OPAMP output (can be used during debug)'. The diagram is labeled MS35326V1.

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 VINP can be used in parallel with the internal PGA, for example a capacitor can be connected between VOUT and VINM for filtering purposes. See datasheet for the value of resistors used in the PGA resistor network.

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

Circuit diagram showing an STM32 microcontroller's internal OPAMP configured in PGA mode. The non-inverting input (+) is connected via a multiplexer to either a GPIO or DAC_OUT. The inverting input (-) is connected via a multiplexer to a feedback network. A GPIO pin allows an external capacitor to be connected between the output and the inverting input for low-pass filtering. The feedback network includes a resistor ladder connected to ground. The output is also routed to an internal ADC. A dashed line indicates the 'Equivalent to' relationship between the external capacitor and the internal filtering path. Labeled MS35327V1.
Circuit diagram showing an STM32 microcontroller's internal OPAMP configured in PGA mode. The non-inverting input (+) is connected via a multiplexer to either a GPIO or DAC_OUT. The inverting input (-) is connected via a multiplexer to a feedback network. A GPIO pin allows an external capacitor to be connected between the output and the inverting input for low-pass filtering. The feedback network includes a resistor ladder connected to ground. The output is also routed to an internal ADC. A dashed line indicates the 'Equivalent to' relationship between the external capacitor and the internal filtering path. Labeled MS35327V1.

1. The gain depends on the cutoff frequency.

18.3.5 Calibration

At startup, the trimming values are initialized with the preset ‘factory’ trimming value.

The user can trim the operational amplifier offset. Specific registers allow different trimming values for normal mode and for low-power mode.

The aim of the calibration is to cancel as much as possible the OPAMP inputs offset voltage. The calibration circuitry reduces the inputs offset voltage to less than \( \pm 1.5 \) mV within stable voltage and temperature conditions.

For each mode of the operational amplifier, two trimming values need to be trimmed, one for N differential pair and one for P differential pair.

There are two registers for trimming the operational amplifier offset, one for normal mode ( OPAMP_OTR ) and one low-power mode ( OPAMP_LPOTR ). 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.

Using the USERTRIM bit in the OPAMP_CSR register, the user can switch from 'factory' values to 'user' trimmed values. This bit is reset at startup. The 'factory' value is then applied by default to the OPAMP trimming 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 CALOUT bit reflects the influence of the trimming value selected by CALSEL and OPALPM. When the value of CALOUT switches between two consecutive trimming values, this means that those two values are the best trimming values. The CALOUT flag needs up to 1 ms after the trimming value is changed to become steady (see \( t_{OFFTRIMmax} \) 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 97. Operating modes and calibration

ModeControl bitsOutput
OPAENOPALPMCALONCALSELV OUTCALOUT flag
Normal operating mode100Xanalog0
Low-power mode110Xanalog0
Power down0XXXZ0
Offset cal high for normal mode1010analogX
Offset cal low for normal mode1011analogX
Offset cal high for low-power mode1110analogX
Offset cal low for low-power mode1111analogX

Calibration procedure

Here are the steps to perform full operational amplifier calibration:

  1. 1. Select correct OPA_RANGE in OPAMP_CSR, then set the OPAEN bit in OPAMP_CSR to 1 to enable the operational amplifier.
  2. 2. Set the USERTRIM bit in the OPAMP_CSR register to 1.
  3. 3. Choose a calibration mode (refer to Table 97: Operating modes and calibration ). The steps 3 to 4 must be repeated four times. For the first iteration, select :
    • – Normal mode, offset cal high (N differential pair)
    The above calibration mode corresponds to OPALPM=0 and CALSEL=0 in the OPAMP_CSR register.
  4. 4. Increment TRIMOFFSETN[4:0] in OPAMP_OTR, starting from 00000b and until CALOUT changes to 1 in OPAMP_CSR.

Note: CALOUT switches from 0 to 1 for offset cal high and from 1 to 0 for offset cal low.

Note: Between the write to the OPAMP_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.

The commutation means that the offset is correctly compensated and that the corresponding trim code must be saved in the OPAMP_OTR register.

Repeat steps 3 to 4 for:

If a mode is not in use, you do not need 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 \( \mu \) A.

During the calibration procedure, it is necessary to set up OPAMODE bits as 00 or 01 (PGA disable) or 11 (internal follower).

18.4 OPAMP low-power modes

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

ModeDescription
SleepNo effect.
Stop 0 / Stop 1No effect, OPAMP registers content is kept.
Stop 2OPAMP registers content is kept. OPAMP must be disabled before entering Stop 2 mode.
StandbyThe OPAMP registers are powered down and must be re-initialized after exiting Standby or Shutdown mode.
Shutdown

18.5 OPAMP registers

18.5.1 OPAMP1 control/status register (OPAMP1_CSR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
OPA_
RANGE
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
rw

1514131211109876543210
CAL
OUT
USER
TRIM
CAL
SEL
CALONRes.VP_
SEL
VM_SEL[9:8]Res.Res.PGA_GAIN[5:4]OPAMODE[3:2]OPA
LPM
OPAEN
rrwrwrwrwrwrwrwrwrwwrwrw

Bit 31 OPA_RANGE : Operational amplifier power supply range for stability

All AOP must be in power down to allow AOP-RANGE bit write. It applies to all AOP embedded in the product.

0: Low range ( \( V_{DDA} < 2.4V \) )

1: High range ( \( V_{DDA} > 2.4V \) )

Bits 30:16 Reserved, must be kept at reset value.

Bit 15 CALOUT : Operational amplifier calibration output

During calibration mode offset is trimmed when this signal toggle.

Bit 14 USERTRIM : allows to switch from 'factory' AOP offset trimmed values to AOP offset 'user' trimmed values

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

0: 'factory' trim code used

1: 'user' trim code used

Bit 13 CALSEL : Calibration selection

0: NMOS calibration (200mV applied on OPAMP inputs)

1: PMOS calibration ( \( V_{DDA}-200mV \) applied on OPAMP inputs)

Bit 12 CALON : Calibration mode enabled

0: Normal mode

1: Calibration mode (all switches opened by HW)

Bit 11 Reserved, must be kept at reset value.

Bit 10 VP_SEL : Non inverted input selection

0: GPIO connected to VINP

1: DAC connected to VINP

Bits 9:8 VM_SEL[9:8] : Inverting input selection

These bits are used only when OPAMODE = 00, 01 or 10.

00: GPIO connected to VINM (valid also in PGA mode for filtering)

01: Reserved

1x: Inverting input not externally connected. These configurations are valid only when OPAMODE = 10 (PGA mode)

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

Bits 5:4 PGA_GAIN[5:4] : Operational amplifier Programmable amplifier gain value

Bits 3:2 OPAMODE[3:2] : Operational amplifier PGA mode

Bit 1 OPALPM : Operational amplifier Low Power Mode

The operational amplifier must be disable to change this configuration.

Bit 0 OPAEN : Operational amplifier Enable

18.5.2 OPAMP1 offset 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[12:8]Res.Res.Res.TRIMOFFSETN[4:0]
rwrwrwrwrwrwrwrwrwrw

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

Bits 12:8 TRIMOFFSETP[12:8] : 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

18.5.3 OPAMP1 offset trimming register in low-power mode (OPAMP1_LPOTR)

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.TRIMLPOFFSETP[12:8]Res.Res.Res.TRIMLPOFFSETN[4:0]
rwrwrwrwrwrwrwrwrwrw

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

Bits 12:8 TRIMLPOFFSETP[12:8] : Low-power mode trim for PMOS differential pairs

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

Bits 4:0 TRIMLPOFFSETN[4:0] : Low-power mode trim for NMOS differential pairs

18.5.4 OPAMP register map

Table 99. OPAMP register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00OPAMP1_CSROPA_RANGERes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CALOUTUSERTRIMCALSELCALONRes.VP_SELVM_SELRes.Res.Res.PGA_GAINOPAMODEOPALPMOPAEN
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.TRIM OFFSETN[4:0]
Reset value(1)(1)
0x08OPAMP1_LPOTRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TRIMLP OFFSETP[4:0]Res.Res.Res.TRIMLP OFFSETN[4:0]
Reset value(1)(1)

1. Factory trimmed values.

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