Skip to main content
Dai
Associate
June 8, 2023
Solved

How to accurately determine whether comparator interrupt was generated by rising or falling in the interrupt routine

  • June 8, 2023
  • 4 replies
  • 1700 views

I use comparator(COMP7) on STM32F303VB as

・Non-inverting input: PC1 (ADC)

・Inverted input: DAC2 output

・Comparator interrupt: rising/falling edge trigger

I checked the COMP7OUT bit, but it seems that this bit is "comparator output at the time the bit is checked" and not the rising or falling edge at the time of interrupt generation.

Is there a way to check whether an interrupt occurred on the rising edge or on the falling edge?

This topic has been closed for replies.
Best answer by waclawek.jan

Comparators in 'F3 don't have an inherent mechanism for interrupts, they simply use the EXTI, and that in turn does not have a distinct register to remember rising or falling edge (that's the same as with genuine external interrupts upon changes on pins).

One way to tackle this is to enable only one of the edges, so that you then know the interrupt was from that edge; and when it happens, disable this edge and enable the other (with care taken for signal which has already flipped back).

The other way is to avoid EXTI, and use the feed from comparator output to a timer's input channel, and there use the possibility to feed the signal also to the "neighbouring" channel with opposite polarity (as used with "PWM input" in RM).

JW

4 replies

waclawek.jan
waclawek.janBest answer
Super User
June 8, 2023

Comparators in 'F3 don't have an inherent mechanism for interrupts, they simply use the EXTI, and that in turn does not have a distinct register to remember rising or falling edge (that's the same as with genuine external interrupts upon changes on pins).

One way to tackle this is to enable only one of the edges, so that you then know the interrupt was from that edge; and when it happens, disable this edge and enable the other (with care taken for signal which has already flipped back).

The other way is to avoid EXTI, and use the feed from comparator output to a timer's input channel, and there use the possibility to feed the signal also to the "neighbouring" channel with opposite polarity (as used with "PWM input" in RM).

JW

Dai
DaiAuthor
Associate
June 9, 2023

Thank you for the reply.

About second way, 

does it mean that if the output from the comparator is a rising edge, capture/compare interrupt of the timer channel (CH1) occurs, and if it is the falling edge, capture/compare interrupt of the channel (CH2) with opposite polarity occurs?

Does RM mean Reference manual?

waclawek.jan
Super User
June 9, 2023

Yes, you then have a capture and overcapture flag and the"timestamp" in CCRx, individually for either polarity. This is at the cost of "spending" a timer.

> Does RM mean Reference manual?

Yes.

JW

Dai
DaiAuthor
Associate
June 13, 2023

Thank you for the answer.