|
|
View previous topic :: View next topic |
Author |
Message |
C0J
Joined: 05 Nov 2008 Posts: 25
|
comparator input |
Posted: Wed Dec 10, 2008 11:50 am |
|
|
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 ?:
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
|
|
Posted: Wed Dec 10, 2008 1:01 pm |
|
|
Post your compiler version. |
|
|
C0J
Joined: 05 Nov 2008 Posts: 25
|
|
Posted: Wed Dec 10, 2008 1:28 pm |
|
|
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
|
|
Posted: Wed Dec 10, 2008 3:03 pm |
|
|
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
|
|
Posted: Wed Dec 10, 2008 3:33 pm |
|
|
Thank u again PCM
|
|
|
|
|
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
|