|
|
View previous topic :: View next topic |
Author |
Message |
prog Guest
|
ADC problem with 16F88 |
Posted: Tue Jul 29, 2008 2:07 am |
|
|
Hi,
I have a problem with read_adc().
I try reading the chanel AN0. In the input I have 1.05 V(VDD = 3) and the function return 3C --> 0.175 V.
Code: |
#include <16F88.h>
#device adc=10
#use delay(clock=8000000,RESTART_WDT)
#fuses HS,MCLR,WDT,PUT,NOBROWNOUT,NOLVP
void main(){
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(TRUE){
delay_us(20);
vbat = read_adc();
vbat = (vbat*0.0293+0.6).001+vbat_old*0.999;
vbat_old = vbat;
}
}
|
Thanks! |
|
|
Ttelmah Guest
|
|
Posted: Tue Jul 29, 2008 4:10 am |
|
|
First, give us some code that can actually work.
What you post, has no definitions for vbat, or vbat_old, and the arithmetic as posted can't work. Makes it impossible to really 'comment'...
The code should be similar in length, but able to be compiled, and work to show the problem.
Second, what compiler version?. On a few of the older compilers, there are problems with some of the setup values for things like the ADC port.
Consider some other way of doing the damping. floating point arithmetic is _slow_, and bulky. There are simpler ways of getting a similar result.
Third, though it won't cause this problem, and the data sheet for the F88, is one of a number that doesn't 'warn' about this, the internal ADC oscillator, should only really be used in conjunction with 'sleep' sampling, otherwise the processor noise, which is asynchronous to this RC clock, can lead to poor result accuracy.
Best Wishes |
|
|
|
|
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
|