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

Setup comparator on PIC16F636

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



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

Setup comparator on PIC16F636
PostPosted: Wed Dec 06, 2006 3:09 am     Reply with quote

Hello,
I'm trying to use the two comparator of the PIC16F636, to detecte voltage over 400mV

i use the next function to initiate de PIC comparator reference :
setup_vref (VREF_LOW | 2);

but i don't know how to configure the
setup_comparator (mode);

i don't anderstand the next modes :
A0_A3_A1_A2
A0_A2_A1_A2
NC_NC_A1_A2
NC_NC_NC_NC
A0_VR_A1_VR
A3_VR_A2_VR
A0_A2_A1_A2_OUT_ON_A3_A4
A3_A2_A1_A2


Wich configuration i need to use the inputs of the comparators without external voltage reference??

Thanks for your help.
Ttelmah
Guest







PostPosted: Wed Dec 06, 2006 5:02 am     Reply with quote

Start by looking at the data sheet...
The 'modes' correspond exactly to the modes in the sheet.
Key is that there are a total of four inputs, and each pair can be an external pin, or the Vref. In the CCS defines, the pins are defined by name (hence A0, A1 etc.), and the Vref, is referred to by 'VR'.
There are a number of modes using the Vref, with the option for software only 'output', or hardware output.
For example:
A0_VR_C0_VR

Implies RA0 feeding into comparator 1, with Vref on the other input pin. RC0 feeding comparator 2, with Vref on its other input, and 'software only' outputs.

Best Wishes
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Wed Dec 06, 2006 5:23 am     Reply with quote

ok, so to have the following configuration :
first comparator:
- Analog input connected to RA1
- reference define by software
- Software output

second comparator:
- Analog input connected to RC1
- reference define by software
- Software output

i have to do :
setup_comparator (A1_VR_C1_VR );

??
Ttelmah
Guest







PostPosted: Wed Dec 06, 2006 6:00 am     Reply with quote

Yes.
If the define file does not have this mode (the ones you list miss this one, but modern compilers do have this), then add:
#define A1_VR_C1_VR 0x10FF02

The define is identical to the one for A0_VR_C0_VR, with '8' subtracted, which changes bit 3 in the register configuration, toggling the input select switch to use the other inputs.
If your compiler is so old, that it doesn't have this mode, I'd be quite worried whether the code is going to work. The list was correct in V3.226, which was one of the first compilers supporting this chip...

Best Wishes
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

PostPosted: Wed Dec 06, 2006 6:48 am     Reply with quote

Ttelmah wrote:

#define A1_VR_C1_VR 0x10FF02


Can someone please explain how you get from A1_VR_C1_VR, which are the settings stored in the CMCON0 register at address 19h, to 0x10FF02?
Ttelmah
Guest







PostPosted: Wed Dec 06, 2006 11:00 am     Reply with quote

The defintions are in the .h file for the processor. Each gives a text word, and a number corresponding to the settings. Now the command sets the values of several registers from the number. The last two characters, correspond to the value sent to CMCON0 register. The next couple of bytes control the setup of timer1, configuring whether it is fed from the C2OUT control, and/or whether this signal is routed to the output pin. The top byte feeds CMCON1.

Best Wishes
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