This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWN without output, comparor etc.

I'm just getting started with STM32, so I apologize for a possible trivial question.
I'm trying to find the optimal solution for this task

The internal comparator compares the voltage Uss to the reference
If the USS is smaller than the reference, the MCU must generate a 100us pulse on the GPIO .
The voltage may or may not rise during the pulse (comparator status is not deffined )
900us after the end of the pulse or 1ms after the start of the pulse it is necessary to find out the status of the comparator. If the USS still does not equal Uref, a pulse is generated again, if the equal pulse is not generated.
What is monitored is the number of pulses per second required for USS = Uref
Purely software any as

int pulsecounter=0;
while(1)
{
For (x=0;x<1000;x++)       // 1000 x 1ms = 1s
{
If (comparator==1 )
   {
     Set GPIO 1;
     Delay (100us);
     Set GPIO 0;     // in time 0-100us is not defined comparator status may by 0 may by 1
     pulsecounter=+;
    }
Delay (900us);
}
Printf(“Numbed of pules/sec %d\n", pulsecounter);
pulsecounter=0;
}

This is somewhat slavish and the MCU couldn't do anything else, so I'm looking for a more effective solution
I thought
A timer in PWM mode without output is used to generate an interrupt
PWM mode generates PWM with frequency 1000 Hz, 100us Hi 900us Low
Here I assume that there is an interrupt for each signal change?

The interrupt handler would then
- checked the comparator status
- set or did not set GPIO
- counted pulses

Questions
1. Does it generate interrupts at each level change, pwm without output?
2. Any better idea?

Thans you