View previous topic :: View next topic |
Author |
Message |
delesan
Joined: 23 Jun 2010 Posts: 19
|
12F683 Analogue comparator |
Posted: Thu Jul 01, 2010 3:38 am |
|
|
Hi,
I would like to monitor the output when an analogue signal goes above 1V compared with the internal voltage reference.
Could anyone kindly provide the steps to configure/setup the analogue comparator on the 12F683. I would like to monitor the output of the comparator and use the internal voltage reference Vdd.
Example c-code programs is appreciated.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 01, 2010 12:49 pm |
|
|
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
|
ANALOGUE COMPARATOR ON 12F683 |
Posted: Fri Jul 02, 2010 2:03 am |
|
|
Many thanks for the example program code.
Will try it out now. |
|
|
delesan
Joined: 23 Jun 2010 Posts: 19
|
ANALOGUE COMPARATOR ON 12F683 |
Posted: Mon Jul 05, 2010 1:37 am |
|
|
Many thanks for the example source code. It worked. |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
|
Posted: Sat Mar 16, 2019 10:01 am |
|
|
Hi PCM Programmer
Thank you for the information and the example.
Brian |
|
|
|