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 CCS Technical Support

12F683 Analogue comparator

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 12:49 pm     Reply with quote

Here is a demo program for the comparator on the 12F683.
Put a 10K trimpot on pin A1, so that you can vary the voltage
from 0 to 5v on that pin. Put an LED on pin A5 (with series
resistor). When you adjust the trimpot to put out a voltage
greater than 1v, the LED will go on. If the voltage is less than 1v,
the LED will go off.
Code:

 #include <12F683.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)

#define LED_PIN  PIN_A5

//===================================
void main()
{
output_low(LED_PIN);  // Turn off the LED initially

// Comparator input voltage is on pin A1, with internal
// Vref, and inverted Comparator output.  The inversion
// is done so that when the input voltage is greater
// than Vref, the comparator output will go high.  When
// the input is below Vref, the output will go low.
setup_comparator(A1_VR | COMP_INVERT); 

setup_vref(VREF_LOW | 5); // Vref = 5v * (5/24) = 1.04v

// Wait for the Comparator mode change delay, and the Vref
// settling time. (spec = 10 us, so use 20us to be safe).
delay_us(20);               

// Continuously poll the Comparator output status bit.
// If it's high, it means the input voltage is greater
// than the Vref voltage.  In that case, turn on the LED.
// If not, turn the LED off.
while(1)
  {
   if(C1OUT == 1) 
      output_high(LED_PIN); 
   else
      output_low(LED_PIN);
   
   delay_ms(100);   // Debounce time
  }
}
delesan



Joined: 23 Jun 2010
Posts: 19

View user's profile Send private message

ANALOGUE COMPARATOR ON 12F683
PostPosted: Fri Jul 02, 2010 2:03 am     Reply with quote

Many thanks for the example program code.

Will try it out now.
delesan



Joined: 23 Jun 2010
Posts: 19

View user's profile Send private message

ANALOGUE COMPARATOR ON 12F683
PostPosted: Mon Jul 05, 2010 1:37 am     Reply with quote

Many thanks for the example source code. It worked.
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Sat Mar 16, 2019 10:01 am     Reply with quote

Hi PCM Programmer

Thank you for the information and the example.

Brian
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