cancel
Showing results for 
Search instead for 
Did you mean: 

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

Dai
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4

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

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?

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

Thank you for the answer.