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 PIC16F636

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



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

Comparator PIC16F636
PostPosted: Mon Feb 18, 2008 6:09 am     Reply with quote

Hi,

I am having issues with the Comparator Module.

The internal voltage reference appears to be a no go.

My register value's are;

#byte CMCON0_reg=getenv("SFR:CMCON0")
#byte VRCON_reg=getenv("SFR:VRCON")

set_tris_a( 0xfb ); // was fe
VRCON_reg= 0xEC;
CMCON0_reg = 0x12;

From the hardware side;

Vdd = 5V

C1in- = 1k in series with 47pF to Vdd ( standard intergrator circuit)
C1in+ = should be internal Ref as set in CMCON0 and VRCON

C1out read from bit 6 of CMCON0 in firmware.

The Cout is stuck at VDD or VSS depending on whether CINV is set or cleared.

I also tried to use the CCS helper functions, but get no joy from:

setup_comparator(A1_VR_C1_VR|C1OUT);
setup_vref(VREF_HIGH|7);


Have I missed anything obvious, I have worked with module previously on other targets with no issue.

I am on version 4.064

Any suggestions ?

thanks

trent.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 12:03 pm     Reply with quote

C1OUT is a bit address. It shouldn't be OR'ed with other parameters.
From the 16F636.h file:
Code:
#bit C1OUT = 0x19.6


Post a small test program that will test if your comparator
and vref setup is working. Also post your external hardware
components and connections. For example, if you have a
trimpot connected to the comparator input, so that you can
apply a variable voltage to it, then post a description of the
circuit.

The test program should be small, but compilable with no errors.
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Tue Feb 19, 2008 11:57 am     Reply with quote

Thanks for noticing the #bit C1OUT.

Here is the test program;

setup_oscillator(OSC_4MHZ);
set_tris_a( 0xfb ); // was fe
setup_comparator(A1_VR_C1_VR;
setup_vref(VREF_HIGH|7);

while(1)
{
if(C1OUT==TRUE)
{

output_high(PIN_C0);
}
if(C1OUT==FALSE)
{

output_low(PIN_C0);
}
}

The hardware set up;

C1in- is connect to the RSSI out on the AFE on the PIC16F639. The the 16F636 and the MCP2030 on the one bit of Silicon.

The RSSI is switch from 0V to 5V. The C1OUT should mimic this for all values of VREF.


Thanks again.
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 21, 2008 9:25 am     Reply with quote

sorry, that wouldn't have compiled.

Try;

setup_oscillator(OSC_4MHZ);
set_tris_a( 0xfb ); // was fe
setup_comparator(A1_VR_C1_VR);
setup_vref(VREF_HIGH|7);

while(TRUE)
{
if(C1OUT==TRUE)
{

output_high(PIN_C0);
}
if(C1OUT==FALSE)
{

output_low(PIN_C0);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 21, 2008 11:54 am     Reply with quote

Post the #include, #fuses, and #use statements. i.e., Post a compilable
test program.
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 22, 2008 8:45 am     Reply with quote

#include <16F639.h>
#device ICD=TRUE
#device ansi

#FUSES NOWDT //No Watch Dog Timer

#FUSES INTRC_IO
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOIESO
#FUSES NOPUT //No Power Up Timer
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOWURE //Wake-up and continue
//#FUSES BROWNOUT_NOSL //No brownout reset TBD - enable
#FUSES NOBROWNOUT // No brownout reset

#use delay(clock=4000000)

setup_oscillator(OSC_4MHZ);
set_tris_a( 0xfb ); // was fe
setup_comparator(A1_VR_C1_VR);
setup_vref(VREF_HIGH|7);

while(TRUE)
{
if(C1OUT==TRUE)
{

output_high(PIN_C0);
}
if(C1OUT==FALSE)
{

output_low(PIN_C0);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 11:25 am     Reply with quote

In your posts you sometimes refer to 16F636 and other times to 16F639.
You don't copy and paste your real program. Instead, you type in code.
For these reasons, I am giving up.
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 22, 2008 11:32 am     Reply with quote

The PIC16F639, is the PIC16F636 with the AFE added, so the Header files are the same.

That is my real program, less the stuff for other peripherals ect.

I didn't mean to waste anyone's time, so sorry if I did. Embarassed
kolio



Joined: 06 Feb 2008
Posts: 26

View user's profile Send private message

PostPosted: Tue Feb 26, 2008 2:15 am     Reply with quote

Buddy,
are you sure C0 is the proper way to track the comparator.
Check out what is the status of C0 in case of A1_VR_C1_VR = 0x10FF02 according 16F639.H !
The last byte '02' seems to turn C0 as an analog input.
You may use another pin for the output.
BTW in this chip the cost of Vref is very high - you have to sacrifice 2 pins C0 and C1 Crying or Very sad
wish you luck
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Tue Feb 26, 2008 4:46 am     Reply with quote

This was more as test code so I could see something happening externally.

I have tried with the helper functions in CCS and directly addressing the registers. C1OUT does not change regardless of the inputs to the comparator.

I am sure its something I am doing, thanks for your input.
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