Re: adc problem
rkodaira,
yah,my setting is left justified and the program is just output the ADRESH..so,the two settings is not my problem..
and, in the testing program of adc, is the Acquisition time important??
i see the datasheet calculate them with internal capacitor,temperature....can u teach me how to calculate them, i'm very confused now..
the next is ...what is source impedance??the resistor connected or the source's internal resistance??
i see many ppl used this with voltage divider circuit..what is a voltage divider circuit??
Please refer to equation 11-1 from page 114 of 16F877 datasheet. There says that:
Tacq = Tamp + Tc + Tcoff
Tacq = acquisition time (time period between you turn the converter on ( set ADON bit ) and the start of the conversion (set GO/DONE bit)
Tamp = amplifier settling time = fixed 2us
Tc = hold capacitor charging time = Chold * Ric + Rss + Rs) * ln (1/2047)
Being
Rs = source internal impedance (it depends on your sensor, and must be <10kohm))
Ric = interconnect resistance (<1kohm);
Rss = resistance of sampling switch (=7kohm for Vdd = 5V see graphic)
Tcoff = temperature coefficient = [(Work Temperature - 25 degrees celsius)/(0.05us/celsius degree)]
See the example of calculation, which gives 19.72us. If you wait around 20us I think it is ok. Less time results in a non charged hold capacitor with the voltage to be measured. After this time the internal switch disconnects the capacitor from the voltage source to start the conversion itself, so no changes in the input will be considered from now.
The conversion time depends on the setting of Tad which has to be a minimum of 1.6us and max of 6.4us for a correct conversion. If you are using a 4MHz clock, the Tosc = 0.25us, so you should select Tad = 8 Tosc (8 * 0.25us = 2us) which can be obtained by
ADSC1 = 1 and ADSC0 = 0 (both bits from ADCON0 register)
After 12 Tad the bit GO/DONE is cleared and you can read the result on ADRESH and ADRESL (only after GO/DONE is cleared). To start a new conversion, you must wait some time to discharge the capacitor.
The impedance from the source (internal thevenin impedance) is important because the converter has resistances in series with the capacitor. If the source impedance is too high, the capacitor will spend a lot of time to be charged and the lecture will be erratic. In these cases, you should use an operational amplifier as buffer, as it has a very low output impedance. If you are using a high resistance potentiometer to simulate the variation of voltage, it can be the cause of you problem. See the datasheet of sensor to know the output impedance.
[/quote]