View previous topic :: View next topic |
Author |
Message |
empman
Joined: 27 Oct 2011 Posts: 2
|
Not getting 10 bit adc from pic18f14k50 ? |
Posted: Thu Oct 27, 2011 2:47 am |
|
|
I'm using a PIC1814k50 with 10bit adc to make some adc measurement
However, the values that I get only to 8 bit adc?????????
Here is my code :
Code: |
#include <18f14k50.h> //micro name
#device adc=10
#FUSES INTRC //Internal RC Osc
#use delay(Clock=4000000) // oscillator frequency
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8)
main()
{
unsigned long x;
setup_adc_ports(sAN5|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
set_tris_B(0);
//setup_adc( ADC_CLOCK_INTERNAL );
while(true)
{
set_adc_channel( 5 );
x = Read_ADC();
putc(toupper(x));
delay_ms(50);
}
}
}
|
|
|
|
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
|
Posted: Thu Oct 27, 2011 3:38 am |
|
|
Read help:
Quote: |
result = toupper (cvalue)
Parameters: cvalue is a character
Returns: An 8 bit character |
|
|
|
empman
Joined: 27 Oct 2011 Posts: 2
|
The accuracy of calculations is 10 mV؟؟؟ |
Posted: Fri Oct 28, 2011 4:11 am |
|
|
Thank you
But there is still a problem.The calculated value by micro is 8 bit.The accuracy of calculations is 10 mV(vdd=5v,vss=0v)
5/255=10mv
I run this program without a serial port but Accuracy of calculations is 10 mV
for 10bit adc :
5/1023=5mv
Where is the problem؟؟؟؟؟؟؟ |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: The accuracy of calculations is 10 mV؟؟؟ |
Posted: Fri Oct 28, 2011 5:27 am |
|
|
empman wrote: | Thank you
But there is still a problem.The calculated value by micro is 8 bit.The accuracy of calculations is 10 mV(vdd=5v,vss=0v)
5/255=10mv
I run this program without a serial port but Accuracy of calculations is 10 mV
for 10bit adc :
5/1023=5mv
Where is the problem؟؟؟؟؟؟؟ |
Where is the problem? For a start you need to start getting precise with basic arithmetic :-| The correct calculation for ADC resolution is Volts Range/Number of counts. For 8 bit, unipolar, +5.0V Vref that 5.0/256 which is 19.53125mV per bit. I much prefer a reference from a decent reference source, usually 4.096V or 2.048V. These give much simpler to get your head round values for ADC resolution, such as 16mV per bit for 4.096V, 8 bit or 1mV for 12 bit. In any case for anything other than basic position sensing or coarse voltage detection type applications using the supply as your reference is no good. +5V is usually anything other than +5.00V. Anything from +4.74V to +5.25V is normal.
Back to the issue. You are running your ADC WAY TOO fast, it hasn't got a hope in he** of sampling any signal at that speed. Read the data sheet for your PIC. Then read it again and again until you are sure you've understood it. Then change your setup_adc() to give speeds the ADC can handle. Hint, PIC18 ADC clock at a maximum of around 1MHz. Don't for get to make sure your acquisition time is long enough too. Though you might get away with less as you're only sampling one ADC channel. It looks as though you've decided to run the ADC as fast as you can possibly get it to go. You've not sussed out how fast it actually can go AND get decent results.
I'm not sure you can get 40MHz CPU speed when running from the internal oscillator. If you can I'm pretty sure you can use the USB.
When set up correctly - all the clocks going at sensible speeds - you WILL get 10 bits out of the ADC. The overall accuracy wont be 10 bits of course, and that will degrade a lot due to power supply variations and noise, but all ten bits will be there to see. If you really must use the +5 supply as your reference then 8 bits are more than good enough.
So:
1) Sort out your clock speed.
2) Configure your ADC correctly.
3) Decide if your application really needs all ten bits, if so make sure your reference is good (stable and as free from noise as possible) enough.
RF Developer |
|
|
|