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

yet another adc problem...

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



Joined: 28 May 2009
Posts: 1

View user's profile Send private message

yet another adc problem...
PostPosted: Thu May 28, 2009 2:03 pm     Reply with quote

Hi!

I'm trying to read a voltage divider made by a 22k potentiometer.
pin1 of the pot goes to vcc, pin3 to vss and center pin on the pic16f877a.

I wrote this code, but seems like there's something wrong because it's not working.
Code:

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

#include <math.h>
#include <stdlib.h>
#include <string.h>

#fuses  XT, NOWDT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, WRT_50%, NOCPD

#use delay(clock=11059200)
#use rs232 (baud= 9600,xmit=PIN_B6, rcv=PIN_B7, INVERT)



int16 posicao;



void init(void)
{

setup_adc_ports( AN0 );
setup_adc(ADC_CLOCK_INTERNAL);


}


int16 converte_adc()
{

int16 adc;
     
      delay_us(10);
      set_adc_channel( 0 ); 
      adc = read_adc();
     
     
      return adc; 
}


void main(void)
{

printf("ola!!!!");
init();
printf("ola!!!!");

   while(1){
   

      //posicao=converte_adc();   
      posicao=(float)converte_adc();
      posicao=((posicao/255.0)*5.0);
      delay_us(100);             
      printf("\n posicao %ld\n\n\r",posicao);
   
}

}


Any ideas?

Thanks in advance.

RJ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 28, 2009 2:25 pm     Reply with quote

Quote:
#fuses XT, NOWDT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, WRT_50%, NOCPD

#use delay(clock=11059200)

Look in the oscillator section of the PIC data sheet. XT mode is only
recommended for crystals of 4 MHz, maximum. It doesn't have the
power to drive a faster crystal. Use HS mode.

Also, there's no reason to use write protection during development of
an A/D program.
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