Ok thank you. Basically i am facing issue with comparator interrupt code for dspic33ev family controllers. I have two versions of the software can you please tell me which is better or correct. At some times one code seems to be working and some other times the other code is working.
uchar8_t g_dummy_u8;
uchar8_t hall_a;
uchar8_t hall_b;
uchar8_t hall_c;
void __attribute__((__interrupt__,__no_auto_psv__)) _CMP1Interrupt(void)
{
IFS1bits.CMPIF = 0; // clear the interrupt flag
if(CMSTATbits.C1EVT== 1) // Clear comparator 3 event bit)
{
CM1CONbits.CEVT = 0; // Clear comparator 3 event bit
hall_a = CMSTATbits.C1OUT;
g_dummy_u16 = CM1CONbits.COUT;
}
if(CMSTATbits.C2EVT == 1)
{
CM2CONbits.CEVT = 0;
hall_b = CMSTATbits.C2OUT;
g_dummy_u16 = CM2CONbits.COUT;
}
if( CMSTATbits.C3EVT == 1) // Clear comparator 3 event bit)
{
CM3CONbits.CEVT = 0; // Clear comparator 3 event bit
hall_c = CMSTATbits.C3OUT;
g_dummy_u16 = CM3CONbits.COUT;
}
}
because same data is available in both control register and status register.
I am mainly confused with the statement
"The Comparator Interrupt Flag (CMPIF) bit (IFS1<2>) is set when the synchronized output value of any of the comparators changes, with respect to the last read value". What is this last read value? I am also attaching the comparator data sheet. Please help.
A previous dsPIC33 family reference manual illustrates the comparator signal processing as below
Reading CMCON latches the present state, I guess also reading CMSTAT if present in the respective processor. Means operation is similar to input change notification of digital input ports.
So which version of the interrupts i can use or both are same. The issue i am facing is i should get a single interrupt when there is cross over but what i observe is a kind of continuous toggling during the cross over time. I observe this by toggling a port and i observe this in only one comparator. Not sure what is the issue.