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 CCS Technical Support

ADC-- RA0 has a non-zero voltage on it

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



Joined: 06 Nov 2007
Posts: 5

View user's profile Send private message

ADC-- RA0 has a non-zero voltage on it
PostPosted: Wed Nov 07, 2007 3:03 pm     Reply with quote

I am using the A port for ADC (16F877A). When i use RA1 i have no problem but for some reason I am having issues with RA0. I measured the voltage on the pin and it is 2.14V (open). I tried two chips. Is there something I am missing in code?

Code:

#include "C:\Program Files\PICC\Projects\11-7-07\main.h"
  #include <string.h>


void main()
{
   int value; 
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
   //setup_adc_ports(AN0_AN1_AN2_AN4_VSS_VREF);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   //SET_TRIS_A( 0xFF );
   // B7,B6,B5,B4 are outputs
   // B3,B2,B1,B0 are inputs



   printf("Start");
   set_adc_channel( 0 );
 
  output_high(PIN_C0);
 
  while(TRUE){
  output_low(PIN_C0);
  spi_write(0x30);
  spi_write(0x0F);
  output_high(PIN_C0);
  output_high(PIN_C1);
  delay_ms(500);
  value = read_adc();
  printf("A/D value = %2x\n\r", value);
  delay_ms(2000);
 
 
 
  output_low(PIN_C0);
  spi_write(0x3F);
  spi_write(0x00);
  output_high(PIN_C0);
  output_low(PIN_C1);
  delay_ms(500);
  value = read_adc();
  printf("A/D value = %2x\n\r", value);
  delay_ms(2000);
  }
   
   
 
}




.h file

#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES WRT_50%                  //Lower half of Program Memory is Write Protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)



PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 07, 2007 3:07 pm     Reply with quote

Are you trying to do this on a floating input ? If so, you could read
any value. Put a 47K pull-down resistor on that pin. Then read it
with read_adc(). It should read 0.
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