|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
16F88 Comparator Problem |
Posted: Wed May 18, 2005 8:31 pm |
|
|
Has anyone experienced a problem reading C1OUT from CMCON on a 16F88? I can see C1OUT on RA3 but I cannot read it in code.
#include <16F88.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOMCLR
#use delay(clock=20000000)
#Use FAST_IO(A)
#Use FAST_IO(B)
#BYTE VRCONREG = 0x9D
#BYTE CMCON = 0x9C
main() {
int8 Comp;
SET_TRIS_A(0x03);
SET_TRIS_B(0x04);
OUTPUT_HIGH(PIN_B1);
DELAY_MS(1000);
OUTPUT_LOW(PIN_B1);
VRCONREG=0xE2;
CMCON = 6;
while(TRUE)
{ Comp=CMCON;
if(BIT_TEST(Comp,6)){
Delay_us(100);
if(BIT_TEST(Comp,6))
OUTPUT_HIGH(PIN_B3);}
if(!BIT_TEST(Comp,6)){
Delay_us(100);
if(!BIT_TEST(Comp,6))
OUTPUT_LOW(PIN_B3);}
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 19, 2005 12:10 am |
|
|
It looks like you're trying to use the internal Vref with the comparators
in mode 6. However, according to the data sheet, the internal Vref is
only used in mode 2. I can confirm this. I ran the following test
program and it only worked in mode 2.
I used a 16F88 on a PicDem2-Plus board, and I set the trimpot for
an output voltage of 2.5v. When I ran the program below, and
moved the trimpot wheel back and forth very slightly, I got this output:
Quote: |
00
00
00
01
01
01
00
00
00
01
01
01
etc.
|
Code: | #include <16F88.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use RS232(baud=9600, xmit=PIN_B5, rcv=PIN_B2, ERRORS)
void main()
{
setup_oscillator(OSC_8MHZ);
setup_comparator(A0_VR_A1_VR); // Comparator mode 2
setup_vref(VREF_LOW | 12); // Set internal Vref = Vdd/2
while(1)
{
printf("%x\n\r", C1OUT); // Display C1 output every 1/2 second
delay_ms(500);
}
} |
|
|
|
|
|
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
|