|
|
View previous topic :: View next topic |
Author |
Message |
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
Setup comparator on PIC16F636 |
Posted: Wed Dec 06, 2006 3:09 am |
|
|
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
|
|
Posted: Wed Dec 06, 2006 5:02 am |
|
|
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
|
|
Posted: Wed Dec 06, 2006 5:23 am |
|
|
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
|
|
Posted: Wed Dec 06, 2006 6:00 am |
|
|
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
|
|
Posted: Wed Dec 06, 2006 6:48 am |
|
|
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
|
|
Posted: Wed Dec 06, 2006 11:00 am |
|
|
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 |
|
|
|
|
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
|