View previous topic :: View next topic |
Author |
Message |
username Guest
|
a/d reading jumping all over the place |
Posted: Tue Mar 23, 2004 6:08 pm |
|
|
I have a 16f877A set up with all analog on port A, when I read a port i get values that are jumping all over the place.
main() {
setup_adc_ports(ALL_ANALOG); setup_adc(ADC_CLOCK_DIV_32); set_adc_channel(0); delay_us(10);
rms_grid = read_adc();
delay_us(10);
set_adc_channel(1);
delay_us(10);
rms_gen = read_adc();
delay_us(10);
.......
the values seem almost random eventhough they are tied to a constant voltage for testing. i put in a loop and printf statements to monitor the values and its just all over the place
thanks.
can someone give me some idea to settle the values i am reading |
|
|
Guest
|
|
Posted: Tue Mar 23, 2004 6:17 pm |
|
|
what have you connected to the pin, is it just floating?? |
|
|
username Guest
|
a/d |
Posted: Tue Mar 23, 2004 6:33 pm |
|
|
actually what i have it connected to is a simple voltage divider. i am wanting to monitor the level of a 12v battery, and yes they have a common ground. So since the voltage is from a battery it is a static value but the a/d is giving random values.
I will try a new pic when i get one. I have used them before and got a fairly stable reading, since i am using 'all analog' the reference should be vcc so it should give me a stable reading......... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 23, 2004 6:41 pm |
|
|
What resistor values are you using in your voltage divider ?
There could be a problem if they are too large. |
|
|
username Guest
|
a/d |
Posted: Tue Mar 23, 2004 7:53 pm |
|
|
they are fairly high, i was trying to minimize the current in the divider, i dont have the cct here and cant remember the values used off hand.
i will reduce their value and give it a try.
thanks |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Mar 23, 2004 9:07 pm |
|
|
According to the device datasheet, the maximum recommended impedance for analog sources is 10 kΩ. |
|
|
kable Guest
|
a/d |
Posted: Tue Mar 23, 2004 11:09 pm |
|
|
hummmm I wonder if the problem is that the voltage is being sampled from a voltage divider and its loading it down. I wonder if I should throw in a buffer. Shouldnt the a/d have a high impedance and not load the input?
ohh well |
|
|
tywais
Joined: 01 Apr 2004 Posts: 1 Location: Chiangmai Thailand
|
|
Posted: Thu Apr 01, 2004 1:00 am |
|
|
I just finished designing a data acquisition system using a 16F877 and had the same problem before I realized I forgot to set the ADFN bit for right justified ADCON1 = %10000000 else your bottom 6 bits are all zero and you will be getting the 4 lsb's at the top of the resulting word. |
|
|
|