|
|
View previous topic :: View next topic |
Author |
Message |
Francesc Guest
|
A/D from 16F873 |
Posted: Thu Feb 12, 2004 2:11 pm |
|
|
Hi all,
We are beginners with a PIC microcontrollers, but is very strange, we try to read 4 ports analogs from 16F873, but the readings not are corrects.
We modify our code, because had a lot mistakes, another time we try to enter differents voltages, and ever the readings not are correct.Here a new sample:
0,0 V..0000 bit
1,0 V..0190 bit
2,0 V..0177 bit
3,0 V..0121 bit
4,0 v..0079 bit
4,5 v..0181 bit
5,0 v..1023 BIT
We include an small part of our code to try found the error.
The compiler version is 2.732 #10544.
Please, help me..
#include <16f873.h>
#device ADC=10
#fuses xt,nowdt,put,nolvp
#use delay(clock=4000000)
#use RS232(BAUD=9600,BITS=8,XMIT=PIN_C6,RCV=PIN_C7)
#bit ADFM_BIT=0x9F.7
LONG T,K1,K2,K3,K4,K;
main()
{
SETUP_ADC_PORTS(A_ANALOG);
//SETUP_ADC(ADC_CLOCK_DIV_8);
SETUP_ADC(ADC_CLOCK_INTERNAL);
ADFM_BIT=1;
while(1)
{
SET_ADC_CHANNEL(0);
delay_ms(10);
T=READ_ADC();
delay_ms(50);
SET_ADC_CHANNEL(1);
delay_ms(10);
T=READ_ADC();
delay_ms(50);
SET_ADC_CHANNEL(2);
delay_ms(10);
T=READ_ADC();
delay_ms(50);
SET_ADC_CHANNEL(4);
delay_ms(10);
T=READ_ADC();
delay_ms(50);
void display();
}
} |
|
|
Guest
|
|
Posted: Thu Feb 12, 2004 3:05 pm |
|
|
First, the data sheet says that the internal a/d internal RC oscillator should only be used for sleep operation when the device frequency is above 1MHz. Instead use
SETUP_ADC(ADC_CLOCK_DIV_8); // OK to 5MHz
Since the readings are correct at 0 and +5V, the signal source could be the problem. Avoid using high value resistive dividers or potentiometers - there is a 10K source impedance limit for 10 bit operation.
Delay is needed only after selecting a channel to allow the internal capacitor to charge - 10uS is enough if source impedance lower than 10K.
HTH |
|
|
|
|
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
|