Skip to main content
waaizkhan
Associate II
March 20, 2025
Solved

Comparator with PWM

  • March 20, 2025
  • 1 reply
  • 1234 views

In my setup, I’m using Comparator 6 (COMP6) on the STM32G474 microcontroller. The non-inverting input of the comparator is connected to a burden resistor from a current transformer, which measures current flow. The inverting input is tied to a fixed 1.5V reference created by a voltage divider. The goal is for the comparator to disable all PWM signals (generated by HRTIM TimerA) when the burden resistor voltage reaches 1.5V, indicating an overcurrent condition (e.g., 10A).

Issue: Despite the burden resistor voltage hitting 1.5V at 10A, the comparator does not trigger, and the PWM remains active.

Best answer by waaizkhan

Thanks Andrew , 
I initially misinterpreted the readings, but after carefully rechecking, I confirmed that the current does not exceed 10A.
and my comparator work perfectly.

1 reply

Andrew Neil
Super User
March 20, 2025

You expect the PWM to be disabled when this voltage reaches 1.5V ?

So, if the voltage is only reaching 1.4V, then you would not expect the PWM to stop.

Your system seems to be operating as expected ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waaizkhan
waaizkhanAuthor
Associate II
March 21, 2025

Apologies for the typing mistake—it should be 1.5V, not 1.4V. Even when the current exceeds 1.5V, the PWM does not disable.

Andrew Neil
Super User
March 21, 2025

@waaizkhan wrote:

Even when the current exceeds 1.5V, the PWM does not disable.


Have you confirmed if that's because the Comparator doesn't trigger, or your code doesn't act on the trigger?

Have you used the debugger to see what's going on?

and/or added printfs or similar?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.