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

A/D conversion using 18F67J50

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



Joined: 21 Feb 2008
Posts: 24

View user's profile Send private message

A/D conversion using 18F67J50
PostPosted: Thu Nov 06, 2008 2:00 pm     Reply with quote

I'm using compiler PCH version 4.066.
I'm using the 18F67J50.
The PIC is powered by 3.3V.
The A/D reference voltage is 2.048V.

The issue I am seeing is I when set the A/D to use Vdd and Vss as it's limits or when I set the A/D to use Vref+ and Vss as it's limits I read the same value.

I have 3.3V going to all Vdd pins. I have 3.3V going to AVdd, pin 19. I have 2.048 going to Vref+, pin 21. I have all Vss pins, AVss, and Vref- tied to GND.

Here is a short sample program
Code:

#include <18F67J50.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES H4_SW                    //High speed osc with SW enabled 4x PLL
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES MSSPMSK7
#FUSES NOCPUDIV             
#FUSES PLL3                     //No PLL PreScaler

#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,stream=DEBUG)

#byte   OSCTUNE = 0xf9b
#bit      PLL_EN = OSCTUNE.6

#define LED1      PIN_E4
#define LED2      PIN_C1
#define LED3      PIN_E3
#define XMIT_PWR_ON   PIN_D1
#define REF_V      PIN_E1

void main()
{
   int16 cnts=0;

   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

   PLL_EN = 1;   //enable the software PLL
   output_bit(REF_V, 1);
   output_bit(XMIT_PWR_ON,1);
   fprintf(DEBUG, "\fStarting A/D conversions\r\n");

   while(1){
        output_bit(LED1, 1);
        output_bit(LED2, 0);
      setup_adc_ports(sAN0|sAN1|sAN4|VSS_VREF);      
      delay_ms(1000);
      set_adc_channel(0);
      delay_us(10);
      cnts = read_adc();
      fprintf(DEBUG, "0a - Counts=%lu\r\n", cnts);
      delay_ms(3000);
   
        output_bit(LED1, 0);
        output_bit(LED2, 1);
      setup_adc_ports(sAN0|sAN1|sAN4|VSS_VDD);
      delay_ms(1000);
      set_adc_channel(0);
      delay_us(10);
      cnts = read_adc();
      fprintf(DEBUG, "0b - Counts=%lu\r\n", cnts);
      delay_ms(3000);
   }

}


I am putting 0.507V into AN0 and reading 160 counts. That is correct if the A/D is reference to VDD(3.3V). When the A/D is referenced to Vref+(2.048V) I am also reading 160 counts. I would expect to read around 253 counts.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 06, 2008 6:08 pm     Reply with quote

Quote:
The PIC is powered by 3.3V.
The A/D reference voltage is 2.048V.

The problem is in the Vref+ value. Look at this table in the PIC data
sheet, on page 456 in the Acrobat reader:
Quote:
TABLE 28-28: A/D CONVERTER CHARACTERISTICS: PIC18F87J50 FAMILY (INDUSTRIAL)

Look at spec A20, the Reference Voltage Range. If Vdd is > 3.0v,
the Vref delta must be at least 3 volts. So in your case, the lowest
that you can set it is 3.0v.
ntgcp_08



Joined: 21 Feb 2008
Posts: 24

View user's profile Send private message

PostPosted: Fri Nov 07, 2008 8:26 am     Reply with quote

Thanks!
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