cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Comparator/DAC on STM32G473

Moritz1
Associate III

Hi,

I've been struggling with using the STM32G473's internal comparator and DAC for a few days now.

Comparator
I use the internal COMP1. For the negative Input I selected the DAC3-CH1 and for the positive input I selected the Pin PA1. PA1 is configured in analog mode. The Output signal is triggering an Interrupt via EXTI Line 21. The Hysterese is set to 0 for the moment.

DAC3
The DAC3 is one of the "internal only" DACs. So it unbuffered and can go down until 0V, but I cant measure its voltage output. The VREF+ is connected to an external 2,048V voltage reference. VDDA is connected to a filtered 3,3V source, VSSA is connected to the same Ground as the Controller VSS Pins.

What I want to reach with this setting is: In Software I set a threashold via DAC3, and if the input voltage at pin PA1 reaches/overshoot the threashold I want to get the Interrupt.

Basically this works. But I observe unexplainable differences in the comparator switching threshold (see picture 2).
For example: I set the DAC output to 400mV and increment the voltage at PA1 slowly beginning vom 0V. I see that the comparator always switches at a voltage of 100mV. Where does the 300mV offset comes from?

The observed offset changed with higher threasholds. In picture 2 you can see the characteristic. The blue line is the threashold set via the DAC (so its the voltage I expect switching of the Comparator) and the blue line shows at which voltage at PA1 the comparator has switched if I raise the voltage beginning from zero.

 

I have reproduced this behavior on two Microcontrollers. So I think there is no component defect.

Does anyone has an idea what the problem could be here? Why does the comparator alwasy switches "too early" at voltages up to 300mV below the threashold?

2 REPLIES 2
KHarb.1
Senior

Hi, yes I made progress and found the problem.

In my case there was an aditional ADC measurement at Pin PA1 active.
So the Sample&Hold capacitor of the STM internal ADC has shifted the Signal for COMP IN+ at each time of conversion. It seems that the S&H capacitor is loaded to any voltage if it gets connected to the signal. This leads to a level shift up of the signal and to a switching of the comparator.
If I deactivate the ADC conversions everything works fine.