Jump to content
Sign in to follow this  
cviewengineer

Simple Comparator?

Recommended Posts

I'm trying to get the comparator to work...I can get the ADC to work using pin RA0, and know I'm trying to get the comparator to work for that pin...my dev board has a pot connected to that pin.

 

Here is my code for the comparator:

 

#include <system.h>

#pragma CLOCK_FREQ 18432000

#pragma DATA _CONFIG1, 0b0010001111110011

 

void main(){

//RA0 is the pot connection

trisa = 0x01;

ansel = 0x01;

 

cm1con0 = 0b11010100;

vrcon = 0b11101111;

 

trisd = 0x00; //configure port B

portd = 0x00; //clear port B

 

while(1){

portd.0 = 1;

delay_ms(500);

portd.0 = 0;

delay_ms(500);

 

if(cm1con0.6 == 1){

portd.7 = 1;

delay_ms(500);

portd.7 = 0;

delay_ms(500);

portd.7 = 1;

delay_ms(500);

portd.7 = 0;

delay_ms(500);

}

 

}

}

 

portd is connected to LED's, so the first output to it are just to let me know the code is running, and the second out is for seeing if the compare feature is working...which it isn't

 

if I haven't provided enough information please let me know

 

any help is greatly appreciated

Share this post


Link to post
Share on other sites

You don't say what PIC type you are using.

 

Is the input C12IN0- (C1CH bits = 00) on pin RA1 and not RA0 ?

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

thanks for the reply...i'm using a 16F887, but i found the problem

 

it wasn't triggering on the voltage i wanted, and i finally figured out it was triggering on 0.6V...which is the fixed ref

 

i wasn't setting the proper bits in the cm2con1 register...i'm using comparator 1 so i just skipped over it thinking that its just a register for comparator 2, well it has 1 bit in it that controls comparator 1, that's what i missed

 

Regards,

 

-Aaron

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...