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

setup_comparator(A0_VR_A1_VR); ?

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



Joined: 14 Jun 2005
Posts: 64

View user's profile Send private message

setup_comparator(A0_VR_A1_VR); ?
PostPosted: Sat Mar 18, 2006 6:42 pm     Reply with quote

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.
Guest








PostPosted: Sun Mar 19, 2006 9:49 am     Reply with quote

I think I get the modes.
http://ww1.microchip.com/downloads/en/devicedoc/31020a.pdf pg.5
I want mode 5 for 2 analog inputs (1 is a switch, the other +5 or gnd)
setup_comparator(NC_NC_A1_A2);
There doesn't seem to be an option for 1 comparator with digital inputs.

I still don't understand how the Vref ties in or how to set it up??
Thanks in advance-
SophE


[/img]
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