Sophi
Joined: 14 Jun 2005 Posts: 64
|
setup_comparator(A0_VR_A1_VR); ? |
Posted: Sat Mar 18, 2006 6:42 pm |
|
|
Hi-
What do the modes of setup_comparator mean ? I see what setups I am allowed by the .h file but don't understand how the modes are defined (and where).
I have already searched this forum and the data sheet and the C ref manual and even google- I don't know where to find this out for myself, sorry.
I am using PICF877A. What I want is to have A/D on one pin- AN7. I want to use a comparator as an "interrupt on change". I think that the C manual says that Vref will default to A2 with setup_vref(VREF_HIGH|15); but the data sheet for PIC says Vref A2 is (-) and Vref A3 is (+) . And I see no instructions for how to choose. I have wired a switch to pin A3, it goes low when pushed. BTW I also need to keep at least 2 other PORTA pins digital I/Os. It seems that combinations of Analogs and digitals and comparators and vref are predefined as in what combos one can have. I saw this hint (thanks PCM) I think to deal with that.
[quote]
Use a #byte statement to define the address of a PIC register, and
then use a line of C code to set the register to the required value.
[\quote]
1. I need help (very much please) with the init of Vref and comparator setup, also any explanation. I understand how the comparator itself works.
2. Do I need to have an output pin on the comparator (A4 or A5) that I'd use as a condition to interrupt or can I do this with a vref and a switch only?
Here is what I've got so far.
Thanks in advance-
SophE
Code: | #include <16F877A.H>
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP // HS for 20 mHz, fuses specific to chip
#use delay(clock=20000000) // adjust for resonator frequency
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)// set up options
#include <LCD_16f877A.c>
#include <ltc1298_is.c>
#include <24128.c> // try removing
#use fast_io(c)
#use fast_io(a)
#use fast_io(b)
#include <stdlib.h>
#byte PORTB=6
// interrupts
#INT_COMP // COMPARATOR ISR
comp_isr()
{
lcd_putc("\fInterrupting!! ");
/*use modeXX for 2 comparator analog inputs. output on pin A5 and compare input A1 to A5???
1. select vref for comparator
2. put vref on one input pin and input switch to the other
3. when supply input is bigger than vref, comparator should trigger interrupt*/
}
}
main()
{
set_tris_a(0b01111000); // sets port a direction 0=out 1=in
set_tris_b(0x00); // set all PORTB to outputs-D/A for voice circuit
set_tris_c(0b00110111); // set all PORTC to outputs, pin_C1 for marry
init:
lcd_init();
set_ADC_channel(7); // set PORTA pin 7 for internal A/D
setup_comparator(A3_VR_A2_VR); // sets A2 as vref, A3 as input V???
setup_vref(VREF_HIGH|15); // sets internal vref V2 to > 3.6V
enable_interrupts(INT_COMP); // init interrrupt on comparator
enable_interrupts(GLOBAL);
delay_us(10);
output_high (PIN_A0); // init test circuit routine
lcd_putc("\fCode 12b"); // welcome
delay_ms (1000);
output_low (PIN_A0); // turn LED off
delay_ms (1000);
} // this is a code snippet
|
edit* please ignore any tris errors. |
|