|
|
View previous topic :: View next topic |
Author |
Message |
jjude Guest
|
ADC problem |
Posted: Fri Mar 31, 2006 11:13 am |
|
|
ADC-results is 8-bit!?! I need 10-bit!
Code (i load code PIC16F876A bootloader):
#case
#include <16F876A.h>
#include <ctype.h>
#device *=16
#device adc=10
#org 0x1F00, 0x1FFF {} //BootLoader 8k 16F876/7
#use delay(clock=10000000)
#fuses NOWDT,HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
.
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
int16 int16count;
.
set_adc_channel(0);
delay_us(100);
int16count=read_adc();
.
Results is 1,66 volt -> 85.
What is wrong? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 31, 2006 1:23 pm |
|
|
You didn't show a complete test program so I have to guess what the problem is.
My guess is that you are using only the 8-bit format specifier for printf,
and you need to use 16-bit.
Example:
You are probably doing this:
Quote: | printf("%x", int16count); |
You should do this:
Quote: | printf("%lx", int16count); |
Note the lower case "L" in front of the x. This tells the compiler
to display a 16-bit value. |
|
|
jjude Guest
|
Print |
Posted: Sat Apr 01, 2006 1:34 am |
|
|
I print print("%lu",int32count);
I test adc=16. This send results 0x1ff0
adc=10 results is 0x0ff?!?!? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 01, 2006 2:05 am |
|
|
Post your compiler version. This is a number such as 3.191 or 3.245,
and you can find it at the top of the .LST file. The .LST file is generated
each time you compile a program. Look for that file in your project
folder.
If you post your compiler version, I can check if there is a problem
with the A/D converter functions in your version. |
|
|
|
|
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
|