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

PIC18F25K20 comparator not working - PLS HELP

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



Joined: 08 Oct 2009
Posts: 73

View user's profile Send private message

PIC18F25K20 comparator not working - PLS HELP
PostPosted: Fri Jul 26, 2013 6:36 pm     Reply with quote

Hi,

Compiles 5.010 but tested also with 4.141
PIC18F25K20

Comparator is not working. COUT is always high or if inverted always low. If it is low fires interrupts as should be. I printed all registers after setup, seems to be set correctly. No idea anymore, may be somebody can take a look on it, I maybe something missing. Part of the listing
Code:

        setup_adc(ADC_CLOCK_DIV_4 | ADC_TAD_MUL_16); 
   setup_adc_ports(sAN12|sAN11|sAN9|sAN8|sAN2|sAN1|VSS_VDD);
        setup_comparator(CP1_A1_VREF | CP1_FAST)
   setup_vref(VREF_HIGH | 15 );
   C1RSEL=1; // set manually - compiler not set it ( ???)

.....
.....

   while(1)
   {
      if(C1OUT)   
         printf(bputc,"\n\rLOW"); 
      else   
         printf(bputc,"\n\rHIGH"); 
   }

always the result is high or low (if inverted)

I add the following lines in order to check what is set by compiler in registers


Code:

   printf(bputc,"\n\r\n\rCM1CON0 C1ON:%x", C1ON);
   printf(bputc,"\n\rCM1CON0 C1OUT:%x", C1OUT);
   printf(bputc,"\n\rCM1CON0 C1OE:%x", C1OE);
   printf(bputc,"\n\rCM1CON0 C1POL:%x", C1POL);
   printf(bputc,"\n\rCM1CON0 C1SP:%x", C1SP);
   printf(bputc,"\n\rCM1CON0 C1R:%x", C1R);
   printf(bputc,"\n\rCM1CON0 C1CH1:%x", C1CH1);
   printf(bputc,"\n\rCM1CON0 C1CH0:%x\n\r", C1CH0);

   printf(bputc,"\n\rCVRCON CVREN:%x", CVREN);
   printf(bputc,"\n\rCVRCON CVROE:%x", CVROE);
   printf(bputc,"\n\rCVRCON CVRR:%x", CVRR);
   printf(bputc,"\n\rCVRCON CVRSS:%x", CVRSS);
   printf(bputc,"\n\rCVRCON CVR3:%x", CVR3);
   printf(bputc,"\n\rCVRCON CVR2:%x", CVR2);
   printf(bputc,"\n\rCVRCON CVR1:%x", CVR1);
   printf(bputc,"\n\rCVRCON CVR0:%x\n\r", CVR0);
   
   printf(bputc,"\n\rCM2CON1 C1RSEL:%x\n\r", C1RSEL);   
 
   printf(bputc,"\n\rCVRCON2 FVREN:%x\n\r", FVREN);
   printf(bputc,"\n\rCVRCON2 FVRST:%x", FVRST);
 
   printf(bputc,"\n\rLATA:%x\n\r", LATA);
   printf(bputc,"\n\rANS1:%x\n\r", ANS1);

   while(1);

an the results from terminal printout are here:


CM1CON0 C1ON:01
CM1CON0 C1OUT:00
CM1CON0 C1OE:01
CM1CON0 C1POL:00
CM1CON0 C1SP:01
CM1CON0 C1R:01
CM1CON0 C1CH1:00
CM1CON0 C1CH0:01

CVRCON CVREN:01
CVRCON CVROE:00
CVRCON CVRR:00
CVRCON CVRSS:00
CVRCON CVR3:01
CVRCON CVR2:01
CVRCON CVR1:01
CVRCON CVR0:01

CM2CON1 C1RSEL:01

CVRCON2 FVREN:00

CVRCON2 FVRST:00
LATA:23

ANS1:01


I tested with voltage provided to the C12IN1- pin from 0 up to VDD (3.3 V)
always the same result.

Any idea what can I do??

Thank you in advance
Best Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 12:04 am     Reply with quote

Quote:
setup_comparator(CP1_A1_VREF | CP1_FAST);

The line above produces this ASM code in the .LST file (for both vs 4.141 and vs. 5.010):
Code:

.................... setup_comparator(CP1_A1_VREF | CP1_FAST); 
0026:  BCF    CM2CON1.C1RSEL
0028:  BCF    CM2CON1.C2RSEL

002A:  CLRF   CM2CON0

002C:  MOVLW  8D
002E:  MOVWF  CM1CON0

0030:  MOVF   TRISA,W
0032:  IORLW  01   <== Bug. Sets pin A0 to an input. Should be pin A1.
0034:  MOVWF  TRISA

0036:  MOVF   TRISB,W
0038:  IORLW  01   <== Bug.  Pin B0 is not used by comparator.
003A:  MOVWF  TRISB


To fix the TRISA bug, insert the line in bold below, after the setup_comparator() line:
Quote:

setup_comparator(CP1_A1_VREF | CP1_FAST);
output_float(PIN_A1);
setup_vref(VREF_HIGH | 15 );
C1RSEL=1;
micro_debugger



Joined: 08 Oct 2009
Posts: 73

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 2:42 am     Reply with quote

Thank you so much !!!!!
You save me a lot of time!!!
I'm going to test it and keep you informed.
Warmest regards
micro_debugger



Joined: 08 Oct 2009
Posts: 73

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 2:47 am     Reply with quote

Tested

Working perfectly.
Thank you again.
Warmest regards
micro_debugger



Joined: 08 Oct 2009
Posts: 73

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 5:54 pm     Reply with quote

Hi,

This is the final working version, I made also a small mistake in the register C1RSEL my own definition.
Code:

setup_comparator(CP1_A1_VREF | CP1_FAST | CP1_INVERT);
output_float(PIN_A1);
setup_vref(VREF_HIGH | 15);
C1RSEL=1;

Compiler is not setting up the C1RSEL to 1, and always keep it as 0, just FYI
BR
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 6:08 pm     Reply with quote

Make sure to submit those bugs to CCS support via their email address so they get fixes in upcoming versions
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