cancel
Showing results for 
Search instead for 
Did you mean: 

VREF as comparator input fails but equivalent DAC input works just fine. Why?

KHarb.1
Senior

I have a signal biased around the VREF output (2.048V) of an STM32G4. I have a comparator (COMP7) peripheral configured to compare this signal to VREF and it fails. If I set the second input of the comparator to DAC2 and set the DAC2 output value to max (0xFFF), the comparison works. Both should have the same behavior, but using the VREF comparison directly doesn't work. What could I be doing wrong? 

15 REPLIES 15

Your problem is probably confusion about VREF vs Vrefint. Vrefint is independent internal voltage (typicaly 1.2V with calibration information saved in flash), but VREF (used by DAC, ADC etc) is reference voltage generated by VREFBUF or connected externaly to VREF+ pin or connected to AVDD. 

I'm using CubeIDE and I see no options for vrefint for DACs and COMPs. I only see this option for ADCs...and I'm not using them. What registers can I check on to see if this feature got configured by accident?

Per above, I'm using the VREF+ output successfully for external biasing. DAC1 OUT2 has externally exposed output and works normally. DAC2 OUT1 seems to work normally with COMP7 and COMP6.    DAC3 OUT2 is used for COMP2 and COMP4 and acts unpredictably with COMP4.  (COMP2 can't be observed.)

Analog: No opamps. No ADCs running....I'm using CubeIDE and none of the settings are enabled. Just COMPs and DACs.

Caps: Are you saying I need caps on each COMP input...? Where is this documented? I have nothing in place presently and see proper behavior with COMP3, COMP6 and COMP7.  The input signals are AC ~40khz and can be seen properly biased around VREF+.

Take a look on figure 168 in reference manual:
https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
There you can see that comparator negative input can be GPIO, DAC and Vrefint (!) and its fractions (buffered by "scaler"). This Vrefint have nothing to do with VREF used as DAC reference. If you use DAC referenced by 2.048V from VREF (called VREFBUF) with data 0xFFF, then comparator see on its negative input about 2.048V. And it is close to your measure signal. But when you connect comparator input to "Vrefint", then comparator see about 1.2V threshold and it is far from your signal level.

There is no way how to connect comparator to VREF (2.048V) directly. Only way is through DAC. Therefore your claim:


@KHarb.1 wrote:

I have a comparator (COMP7) peripheral configured to compare this signal to VREF...


must be wrong. You are probably confused by two different voltage references..

Just think: if there is some EMI/stray in spikes, you get the comp switched , but "see" nothing, even you use a scope.

Thats why i would use a cap at every input, at least for testing.

Same/similar can happen on chip, think about 3V switching connections on MHz-speed, just micro-meters away from the comp-input...(I am more surprised about such some-mV-analog circuit working at all in this surrounding switching environment. 🙂 )

Just an example, from my "tests" :

checking the resolution and offset of such fancy 3Msps 16-bit ADC, as on H7 cpus,

simple first test : zero, gnd on input. And got some 80..100 counts , sometimes. The wire gnd - input was about 100mm long, so maybe (always present) cell phone activity ... can this happen here ? so i made a soldered short wire there - suddenly 0...8 counts from zero. Thats about, what it should be, from data. 

If you feel a post has answered your question, please click "Accept as Solution".

Ahhh. Internal Vref is Vrefint and not VREF. Thanks.

Now I just need to figure out why COMP4 and DAC3 are misbehaving....