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

setting adc vref

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



Joined: 04 May 2010
Posts: 2
Location: MALAYSIA

View user's profile Send private message

setting adc vref
PostPosted: Tue May 04, 2010 9:45 pm     Reply with quote

Compiler version 4.057

I'm trying to configure vref for the adc but the compiler give me error.
The error is: setup_adc_ports(RA0_RA1_RA3_ANALOG);

That line I took from the CCS help.

Any idea how to configure vref? I don't want to use the 5V vref cause
my input volt range from 0 to 2V.
Code:

#include <18F4550.h>
#DEVICE ADC=8
#include <math.h>

//configure a 20MHz crystal to operate at 48MHz
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 
#use delay(clock=48000000)

#use rs232(baud=19200, xmit=PIN_B6, rcv=PIN_B7,errors,INVERT)

void main() {

unsigned int8 i, value, min, max;

printf("Sampling:");                      // Printf function included in RS232 library

setup_adc_ports( RA0_RA1_RA3_ANALOG );   
   
setup_adc(ADC_CLOCK_INTERNAL);            // Built-in A/D setup function
set_adc_channel(0);                       // Built-in A/D setup function

do {
   min=255;
   max=0;
   for(i=0; i<=30; ++i) {
      delay_ms(100);                      // Built-in delay function
      value = read_adc();                 // Built-in A/D read function
      if(value<min)
         min=value;
      if(value>max)
         max=value;
   }
     
   printf("\r\nMin: %2X  Max: %2X\n\r",min,max);     
} while (TRUE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 05, 2010 12:37 am     Reply with quote

Quote:

The error is: setup_adc_ports(RA0_RA1_RA3_ANALOG);

The parameters used for that function can vary, according to the PIC
family. The one above is for the 16F877. Look in the 18F4550.h file
to see the available parameters for that PIC. There is a list of them
in the file (near the end) in this section:
Quote:

// Constants used in SETUP_ADC_PORTS() are:

Here's the file location on your PC:
Quote:

c:\program files\picc\devices\18f4550.h
suardi



Joined: 04 May 2010
Posts: 2
Location: MALAYSIA

View user's profile Send private message

PostPosted: Wed May 05, 2010 1:47 am     Reply with quote

thanks PCM, i finally get it worked.

this is from the .h file :

Quote:


// The following may be OR'ed in with the above using |
#define VSS_VDD 0x00 // Range 0-Vdd
#define VREF_VREF 0x30 // Range VrefL-VrefH
#define VREF_VDD 0x20 // Range VrefL-Vdd
#define VSS_VREF 0x10 // Range 0-VrefH


and this is my setup(vref is connected to pin RA3):

Quote:

setup_adc_ports(AN0|VSS_VREF);



thanks again.
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