View previous topic :: View next topic |
Author |
Message |
id31
Joined: 19 Dec 2014 Posts: 16
|
just first adc sample is not good |
Posted: Wed Jan 21, 2015 1:37 am |
|
|
hello all
I will be happy if someone could answer my question, sorry about my english by the way
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: 19547
|
|
Posted: Wed Jan 21, 2015 8:42 am |
|
|
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
|
|
Posted: Wed Jan 21, 2015 3:20 pm |
|
|
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: 19547
|
|
Posted: Wed Jan 21, 2015 3:38 pm |
|
|
MicroC uses 'setup_adc_channel'. Suspicion that it is not CCS code, rises.... |
|
|
|