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

PIC16F88 comparator

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



Joined: 12 May 2004
Posts: 54
Location: edinburgh, Scotland

View user's profile Send private message

PIC16F88 comparator
PostPosted: Wed Mar 08, 2006 3:03 pm     Reply with quote

I'm trying to use the PIC16F88's internal comparator, but so far, no joy.
Here's my code:

Code:
#include <16F88.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)

void main(void)
{
   setup_oscillator(OSC_8MHZ);

   setup_comparator(A0_VR_A1_VR);  // Comparator mode 2   
   setup_vref(0xC0 | 9);

   while(1){
      output_bit(PIN_B5,C1OUT);
      delay_ms(100);   
   }
}


it should be strikingly similar to the code here, but isn't identical. This is beacuse my version of PCM is about 2 years old (version 3.184), which is likely to be where my problem is.

If that isn't the case, what am I doing wrong? I've got the voltage reference oupoutting fine on A2, but no matter what my voltage on A0 is, C1OUT is always 0.
Any ideas?
-JBM
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 08, 2006 3:28 pm     Reply with quote

In your version of the compiler, the wrong address is used
for the CMCON register.

Here is the code for your version:
Code:

... setup_comparator(A0_VR_A1_VR);  // Comparator mode 2     
0028:  MOVLW  02
0029:  BCF    03.5     // Bank 0
002A:  MOVWF  1F       // Wrong address for CMCON

002B:  BSF    03.5     // Bank 1
002C:  MOVF   05,W     // Read TRISA
002D:  IORLW  03       // Set A0 and A1 as inputs
002E:  MOVWF  05       // Write to TRISA

002F:  MOVLW  06       // Do a short delay
0030:  MOVWF  77
0031:  DECFSZ 77,F
0032:  GOTO   031
0033:  NOP

0034:  BCF    03.5     // Bank 0
0035:  MOVF   1F,W     // Read the wrong register
0036:  BCF    0D.6     // Clear the CMIF bit


Here is the code for PCM vs. 3.245:
Code:

... setup_comparator(A0_VR_A1_VR);  // Comparator mode 2     
// Note:  Bank 1 is already selected.
0027:  MOVLW  02
0028:  MOVWF  1C       // Set CMCON (0x9c) = 0x02

0029:  MOVF   05,W     // Read TRISA
002A:  IORLW  03
002B:  MOVWF  05       // Set A0 and A1 = inputws

002C:  MOVLW  06       // Do a short delay   
002D:  MOVWF  77
002E:  DECFSZ 77,F
002F:  GOTO   02E
0030:  NOP

0031:  MOVF   1C,W     // Read CMCON
0032:  BCF    03.5     // Bank 0
0033:  BCF    0D.6     // Clear the CMIF bit

You could fix this by writing to CMCON directly with a line of code.
Define the address with a #byte statement.
JBM



Joined: 12 May 2004
Posts: 54
Location: edinburgh, Scotland

View user's profile Send private message

PostPosted: Wed Mar 08, 2006 3:30 pm     Reply with quote

PCM, you never cease to amaze me.

Thanks a million.
-JBM
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