20. Operational amplifiers (OPAMP)

20.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 non-inverting 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.

20.2 OPAMP main features

20.3 OPAMP functional description

The OPAMP has several modes.

When the OPAMP is 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 low-power mode or the normal mode. In functional mode the inputs and output of the OPAMP are connected as described in the Section 20.3.3: Signal routing .

20.3.1 OPAMP reset and clocks

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

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.

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

20.3.3 Signal routing

The routing for the operational amplifier pins is determined by OPAMP_CSR register.

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

Table 96. Operational amplifier possible connections

SignalPinInternalcomment
OPAMP1_VINMPA1 or dedicated pinOPAMP1_OUT or PGAcontrolled by bits OPAMODE and VM_SEL.
OPAMP1_VINPPA0DAC1_OUT1controlled by bit VP_SEL.
OPAMP1_VOUTPA3ADC1_IN8The pin is connected when the OPAMP is enabled. The ADC input is controlled by ADC.

20.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 which 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 hereafter.

Starting from the default value of OPAMP_CSR, and the default state of GPIOx_MODER, configure bit OPA_RANGE according 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 122. 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) connected to an external OPAMP circuit. Inside the STM32, there are GPIO and DAC_OUT pins. The OPAMP is represented by a triangle with '+' and '-' inputs. The non-inverting input (+) is connected to the DAC_OUT pin. The inverting input (-) is connected to a feedback network consisting of a resistor and a capacitor in parallel, which is then connected to a GPIO pin. The output of the OPAMP is connected to an ADC input and also to a feedback network consisting of a variable resistor and a capacitor in parallel, which is then connected to another GPIO pin. The diagram is labeled MS35324V1.
Circuit diagram of an operational amplifier (OPAMP) in standalone mode with external gain setting. The diagram shows an STM32 microcontroller (dashed box) connected to an external OPAMP circuit. Inside the STM32, there are GPIO and DAC_OUT pins. The OPAMP is represented by a triangle with '+' and '-' inputs. The non-inverting input (+) is connected to the DAC_OUT pin. The inverting input (-) is connected to a feedback network consisting of a resistor and a capacitor in parallel, which is then connected to a GPIO pin. The output of the OPAMP is connected to an ADC input and also to a feedback network consisting of a variable resistor and a capacitor in parallel, which is then connected to another GPIO pin. The diagram is labeled MS35324V1.

Follower configuration mode

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

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 123. 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 through 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 connection is also shown.

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 via 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 connection, labeled 'Always connected to OPAMP output (can be used during debug)', is also shown at the bottom left. 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 through 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 connection is also shown.

Programmable Gain Amplifier mode

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

As soon as the OPAEN bit is set, the signal on pin OPAMP_VINP is amplified by the selected gain and visible on pin OPAMP_VOUT.

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

Figure 124. 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 within an STM32 microcontroller.

The diagram illustrates the internal configuration of an OPAMP within an STM32 microcontroller for PGA mode. The OPAMP is represented by a triangle with '+' (non-inverting) and '-' (inverting) inputs. The non-inverting input (+) is connected to a multiplexer that selects between a GPIO pin and a DAC_OUT pin. The inverting input (-) is connected to a multiplexer that selects a feedback path. This feedback path comes from a resistive divider network connected between the OPAMP output and ground. The divider includes a variable resistor to set the gain (x2, x4, x8, or x16). The OPAMP output is connected to an internal ADC and also routed to an external pin labeled 'Always connected to OPAMP output (can be used during debug)'. The entire circuit is enclosed in a dashed box labeled 'STM32'. The diagram is identified by the reference MS35326V1.

Circuit diagram of an operational amplifier (OPAMP) in Programmable Gain Amplifier (PGA) mode within an STM32 microcontroller.

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

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 purpose (see datasheet for the value of resistors used in the PGA resistor network).

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

Circuit diagram of an operational amplifier (OPAMP) in Programmable Gain Amplifier (PGA) mode with external filtering. The diagram shows an STM32 microcontroller connected to an OPAMP. The non-inverting input (+) is connected to a DAC_OUT pin. The inverting input (-) is connected to a GPIO pin and is part of a feedback loop. The output (VOUT) is connected to an ADC pin and also to a feedback network consisting of a capacitor and a resistor. The feedback network is connected back to the inverting input. A dashed line indicates that the feedback network is 'Equivalent to' an internal PGA resistor network. A note indicates that the gain depends on the cut-off frequency of the external filtering. The diagram is labeled MS35327V1.
Circuit diagram of an operational amplifier (OPAMP) in Programmable Gain Amplifier (PGA) mode with external filtering. The diagram shows an STM32 microcontroller connected to an OPAMP. The non-inverting input (+) is connected to a DAC_OUT pin. The inverting input (-) is connected to a GPIO pin and is part of a feedback loop. The output (VOUT) is connected to an ADC pin and also to a feedback network consisting of a capacitor and a resistor. The feedback network is connected back to the inverting input. A dashed line indicates that the feedback network is 'Equivalent to' an internal PGA resistor network. A note indicates that the gain depends on the cut-off frequency of the external filtering. The diagram is labeled MS35327V1.

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

20.3.5 Calibration

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

The operational amplifier offset can be trimmed by the user. Specific registers allow to have 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 allows to reduce 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.

The user is able to switch from 'factory' values to 'user' trimmed values using the USERTRIM bit in the OPAMP_CSR register. This bit is reset at startup and so the 'factory' value are 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 bit CALOUT will reflect 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 (with a maximum stabilization time remaining 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 will have to be repeated 4 times. For the first iteration select
    • – Normal mode, offset cal high (N differential pair)
    The above calibration mode correspond to OPALPM=0 and CALSEL=0 in the OPAMP_CSR register.
  4. 4. Increment TRIMOFFSETN[4:0] in OPAMP_OTR starting from 00000b until CALOUT changes to 1 in OPAMP_CSR.

Note: CALOUT will switch 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 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 \( \mu A \) .

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

20.4 OPAMP low-power modes

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

ModeDescription
SleepNo effect.
Low-power runNo effect.
Low-power 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

20.5 OPAMP registers

20.5.1 OPAMP1 control/status register (OPAMP1_CSR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
OPA_RANGERes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
rw

1514131211109876543210
CAL OUTUSER TRIMCAL SELCALONRes.VP_SELVM_SELRes.Res.PGA_GAINOPAMODEOPA LPMOPAEN
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 : 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 : Operational amplifier Programmable amplifier gain value

Bits 3:2 OPAMODE : 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

20.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.TRIMOFFSETPRes.Res.Res.TRIMOFFSETN
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

20.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.TRIMLPOFFSETPRes.Res.Res.TRIMLPOFFSETN
rwrwrwrwrwrwrwrwrwrw

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

Bits 12:8 TRIMLPOFFSETP[4:0] : 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

20.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.TRIML OFFSETP[4:0]Res.Res.Res.TRIML OFFSETN[4:0]
Reset value(1)(1)

1. Factory trimmed values.

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