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

just first adc sample is not good

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



Joined: 19 Dec 2014
Posts: 16

View user's profile Send private message

just first adc sample is not good
PostPosted: Wed Jan 21, 2015 1:37 am     Reply with quote

hello all

I will be happy if someone could answer my question, sorry about my english by the way Smile

I am using pic16 and doing adc sample. The problem is that just the first sample is 0..... the 4 other after are ok. Does somebody have an idea?
By the way when i call the function again the first sample is ok..so i get 5 good samples.
Code:

int i=0;
unsigned int32 Sum=0;

setup_adc(adc_clock_internal);
delay_ms(1);
setup_adc_channel(3);
delay_ms(1);

for(i=0;i<5;i++)
{
 SUM+=read_adc();
 delay_ms(10);
}

return sum/5

appreciate your help. good day
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Wed Jan 21, 2015 8:42 am     Reply with quote

1) The code as posted doesn't show us the setup, or PIC you are. Code should be a small complete program that we can compile. Not a 'snippet'.
2) The clock is almost certainly not recommended. The internal RC clock for the ADC should normally (on most PIC16's) only be used if you are running below 1MHz, or are putting the chip to sleep for the ADC sample.
3) Then the code as posted won't work. You are not telling the multiplexer which channels are to be used for ADC operation. The commands being used are not the normal CCS ones (you are using CCS?....).
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 21, 2015 3:20 pm     Reply with quote

another 'thing'
/5 is 'bad' on a PIC, consumes a LOT of time and resources.

better to use /4 or /8

way faster, only 1-2 intrsuctions !

jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Wed Jan 21, 2015 3:38 pm     Reply with quote

MicroC uses 'setup_adc_channel'. Suspicion that it is not CCS code, rises....
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