View previous topic :: View next topic |
Author |
Message |
Trent___
Joined: 20 Jun 2007 Posts: 11 Location: London, UK
|
Comparator PIC16F636 |
Posted: Mon Feb 18, 2008 6:09 am |
|
|
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
|
|
Posted: Mon Feb 18, 2008 12:03 pm |
|
|
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
|
|
Posted: Tue Feb 19, 2008 11:57 am |
|
|
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
|
|
Posted: Thu Feb 21, 2008 9:25 am |
|
|
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
|
|
Posted: Thu Feb 21, 2008 11:54 am |
|
|
Post the #include, #fuses, and #use statements. i.e., Post a compilable
test program. |
|
|
Trent___
Joined: 20 Jun 2007 Posts: 11 Location: London, UK
|
|
Posted: Fri Feb 22, 2008 8:45 am |
|
|
#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
|
|
Posted: Fri Feb 22, 2008 11:25 am |
|
|
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
|
|
Posted: Fri Feb 22, 2008 11:32 am |
|
|
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. |
|
|
kolio
Joined: 06 Feb 2008 Posts: 26
|
|
Posted: Tue Feb 26, 2008 2:15 am |
|
|
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
wish you luck |
|
|
Trent___
Joined: 20 Jun 2007 Posts: 11 Location: London, UK
|
|
Posted: Tue Feb 26, 2008 4:46 am |
|
|
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. |
|
|
|