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

Problem with A_ANALOG_RA3_REF A/D mode

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







Problem with A_ANALOG_RA3_REF A/D mode
PostPosted: Wed Feb 04, 2004 5:58 pm     Reply with quote

I am trying to use the A_ANALOG_RA3_REF mode of a 16F877 (in 10-bit ADC) but it appears that RA3 is not being used as the reference. Here is a description of the connections I've set up for troubleshooting:

Approximately 3 V is connected to RA3 (from a variable power supply). When I connect either RA0, RA1, or RA5 to RA3 I do not get the 1023 value I would expect, instead I get 605 (which would be correct if Vref+ was 5 V). It appears that RA3 is not being used as Vref+.

I'm using PCW Compiler IDE Version 3.40, PCB Version 3.180, PCM Version 3.180

Code:

#include <16f877.h>
#device ADC=10
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)
#bit ADFM_BIT = 0x9F.7
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)

main() {
   int16 IN1, IN2, IN3, IN4;

   setup_adc( A_ANALOG_RA3_REF );
   setup_adc( ADC_CLOCK_INTERNAL );
   ADFM_BIT = 1; // Right justify the A/D result

   while( TRUE ) {
      // Read analog input voltages
      set_adc_channel( 0 );
      delay_ms(5);
      IN1 = read_adc();
      set_adc_channel( 1 );
      delay_ms(5);
      IN2 = read_adc();
      set_adc_channel( 2 );
      delay_ms(5);
      IN3 = read_adc();
      set_adc_channel( 4 );
      delay_ms(5);
      IN4 = read_adc();

      printf("\r\nRA0: %lu, RA1: %lu, RA2: %lu, RA5: %lu", IN1, IN2, IN3, IN4);
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 04, 2004 6:07 pm     Reply with quote

Code:

setup_adc( A_ANALOG_RA3_REF );
setup_adc( ADC_CLOCK_INTERNAL );

You have two setup_adc() statements.
The first one neds to be changed to setup_adc_ports().
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