kenho
Joined: 28 Jun 2013 Posts: 5
|
comparator interrupt on PIC24EP |
Posted: Mon Jul 22, 2013 8:46 am |
|
|
Hi All
In the following code the event does not get cleared after the ISR so the interrupt only works once. I observe the two inputs on the comparator witth an Oscope and verified the difference goes positive, returns negative and goes positive agian on the hardware.
Shouldn't the compiler take care of this?
The E in the output below is the event flag on the comparator CM2CON register and the F is the status register.
Any suggestions?
Code: | #include <24EP512GU810.h>
#include <stdlib.h>
#include <math.h>
#fuses NOWDT,PUT64,NOBROWNOUT,ICSP1,NOJTAG,NODEBUG,NOAWRT,NOAPROTECT
#fuses NOWRT,NOPROTECT,PR_PLL,NOIESO,NOPR,CKSNOFSM
#PIN_SELECT U1RX = pin_D1
#PIN_SELECT U1TX = pin_D2
#bit CM2CON = 0xA8C.9
#bit CMSTAT = 0xA80.9
#bit IFS1 = 0x802.2
#use delay(clock=58960000)
#use fixed_io(D_outputs=PIN_D2)
#use rs232(baud=115200,xmit=PIN_D2,rcv=PIN_D1,stream=DB)
char Wake = 'N';
#int_comp
void comp()
{
Wake = 'Y';
}
void main()
{
clear_interrupt(INT_COMP); // IMPORTANT: Always clear before
ENABLE_INTERRUPTS(INT_COMP);
ENABLE_INTERRUPTS(INTR_GLOBAL);
setup_uart(115200, DB);
setup_oscillator(OSC_INTERNAL);
SETUP_COMPARATOR_FILTER(2,COMP_FILTER_DISABLE);
SETUP_COMPARATOR(2,CXIN2_CXIN1 | COMP_INTR);
while(1)
{
if(Wake == 'Y')
{
fprintf(DB,"WAKE\r\n");
Wake = 'N';
}
if(IFS1) fprintf(DB,"C");
if(CMSTAT) fprintf(DB,"F"); // read only event occured on comparator 2
if(CM2CON) fprintf(DB,"E"); //
delay_ms(100);
}
}
|
Using 4.132
Output on Terraterm from RS232 port:
WAKE
FEFEFEFEFEFEFE |
|