Guest Guest
|
Problem with A_ANALOG_RA3_REF A/D mode |
Posted: Wed Feb 04, 2004 5:58 pm |
|
|
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);
}
}
|
|
|