CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

comparator interrupt on PIC24EP

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kenho



Joined: 28 Jun 2013
Posts: 5

View user's profile Send private message

comparator interrupt on PIC24EP
PostPosted: Mon Jul 22, 2013 8:46 am     Reply with quote

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
kenho



Joined: 28 Jun 2013
Posts: 5

View user's profile Send private message

need to clear bit
PostPosted: Fri Jul 26, 2013 6:09 am     Reply with quote

I found that the 0xA8C bit 9 needs to be cleared by the programmer.

Progress continues!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group