OPAMP operation basics

The operational amplifier is an analog device that amplifies differential input signals (difference between inverting and non-inverting input) to give a resulting output voltage. Figure 1 Basic OPAMP representation illustrates the circuit representation of an OPAMP.
The ideal operational amplifier must have the following properties:
- Infinite amplification gain (open loop)
- Infinite input impedance
- Zero output impedance
- Infinite frequency bandwidth
- Zero input offset voltage
If the OPAMP has infinite gain, then the differential signal at input must be zero (in closed loop linear operation)- because the gain is infinite and output voltage is at finite level:
Uout = Uin x Gain = 0 x ∞ = finite voltage.
This basic idea (input voltage at zero) simplifies the OPAMP usage in real applications.
Real operational amplifier requires properties close to ideal requirements:
- High amplification gain (open loop) – for example: gain = 1,000,000 (120 dB)
- High input impedance – for example Zin = 100 MΩ
- Low output impedance – for example Zout = 10 Ω
- High frequency bandwidth – for example f-3 dB = fGBW = 10 MHz (for closed gain loop = 1)
- Low input offset voltage – for example Uoffset = 1 mV
OPAMP in practice – operation example
The ideal OPAMP has infinite gain. This means that if output needs to be set at a defined value then the input differential signal should be zero. The output signal should influence input differential voltage through negative feedback to balance the operation point. Figure 2 Inverting amplifier by using OPAMP below illustrates an example of an inverting amplifier setup:

A voltage is applied to Uin on the negative OPAMP input of Udiff through R1 resistor. This increase on the negative input causes a voltage decrease on Uout – due to the OPAMP gain ratio. Then the Uout voltage causes a decrease of the voltage on the negative OPAMP input through R2 resistor – this is the negative feedback set up on Uin. The feedback then stabilizes the differential voltage of the OPAMP input (Udiff) to reach zero and the Uout voltage reaches the required level (Uout = Udiff x ∞). If Udiff is zero then Uout voltage is calculated based on Uin using the following formulas:
- Udiff = 0 V (zero differential voltage)
Idiff = 0 A (zero current on the OPAMP input – because input impedance is ∞)
- I1 = Uin / R1 (current through R1, because Udiff = 0 and non-inverting OPAMP input is grounded)
I2 = Uout / R2 (current through R2, because Udiff = 0 and non-inverting OPAMP input is grounded)
- I2 = -I1 (because Idiff = 0)
- Uout / R2 = -Uin / R1
Uout = -Uin . (R2/R1)
The final circuit gain is calculated as a ratio between the output and the input voltage (gain = Uout/Uin). Final gain is given here only by external resistors values of R1 and R2 and is not depend on the OPAMP (if its gain is ∞).
Brief description of the OPAMP in the STM32G4 Series
The STM32G4 Series integrates OPAMPs that can be used in high speed analog to digital applications as analog signal pre-conditioning for ADC data sampling or as standalone amplifiers. Main application areas are:
- Motor control applications (current and voltage sensing)
- Digital switched-mode power supplies – DSMPS (current and voltage sensing, control loop)
- Light control applications (current and voltage sensing)
- Analog sensors measurement applications (thermometers, low signals measurement and so on)
- Medical applications (analog signals sensing/amplification)
- Audio applications (signal amplification)
- General purpose analog signal usage (oscillators, comparators and so on).
OPAMP parameters
Basic performance parameters of the STM32G4 Series operational amplifier are:
- Input voltage offset: approx. +/- 3 mV (after built-in calibration of offset)
- Bandwidth: approx. 13 MHz
- Slew rate:
- Normal mode: approx. 6.5 V/µs
- High speed mode: approx. 45 V/µs.
- Output saturated voltage: less than 100 mV (rai-to-rail)
- Gains:
- Positive: +1, +2, +4, +8, +16, +32, +64
- Negative: -1, -3, -7, -15, -31, -63
- Typical gain error: 2%.
- Open loop gain: ~ 95 dB
- Wakeup time: 3 µs.
OPAMP connections
The OPAMP in STM32G4 Series works across several operational configurations. The OPAMP configuration is defined using a set of analog multiplexers which interconnect the OPAMP input and output terminals through an internal resistor network. Final gain of this programmable gain amplifier (PGA) is defined by the resistor ratios on the feedback.
Figure 3 Internal OPAMP connections in STM32G4 Series illustrates the basic schematic of the OPAMP integrated in STM32G4 Series.

Simple examples of OPAMP configuration
Inverting amplifier
Basic schematic of a general inverting amplifier is illustrated in Figure 4 Inverting amplifier using an OPAMP.

To implement this setup using the STM32G4 Series, configure the multiplexers as shown in Figure 5 Inverting amplifier implementation by OPAMP in the STM32G4 Series. Connect the analog input signal to VINM0 OPAMP pin. Connect the reference ground to VINP0 OPAMP pin. The internal feedback resistors define the gain. The gain is set in the OPAMP configuration registers to: -1, -3, -7, -15, -31 and -63.

External resistors can be used to implement the same inverting amplifier design. The use of external resistors offers a greater choice of gain values together with more accurate amplification values with the use of taylored resistors. Figure 6 Inverting amplifier by using external resistors illustrates the implementation of an inverting amplifier using external resistors.

Non-inverting amplifier
Basic schematic of non inverting amplifier is illustrated in Figure 7 Non- inverting amplifier using an OPAMP.

To implement this setup using the STM32G4 Series, configure the multiplexers as shown in Figure 8 Non-inverting amplifier implementation by OPAMP in the STM32G4 Series. Connect the analog input signal to VINP0 OPAMP pin. The internal feedback resistors define the gain. The gain is set in the OPAMP configuration registers to: 2, 4, 8, 16, 32, 64.

External resistors are used to implement the same non-inverting amplifier design. The use of external resistors offers a greater choice of gain values together with more accurate amplification values with the use of taylored resistors. Figure 9 Non-inverting amplifier by using external resistors illustrates this implementation of non-inverting amplifier using external resistors (with possible filter implementation given by external capacitor C in parallel to R2 resistor).

Configuration of the OPAMP – multiplexers with internal gain settings
Input multiplexer setting options
OPAMP1_CSR):VM_SEL[1:0]– controls the multiplexer on the OPAMP inverting input as illustrated in Figure 10 Multiplexer on inverting OPAMP input below:- 00: inverting input connected to external pin VINM0
- 01: inverting input connected to external pin VINM1
- 10: inverting input connected to feedback resistors (PGA mode)
- 11: inverting input connected to the OPAMP output (Follower mode).
Figure 10. Multiplexer on inverting OPAMP input 
VP_SEL[1:0]– controls the on the OPAMP non-inverting input as illustrated in Figure 11 Multiplexer on non-inverting OPAMP input below:- 00: non-inverting input connected to external pin VINP0
- 01: non-inverting input connected to external pin VINP1
- 10: non-inverting input connected to external pin VINP2
- 11: in dependency from given OPAMP configuration:
- For OPAMP2: non-inverting input connected to external pin VINP3.
- For other OPAMPs: non-inverting input connected internally to DACx_CHy:OPAMP1: DAC3_CH1, OPAMP3: DAC3_CH2, OPAMP4: DAC4_CH1, OPAMP5: DAC4_CH2, OPAMP6: DAC3_CH1.
Figure 11. Multiplexer on non-inverting OPAMP input 
- OPAINTOEN (OPAMP internal output enable) – controls the multiplexer on the OPAMP output (see Figure 12 Multiplexer on OPAMP output).
- 0: OPAMP output connected to the external pin VOUT
- 1: OPAMP output connected internally to an ADC channel and disconnected from the external VOUT pin (the VOUT pin is free and available to be used for another purpose) .
Figure 12. Multiplexer on OPAMP output 
The multiplexer of the inverting OPAMP input offers an additional interconnection option (besides the options described above) and allows access to additional OPAMP modes. The additional connections are controlled by the PGA_GAIN[4:0] gain setting bits:
PGA_GAIN[4:0]= 0 to 5: Standard configuration for simple non-inverting amplifier setting – multiplexer set accordingVM_SEL[1:0]. See Figure 10 Multiplexer on inverting OPAMP inputPGA_GAIN[4:0] = 8 to 13: Implementation of an inverting amplifier – one terminal of the internal resistor is connected to the external pin VINM0 through the multiplexer. The OPAMP inverting input is kept connected to the feedback resistor which defines the gain, see Figure 13 Inverting amplifier or non-inverting amplifier with external bias. The non-inverting amplifier implementation also uses this mode. The difference is that the input signal is connected on the non-inverting OPAMP terminal. The advantage is the possibility of bias level setting by the external pin VINM0. An external bias voltage control is a nice feature in practical applications, to adjust the reference voltage level for the input signal in particular if the ground signal is shifted or the ground is noisy.Figure 13. Inverting amplifier or non-inverting amplifier with external bias 
PGA_GAIN[4:0] = 16 to 21: The inverting OPAMP input is connected accordingVM_SEL[1:0]setting and also connected to externalVINM0pin. This mode is useful for adding an external capacitor as low pass filter for non-inverting amplifier. See Figure 14 Non-inverting amplifier with external filter.Figure 14. Non-inverting amplifier with external filter 
PGA_GAIN[4:0] = 24 to 29: Implementation of an inverting amplifier or non-inverting amplifier with the possibility of connecting an external filtering capacitor on VINM1 pin.This mode is very similar to the case of thePGA_GAIN[4:0] = 8 to 13(case 2 described above) but there is the additional option to connect an external capacitor for filtering on pin VINM1. See Figure 15 Inverting amplifier or non-inverting amplifier with external bias and with external filter.Figure 15. Inverting amplifier or non-inverting amplifier with external bias and with external filter 
Frequency compensation of OPAMP
In many practical applications, the bandwidth needs to be limited of the designed amplifier. For example, suppressing high frequency noise or removing glitches in transient states.
The OPAMP implements the amplifier with low pass filtering by using an external capacitor. This capacitor is used in internal or external gain setting modes for both inverting and non-inverting configurations:
- Frequency compensation implementation for non-inverting PGA amplifier is in Figure 14 Non-inverting amplifier with external filter.
- Frequency compensation implementation for inverting PGA amplifier is in Figure 15 Inverting amplifier or non-inverting amplifier with external bias and with external filter.
- Frequency compensation for gain set with external components is implemented by adding a capacitor to the feedback resistor R2 – see Figure 9 Non-inverting amplifier by using external resistors and Figure 6 Inverting amplifier by using external resistors.
The -3 dB low pass bandwidth is given by the formula:
fLP = 1/ (2.π.R2.C)
where: R2 is the feedback resistor and C is the external capacitor connected in parallel to the R2 resistor.
DAC output to OPAMP input – offset/bias voltage setting
On the non-inverting OPAMP input, it is possible to connect the output from internal DAC (Digital to Analog Converter) by configuring the multiplexer on the non-inverting input (bits VP_SEL[1:0] = 3). See Figure 11 Multiplexer on non-inverting OPAMP input .
The internal DAC generates a fixed voltage on the non-inverting OPAMP input and sets a bias voltage for the inverting amplifier implementation. Basic schematic for inverting amplifier implementation (see Figure 5 Inverting amplifier implementation by OPAMP in the STM32G4 Series and Figure 6 Inverting amplifier by using external resistors) uses the non-inverting OPAMP input connected to ground – reference voltage for the input signal is ground. However, if the input signal ground reference is shifted, for example to VDD/2, then the bias voltage is set to VDD/2 by the DAC. This bias voltage (virtual signal ground) shift allows the application to use higher gains (because the OPAMP does not then amplify the offset). It is very useful to amplify small modulated signals on a relatively high DC offset voltage (this offset voltage is set by DAC on the non-inverting OPAMP input).
DAC output to OPAMP input – internal DAC output redirection to external pin
The DAC output connected to the non-inverting OPAMP input (described in DAC output to OPAMP input – offset/bias voltage setting) is always the internal DAC output with no connection to any output pin: either DAC3 or DAC4. Internal DACs have no direct output to external pins and are available to be used internally as COMP or OPAMP inputs. The internal DAC output signal is “redirected” to the output pin through the OPAMP. The multiplexer on the non-inverting input is set as input from the internal DAC output (option VP_SEL[1:0] = 3). The OPAMP is then set in the follower mode. The OPAMP output pin (VOUT) is now the signal from the internal DAC output. Alternatively, the OPAMP is set to some higher gain mode (instead of follower mode where the gain = 1) to amplify the signal from internal DAC.
The internal DAC redirection to the output pin through OPAMP takes advantage of the internal DAC speed to generate high-speed analog output waveforms. Internal DACs are much faster (15 Msps data rate) than the external DACs (with 1 Msps data rate). The final analog waveform is limited by combination of the OPAMP bandwidth and the internal DAC bandwidth.
The Figure 16 Internal DAC redirected through OPAMP to output pin – update steps and Figure 17 Internal DAC redirected through OPAMP to output pin – OPAMP slew rate are screenshot examples where the internal DAC is redirected to OPAMP output pin. The DAC generates full scale (2.048 V) saw tooth signal with 15 Msps data rate (step = 40 LSBs) and the OPAMP is set to follower mode. The output analog signal is measured on the pin – OPAMP output.


OPAMP internal output only to ADC
In many applications, the OPAMP is only used as an analog signal amplifier for the ADC sampling. In this case, it may only be necessary to connect the OPAMP to the ADC using the internal signal. There is no need to put the OPAMP output to an external pin.
The external OPAMP output pin is then available for another purpose. The collateral advantage is that in a noisy environment the external pin cannot “receive” any external noise and therefore does not disturb the ADC measurement.
The OPAMP output redirection to the internal ADC is only performed by configuring the output multiplexer (OPAINTOEN = 1). See Figure 12 Multiplexer on OPAMP output.
OPAMP offset trimming
The offset parameter is the basic parameter for operational amplifiers. Ideally, it should be close to zero, it is good to minimize it as much as possible. The OPAMP in STM32G4 Series features a programmable hardware offset voltage calibration/trimming. The OPAMP contains trimming value registers for offset correction. The reference manual documents the recommended procedure for offset calibration. There is no need to add any additional external components to perform such trimming. Offsets are calibrated in the final application design with no influence of the rest of application. By default, the offset trimming value is programmed by ST at the time of production.
Please refer to the datasheet for the factory test conditions.