|
|
View previous topic :: View next topic |
Author |
Message |
mew1986
Joined: 15 Oct 2011 Posts: 7 Location: CHENNAI
|
adc reading problem in 18f4431 |
Posted: Mon Apr 02, 2012 12:07 am |
|
|
I am Edward, for my project I want to read adc value in 18f4431. I already write the code for my project. In isis simulation software it is working fruitfully. But when I put in hardware, any adc input voltage gives the value of 1023. I put acd=10.
I attached my code below.
Code: |
#include <18F4431.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fixed_IO(C_outputs = PIN_C6)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
long value;
SET_TRIS_A( 0x0F );
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
set_adc_channel(0);
while(1)
{
delay_us(10);
value=read_adc();
printf("adc=%lu\r",value);
delay_ms(100);
}
}
|
Anyone help me please. _________________ EDWARD |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Mon Apr 02, 2012 3:16 am |
|
|
There is nothing really wrong with the code as posted. However a few minor things that are either unnecessary, or would degrade accuracy:
1) Get rid of the fixed IO line. The compiler does all I/O handling for you. You only need to ever use this, if you really _must_ override what the compiler does.
2) Same applies to the TRIS line.
3) Add 'errors' to you RS232 declaration. This _must_ be present when using the hardware UART, unless _you_ handle errors yourself. Not having this risks hanging the UART.
4) ADC_CLOCK_INTERNAL, is _not_ a legitimate clock for a CPU at 20MHz. Read the data sheet on this. However it'll just make the result 'noisier' than it should be, not stop it working.
I'd suspect the real problem is pin connections to the CPU. Proteus makes some of these invisibly for you. I'd guess you are possibly not making the connections to AVdd, and AVss....
Best Wishes |
|
|
mew1986
Joined: 15 Oct 2011 Posts: 7 Location: CHENNAI
|
|
Posted: Mon Apr 02, 2012 10:22 pm |
|
|
Thank you for your time of help
I got the result
Thank you lot sir _________________ EDWARD |
|
|
|
|
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
|