Skip to main content
Visitor
October 2, 2026
Question

About comparators in STM32G474.

  • October 2, 2026
  • 3 replies
  • 16 views

I am enquiring about comparators in STM32G474.

For COMP4, it says that the INP can be connected to PB0 and INM can be connected to DAC1_CH1. But when PB0=1.65V and PA4(which is the output of DAC1_CH1)=3.15V , the VALUE bit in COMP_CSR is 1, which should be 0. I measured in from nucleo board and they are exactly the values I expected. And VALUE bit remains 1 when I changed the DAC1_CH1 to other values.

It makes me wonder if there is an issue in the manual. It seems that DAC1 is not really connected to COMP4.

Thank you!

3 replies

mƎALLEm
ST Technical Moderator
October 2, 2026

Hello ​@xiaoyu wang and welcome to the ST community,

Please attach your project you’ve used for this test.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Visitor
October 2, 2026

The code related to the COMP4 and DAC1 configuration is as follows:

/* overcurrent protection configuration

* current limiting, max 3A (3.5A max for inductor,3A max for ADC) */

//Enable DAC1 clock

RCC->AHB2ENR |= (uint32_t) 0x10000U;

//DAC_out=V_ref*DOR/4096=1.65(offset)+1.5(3A in reality,gain for IN240A1=20,3*(25e-3)*20=1.5)=3.15,V_ref=3.3V

DAC1->DHR12R1 = (uint32_t)(12902.0f/3.3f);

//DAC enable

DAC1->CR |= (uint32_t)0x1U;

for(volatile int i=0; i<10000; i++);

//COMP4 configuration

RCC->APB2ENR |= (uint32_t)0x1U;

/* Select DAC1 CH1 as negative input

* Non-inverting input selection (PB0 over-current protection) for positive input

* inverted output(make enable bit in gate driver work)

* Enable comparator */

COMP4->CSR = (uint32_t)0x8051U;

waclawek.jan
Super User
October 2, 2026

Measuring PA4 shows the expected voltage?

Read out and check/post the relevant COMP and GPIO registers’ content.

JW