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

comparator not working (16F690)

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



Joined: 05 Nov 2008
Posts: 25

View user's profile Send private message

comparator not working (16F690)
PostPosted: Thu Nov 20, 2008 1:46 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 20, 2008 3:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 21, 2008 12:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 21, 2008 1:08 am     Reply with quote

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.
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