|
|
View previous topic :: View next topic |
Author |
Message |
prayami
Joined: 22 Dec 2004 Posts: 78
|
10 bit ADC while frequency is 40Mhz |
Posted: Wed Apr 26, 2006 5:14 pm |
|
|
Hi...
We are using 18F4525 with 10Mhz crystal X 4(PLL) = 40Mhz frequency.
The compiler we got is PCH 3.249.23.12 .
I am trying to read 10 bit ADC.
What I find, sometime it reading wrong values. I tried it different-
different way. But could not solve the problem. I had read in the
datasheet for Aquition time etc setting but still confusing. N E body who
knows what can be the problem..plzzzzzzz...
Following is the setting I made for ADC 10 bit.
Quote: |
#include <18F4525.h>
#device ADC=10
#fuses H4,NOWDT,NOLVP,NOBROWNOUT,NOPBADEN,PUT,NOXINST,NOMCLR,NOLPT1OSC,NOWRT,NOWRTD,EBTR,NOCPB,EBTRB,NOWRTC,NOWRTB,PROTECT,CPD
#use delay(clock=40000000)
unsigned int16 CurrentValue;
//------ADC setting------------------
setup_port_a( AN0 );
delay_ms(5);
setup_adc( ADC_CLOCK_DIV_32| ADC_TAD_MUL_12 );
//setup_adc( ADC_CLOCK_DIV_4 | ADC_TAD_MUL_12 ); //tried this
//setup_adc( ADC_CLOCK_INTERNAL ); //tried this
set_adc_channel( 0 );
delay_ms(10);
//-------ADC reading is simple----------
CurrentValue = Read_ADC(); // CurrentValue is "unsigned int16"
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 26, 2006 6:25 pm |
|
|
Make a simple program and run it at 10 MHz. See if it works OK.
This will tell you if the problem is related to running at 40 MHz, or
if maybe the problem is in the external circuit which provides the
analog signal. Try this program:
Code: |
#include <18F4525.h>
#device adc=10
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==============================
void main()
{
int16 CurrentValue;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(10);
while(1)
{
CurrentValue = read_adc();
printf("%lx", CurrentValue);
delay_ms(1000);
}
} |
|
|
|
prayami
Joined: 22 Dec 2004 Posts: 78
|
|
Posted: Wed Apr 26, 2006 9:28 pm |
|
|
It is working for 10MHz. Can you please let me know, what should be
the Tad and Fosc etc settings for 40Mhz. I tried as per I understand but sometimes reading unexpcted value.
Thanks... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 26, 2006 11:30 pm |
|
|
I would try it with the changes shown in bold below:
Quote: |
#include <18F4525.h>
#device adc=10
#fuses H4, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==============================
void main()
{
int16 CurrentValue;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_64);
set_adc_channel(0);
delay_us(10);
while(1)
{
CurrentValue = read_adc();
printf("%lx", CurrentValue);
delay_ms(1000);
}
} |
|
|
|
|
|
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
|