Skip to main content
Visitor II
May 7, 2024
Solved

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

  • May 7, 2024
  • 2 replies
  • 3651 views

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? 

    This topic has been closed for replies.
    Best answer by Michal Dudka

    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..

    2 replies

    Super User
    May 7, 2024

    How you set the comp input selector ?

     

    AScha3_0-1715062210308.png

     

    KHarb.1Author
    Visitor II
    May 7, 2024

    I used CubeIDE to change the settings.

    I'm using the externally exposed VREF, so I know it's working that way. Are there extra init commands for using an internal VREF with a comparator?

    Super User
    May 7, 2024

    >I used CubeIDE to change the settings.

    ok.

    >Are there extra init commands

    No.. Did you try to select other comp inputs , like vref/2 ?

    Graduate II
    May 22, 2024

    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. 

    KHarb.1Author
    Visitor II
    May 22, 2024

    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.)

    Graduate II
    May 22, 2024

    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..