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 setup

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



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

Comparator setup
PostPosted: Fri Oct 22, 2010 1:45 pm     Reply with quote

Compiler: PCWH 4.099
Chip: PIC18F26J50

I want to set up comparator 1 to use A0 and A3 as its inputs, internal output, no interrupt, and turn comparator 2 off. Seems pretty simple. But looking at the header file for my chip, I'm not understanding what the setup_comparator function is doing. The header shows this:
Code:
////////////////////////////////////////////////////////////////// COMP
// Comparator Variables: C1OUT, C2OUT
// Constants used in setup_comparator() are:
#define A0_A3_A1_A3  0xfff04
#define A0_A3_A1_A2_OUT_ON_A4_A5  0xfcf03
#define A0_A3_A1_A3_OUT_ON_A4_A5  0xbcf05
#define NC_NC_NC_NC  0x0ff07
#define A0_A3_A1_A2  0xfff02
#define A0_A3_NC_NC_OUT_ON_A4  0x9ef01
#define A0_VR_A1_VR 0x3ff06
#define A3_VR_A2_VR 0xcff0e
#define CP1_INVERT  0x0000010
#define CP2_INVERT  0x0000020

#bit C1OUT = 0xfb4.6     
#bit C2OUT = 0xfb4.7     

which looks like just a subset of the possible configurations. None match what I want. Those last two lines concern me, too... those are CCP2CON bits! C1OUT and C2OUT would be 0xF70.0 and 0xF70.1, methinks. And since the CMxCON registers are 8 bits, I looked at the .LST file to see what it's doing with three bytes. I figured I could build my own constant to pass to setup_comparator() to do what I want.

BUT... when I look at the .LST file, the compiler seems to be manipulating things not involved with the comparators:
Code:
....................     setup_comparator(A0_A3_A1_A2);
286C:  MOVLW  02
286E:  MOVWF  FB4     // CCP2CON??
2870:  MOVF   F92,W
2872:  IORLW  0F
2874:  MOVWF  F92
2876:  MOVLW  27
2878:  MOVWF  00
287A:  DECFSZ 00,F
287C:  BRA    287A
287E:  BRA    2880
2880:  MOVF   FB4,W
2882:  BCF    FA1.6

This doesn't look right to me. I can see where the first two bytes of the setup_comparator() parameter are used to set the TRISA bits for inputs and outputs, that's fine (if the second byte is anything but 0xFF, there is an ANDLW before the byte is written to TRISA). But nowhere do I see CM1CON/CM2CON getting set, and it seems to be writing to CCP2CON instead -- with a value that does not match what should be written to CMxCON anyway, which in my case would be 0x80.

This just doesn't look right at all. Is comparator support broken for this chip, or am I mis-reading the output?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 22, 2010 2:17 pm     Reply with quote

Here are the 18F26J50.h settings for Comparator 1, for vs. 4.112.
I'm not sure where they get this F5, F6 stuff from. It looks to me like
they copied the pin names from the 18F87J90 or 18F87J50, etc.
Code:

//Pick one constant for COMP1
#define CP1_VREF_F6     0x83
#define CP1_F5_F6       0x80
#define CP1_VREF_VREF   0x87
#define CP1_F5_VREF     0x84
//Optionally OR with one or both of the following
#define CP1_OUT_ON_F2 0x40
#define CP1_INVERT    0x20
#define CP1_INT_H_TO_L 0x10
#define CP1_INT_L_TO_H 0x08

#bit C1OUT = 0xfa6.0
#bit C2OUT = 0xfa6.1


A test compile with vs. 4.112 for the 18F26J50 gives this:
Code:

.... setup_comparator(CP1_F5_F6 | CP1_INT_L_TO_H); 
0022:  MOVLW  88
0024:  MOVWF  FD2  // CM1CON
0026:  CLRF   FD1  // CM2CON


If you want to make your version work, this post gives examples of
writing directly to the comparator registers:
http://www.ccsinfo.com/forum/viewtopic.php?t=43155&start=20
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Oct 22, 2010 2:29 pm     Reply with quote

OK... so comparator support is badly broken for the compiler version I have. That makes more sense than what I was seeing. I figured I could just write to the config registers, but was just curious whether things were as bad as they looked.

Now I'll need to go look at the PWM setup, since that's not working at the moment either. I probably should upgrade, but giving them more money every time I find something busted seems like encouraging bad behavior!

Thanks for your time in looking at this -- I appreciate it.
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