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 support@ccsinfo.com

16F88 Comparator Problem

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








16F88 Comparator Problem
PostPosted: Wed May 18, 2005 8:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 19, 2005 12:10 am     Reply with quote

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);
  }
   
}
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