2023-06-08 12:35 AM
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?
Solved! Go to Solution.
2023-06-08 01:50 AM
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
2023-06-08 01:50 AM
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
2023-06-08 07:41 PM
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?
2023-06-08 11:55 PM
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
2023-06-12 11:02 PM
Thank you for the answer.