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 input

 
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 input
PostPosted: Wed Dec 10, 2008 11:50 am     Reply with quote

Hi,

1) Have seen some workable codes using comparator, but the code
does not include setting the input pin as analog like using
'setup_adc_ports(ALL_ANALOG)' in AD conversion. Why is this so ?

2) Have checked the ANSEL register using MPLAB SIM & all the bits
are '0'. Doesn't bits of ANSEL register='0' means digital i/o, then how can
it be an analog i/p of a comparator?

3) Referring to the following code, is a delay required before the
following statement ?:

Code:
if(C1OUT==1){


Thanks,
CJ
Code:

#include <16F690.h>

#FUSES NOWDT,INTRC_IO,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD,NOPUT,NOIESO,NOFCMEN

void main()
{
setup_comparator(CP1_A1_VR);
setup_vref(VREF_HIGH|15);

while(1)
{
if(C1OUT==1){
output_high(PIN_C6);}
else if(C1OUT==0)
{
output_low(PIN_C6);}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 1:01 pm     Reply with quote

Post your compiler version.
C0J



Joined: 05 Nov 2008
Posts: 25

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 1:28 pm     Reply with quote

Hi PCM,

Ver4.038

& also seen that C1VREN bit of VRCON register is not set to '1' when the function setup_vref(VREF_HIGH|15) is used.

Is it correct for me to say that C1VREN bit of VRCON register should be set to '1' when function setup_vref(VREF_HIGH|15) is used ?

as the data sheet states that C1VREN='1' is CVREF cct powered on and routed to C1VREF input of of Comparator C1



Code:
#include <16F690.h>

#FUSES NOWDT,INTRC_IO,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD,NOPUT,NOIESO,NOFCMEN

void main()
{
setup_comparator(CP1_A1_VR);
setup_vref(VREF_HIGH|15);

while(1)
{
if(C1OUT==1){
output_high(PIN_C6);}
else if(C1OUT==0)
{
output_low(PIN_C6);}

 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 3:03 pm     Reply with quote

Quote:
1) Have seen some workable codes using comparator, but the code
does not include setting the input pin as analog like using
'setup_adc_ports(ALL_ANALOG)' in AD conversion. Why is this so ?

The 16F690 data sheet does not explicitly state that ANSEL register must
be set to analog inputs for the comparator pins. It sort of implies it,
in two statements given in "gray boxes" in the data sheet.

Quote:
2) Have checked the ANSEL register using MPLAB SIM & all the bits
are '0'. Doesn't bits of ANSEL register='0' means digital i/o, then how can
it be an analog i/p of a comparator?

The CCS generated ASM code for setup_comparator() does not set the
pins to analog. They are put into digital i/o mode by the CCS start-up
code, and left in that state. If you want to configure the pins as analog
inputs, you can use the setup_adc_ports() function to do it. Refer to the
16F690.H file for a list of constants used with that function.


Quote:
3) Referring to the following code, is a delay required before the
following statement ?:

Code:
if(C1OUT==1){

I don't think so.


Quote:

Also seen that C1VREN bit of VRCON register is not set to '1' when the function setup_vref(VREF_HIGH|15) is used.

There are two constants in the 16F690.H file that can be OR'ed into the
setup_vref() statement, to control the C1VREN and C2VREN bits:
Code:

#define VREF_COMP1  0x80
#define VREF_COMP2  0x40
C0J



Joined: 05 Nov 2008
Posts: 25

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 3:33 pm     Reply with quote

Thank u again PCM
Smile
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