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 CCS Technical Support

problem with comparator interrupt

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



Joined: 09 Aug 2007
Posts: 4

View user's profile Send private message

problem with comparator interrupt
PostPosted: Fri Aug 17, 2007 2:12 am     Reply with quote

Hi, Im using a 16f616's comparator to compare two analog signal. It's ok while I wrote it without interrupt function. The code I'm using to test is as following.

Code:
#include <16F616.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,IOSC8,NOPUT
#use delay(internal=8M)

void main() {
   byte value;

  setup_comparator(CP1_A1_A0);

while( TRUE ) {

   if(!C1OUT) //true when comparator output is high
   output_low(pin_a2);
   else
   output_high(pin_a2);
  }

}


Unfortunately, when I try to use the interrupt function. The code is as following.
Code:
#include <16F616.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,IOSC8,NOPUT
#use delay(internal=8M)

#INT_COMP
void isr()  {

   if(!C1OUT) //true when comparator output is high
   output_low(pin_a2);
   else
   output_high(pin_a2);

}

void main() {
   byte value;

  setup_comparator(CP1_A1_A0);

while( TRUE ) ;

}

The CCS version is 4.033.
Could someone give me some suggestion to overcome this problem?
Thanks a lot!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 17, 2007 11:39 am     Reply with quote

In main(), you need to enable INT_COMP interrupts, and also GLOBAL
interrupts -- after the setup_comparator() statement.

Inside the comparator isr, you need to read the CM1CON0 register, to
clear the "mis-match" condition that caused the comparator interrupt.
You also should do this in main(), before you enable the interrupts.
Use a #byte statement to define the address of CM1CON0, and then
just read the register into a variable.
tquantum



Joined: 09 Aug 2007
Posts: 4

View user's profile Send private message

PostPosted: Mon Aug 20, 2007 4:14 am     Reply with quote

Dear PCM,
According to your suggestion, I have add some code to the test program. The modified program is as following.
Code:
#include <16F616.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,IOSC8,NOPUT
#use delay(internal=8M)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BRGH1OK)

#byte CM1CON0 = 0x1A

#INT_COMP
void comp_isr()  {
   byte b;
   b = CM1CON0;
   if(!C1OUT) //true when comparator output is high
   output_low(pin_a2);
   else
   output_high(pin_a2);
}

void main() {
   byte value;

  setup_adc_ports(NO_ANALOGS);
  setup_comparator(CP1_A1_A0);

   enable_interrupts(INT_COMP);
   enable_interrupts(GLOBAL);

while( TRUE );

}

Unfortunately, it still has problem. Is there somthing wrong? Please help me, thanks! Is it possible that my complier is not the full version?
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