cancel
Showing results for 
Search instead for 
Did you mean: 

Can ADC readings be taken on the same pin used as a comparator input at the same time?

KHarb.1
Senior II

I am using COMP2 and COMP6 to compare external voltages to internal DAC values. I need to calibrate the internal DAC values by taking ADC measurements from the input pins. Can the ADC measurements be taken with the COMPx peripheral active?   If so, how would I set up the IOC file and init code?

1 REPLY 1
RomainR.
ST Employee

Hi @KHarb.1 

Yes, it is possible to use the same analog GPIO with both ADC and Comparator enabled on STM32G4.
This is a common use case and the analog path is common for both peripherals, allowing them to share the same pin.

GPIO in analog mode: Set the pin to analog mode so the digital input buffer is disabled and
the analog pad connects to the internal analog multiplexers.
Independent routing: The ADC and COMP each have their own internal analog switch/mux to tap that pad.
They do not block each other, so both can be enabled and reading the same node concurrently.
Per-pin capability: You must choose a pin that is wired to both the ADC channel and to the desired COMP
input (positive or negative). This is device/part-number dependent—check your specific STM32G4 datasheet pin table.

In attached, you will find a CubeMx example showing this configuration:

  • PA3: in Analog Mode ADC1_IN4 and COMP2_INP (with DAC1_OUT2 used for COMP2_INM)
  • PB11: in Analog Mode ADC1_IN14 and COMP6_INP (with DAC2_OUT1 used for COMP6_INM)

While sharing is feasible, there are important considerations to follow:

Noise Interference: At high frequency, ADC switching noise can affect comparator operation.
This can lead to inaccurate results if both peripherals are active simultaneously.
Source impedance: The ADC uses a sampling capacitor that draws current during the sampling phase. Keep the source impedance ≤ 10 kΩ, or select a longer ADC sampling time, or buffer the signal with the internal OPAMP or an external op-amp.

Best regards,

Romain,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.