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

ADC problems!

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



Joined: 20 Oct 2003
Posts: 5
Location: Sydney, Australia

View user's profile Send private message

ADC problems!
PostPosted: Tue Aug 24, 2004 12:51 am     Reply with quote

What's wrong with the following code? It just displays values that starts with some value like 700 and then keeps on decreasing to near zero.
I have checked PIN_B4 and has a 3V dc signal applied on it. I used to get this ok on older PCMs. My current version is PCH 3.168. Tried it also on 16F877 with same results!

Thanks for your help.


#include <18F258.H>
#DEVICE ADC=10
#fuses HS,NOPROTECT,BROWNOUT,PUT,NOLVP,NOWDT
#use delay (clock=8000000)
#USE rs232(baud=9600,bits=8,parity=N,xmit=pin_C6,rcv=pin_C7,ERRORS)


//MAIN
//-------------------------------------------------------------
main()
{
int16 value;

printf("hello World!\n\r"); //show something

SETUP_ADC_PORTS(ALL_ANALOG);
SETUP_ADC(ADC_CLOCK_INTERNAL);
SET_ADC_CHANNEL(4); //Read from Chnl 4 only


do
{
value=read_adc();
printf("%lu\n\r", Value);
delay_ms(1000);
}while(TRUE);

}
verba



Joined: 17 Aug 2004
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 24, 2004 2:35 am     Reply with quote

I donīt know a lot about this, but why donīt you put the delay between the adc and the printf, then you give time to adc to read correctly.
Then, I think you need divide the frecuency of clock. In the datasheet you can read than for speeds greaters 1 Mhz, RTC only is recomended to sleep mode. Try with div_32.
I will post now a problem of changes in values of adc very stranges, maybe it can help in your problem.
Verba
Ttelmah
Guest







PostPosted: Tue Aug 24, 2004 2:59 am     Reply with quote

I hope the comment that you have tested pin B4, is a missprint, since the analog input is pin RA5 - note this is not RA4...
ADC_CLOCK_INTERNAL will work, but may not give good accuracy. On some chips, the data sheet recommends not using this, or using 'sleep', over 4MHz. Use div_32 instead.
Your first reading will be wrong (you are not allowing any time between selecting the ADC channel and reading it. Put the delay at the start of the loop, so the capacitor in the ADC has time to charge.
Obviously, the stability of the reading, will depend on th quality of your supply rail. Noise here will degrade the performance significantly.
I suspect your signal is connected to the wrong pin, and the real pin is discharging with successive readings.

Best Wishes
achacko



Joined: 20 Oct 2003
Posts: 5
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Aug 24, 2004 7:29 pm     Reply with quote

Thanks everyone. Obviously I was looking at the wrong pin. Got it fixed and all working now Smile
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