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
TCC



Joined: 10 Feb 2010
Posts: 9

View user's profile Send private message

problem with comparator interrupt
PostPosted: Mon Apr 05, 2010 7:46 pm     Reply with quote

Hi,

I have problem triggering the comparator interrupt, when C1+/AN2 input is greater than C1-/AN0 input (this threshold is fixed at 0.207V). I expect the interrupt to trigger, it just don't happen. Anyone can help?
Code:

#include <16F1827.h>

#DEVICE ADC=10
#use delay(clock = 16000000)
#use rs232(baud=38400, xmit=PIN_B5, rcv=PIN_B2, PARITY=N, BITS=8, STOP=1)
#fuses INTRC_IO, NOWDT, BROWNOUT, NOMCLR

#BYTE PIR2        = 0x12
#BIT PIR2_C1IF    = PIR2.5
#BYTE PIE2        = 0x92
#BIT PIE2_C1IE    = PIE2.5   

//#INT_COMP
void comparator_isr()
{
printf("OverCurrent ");
overCurrent = TRUE;
}

void main() {

setup_adc_ports(sAN0 | sAN2);
setup_comparator(A0_A2_A1_A2);
//     enable_interrupts(INT_COMP);          
//     enable_interrupts(GLOBAL);          
PIE2_C1IE = 1;

while(1)
  {
   while(PIR2_C1IF)     // Wait for Comp. interrupt       
      {
       comparator_isr();             
       PIR2_C1IF = 0;     // Clear Comp. interrupt flag
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 05, 2010 8:21 pm     Reply with quote

What's your compiler version ?
TCC



Joined: 10 Feb 2010
Posts: 9

View user's profile Send private message

PostPosted: Mon Apr 05, 2010 10:38 pm     Reply with quote

I am using PCM V 4.106.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 4:01 am     Reply with quote

The CCS code for the 16F1827 for vs. 4.106 has a lot of bugs. The
first thing I noticed is that it's doing a software UART even though
the hardware pins are specified. So that's a bug. It may still be usable
but it's not preferable.

There are several bugs in the start-up code. Most of them are harmless.
They're writing to registers that don't need to be written to. But
presumably CCS intended to write to other registers. I didn't take the
time to guess what they really wanted to do.

The setup_comparator() function doesn't write to the Comparator
registers. Therefore, it doesn't work. To fix this, you need to
write directly to the comparator registers and set them up manually.
Define the registers with #byte statements and write to them in main().

Here's part of the .LST file for vs. 4.106, showing some of the bugs.
Code:

.................... void main() { 
0074:  CLRF   05
0075:  CLRF   04
0076:  MOVLW  1F
0077:  ANDWF  03,F

0078:  MOVLB  01
0079:  BCF    0D.5  // TRISB.5 = 0 (output)

007A:  MOVLB  02
007B:  BSF    0D.5  // LATB.5 = 1

007C:  MOVLW  00
007D:  MOVLB  03
007E:  MOVWF  0D    // ANSELB = 0x00 (all digital)

007F:  BCF    10.0  // *** Bug - register doesn't exist
0080:  BCF    10.1
0081:  BCF    10.2

0082:  MOVLB  01
0083:  BCF    1E.0  // ADCON1   Vref+ = AVdd
0084:  BCF    1E.1

0085:  MOVLB  03   
0086:  MOVWF  0C    // ANSELA = 0x00 (all digital)

0087:  MOVLB  01
0088:  CLRF   17    // WDTCON = 0  *** Bug: Not Needed

0089:  MOVLW  07
008A:  MOVWF  1C    // ADRESH = 7  *** Bug:  Not needed
.................... 
.................... setup_adc_ports(sAN0 | sAN2); 
008B:  MOVLW  00
008C:  MOVLB  03
008D:  MOVWF  0D   // ANSELB = 0x00 (all digital)

008E:  BCF    10.0  // *** Bug - register doesn't exist
008F:  BCF    10.1
0090:  BCF    10.2

0091:  MOVLB  01
0092:  BCF    1E.0 // ADCON1   Vref+ = AVdd
0093:  BCF    1E.1

0094:  MOVLW  05
0095:  MOVLB  03
0096:  MOVWF  0C   // ANSELA = 0x05

.................... setup_comparator(A0_A2_A1_A2); 

0097:  MOVLB  01 
0098:  CLRF   17   // WDTCON = 0x00  *** Bug: Not needed

0099:  MOVLW  03
009A:  MOVWF  1C   // ADRESH = 7  *** Bug:  Not needed

009B:  MOVF   05,W  // Read FSR0H  *** Bug:  Not needed
009C:  IORLW  30
009D:  MOVWF  05    // Write FSR0H  *** Bug:  Not needed

009E:  MOVLW  0D    // 10us delay loop
009F:  MOVWF  77
00A0:  DECFSZ 77,F
00A1:  GOTO   0A0

00A2:  MOVF   1C,W  // Read ADRESH  *** Bug: Not needed

00A3:  MOVLB  00
00A4:  BCF    12.5  // PIR2.C1IF = 0
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 5:06 am     Reply with quote

On the UART, this can be fixed with device editor. CCS have the TX and RX selected as B1/B2, rather then B1/B5.... :(

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 06, 2010 1:35 pm     Reply with quote

I just now emailed CCS support about all these bugs.

Update:
CCS support says they will fix these problems in the next release,
which will be vs. 4.107.
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