View previous topic :: View next topic |
Author |
Message |
C0J
Joined: 05 Nov 2008 Posts: 25
|
comparator not working (16F690) |
Posted: Thu Nov 20, 2008 1:46 pm |
|
|
Hi,
referring to the code below:
after reading the data speed of 16F690, the following are my understanding for comparator (pls correct me if i am wrong, thanks)
1) is it correct for me to say that i am using comparator2 and C2- is A1, C2+ is VR based on the statement "setup_comparator(CP2_A1_VR);"?
2) i am confused on the followings (extracted from datasheet)
Input Condition CxPOL CxOUT
a) CxVIN- > CxVIN+ 0 0
b) CxVIN- < CxVIN+ 0 1
c) CxVIN- > CxVIN+ 1 1
c) CxVIN- < CxVIN+ 1 0
looking at a), c) the input condition is the same but CxOUT is different, how do i interpret this ?
3) i have setup the compartor based on mode2( if i do not interpret it wrongly) but the statement "output_high(PIN_C0);" is executed when RA1 is from 0 to 0.6V & "output_low(PIN_C0);" is executed when RA1 is >~0.6V
Is there anything wrong with the code ?
Thanks,
CJ
Code: | #include <16F690.h>
#FUSES NOWDT,INTRC_IO,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD,NOPUT,NOIESO,NOFCMEN
#use delay(clock=8000000)
void main()
{
setup_comparator(CP2_A1_VR);
setup_vref(VREF_HIGH|15); //set vref as 3.6V
while(1)
{
delay_ms(500);
if(C2OUT==1)
{
output_high(PIN_C0);
}
else if(C2OUT==0)
{
output_low(PIN_C0);}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 20, 2008 3:25 pm |
|
|
Pin C0 is used by comparator C2. It's the C2IN+ pin. I wouldn't use
it for an LED. |
|
|
C0J
Joined: 05 Nov 2008 Posts: 25
|
|
Posted: Fri Nov 21, 2008 12:22 am |
|
|
Thanks PCM,
May I know where to get that info ? (So that I can read it up to have a better understanding on comparator).
Thanks again,
CJ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 21, 2008 1:08 am |
|
|
Quote: | May I know where to get that info ? |
It's in the PIC data sheet, in two places:
1. In the pin diagrams.
2. In the Pinout Summary tables.
These are both near the front of the data sheet.
To get the data sheet, go to the Microchip Data Sheet Finder page.
(Bookmark this page).
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2046
Select your PIC in the drop-down box. Then wait for the page to load.
The link for data sheet will be on the upper left side. |
|
|
|