2025-12-06
4:28 PM
- last edited on
2025-12-12
2:26 AM
by
Maxime_MARCHETT
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?
2025-12-08 12:30 AM
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:
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.