View previous topic :: View next topic |
Author |
Message |
max23 Guest
|
jumpy adc value |
Posted: Sat Jan 23, 2010 10:13 pm |
|
|
Code: | void main ()
{
lcd_init();
setup_adc_ports( ANALOG_RA3_REF );
setup_adc( ADC_CLOCK_DIV_32 );
while (1)
{
printf(lcd_putc,"\fX:%Ld Y:%Ld\nz:%Ld",value_x(),value_y(),value_z());
delay_ms(350);
}
}
int16 value_x()
{
set_ADC_channel(0);
delay_us(20);
return read_adc();
}
int16 value_y()
{
set_ADC_channel(1);
delay_us(20);
return read_adc();
}
int16 value_z()
{
set_ADC_channel(2);
delay_us(20);
return read_adc();
} |
the value i read is jumpy
what might be the problem |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 4:14 am |
|
|
my ref voltage jumpy 3.3v~3.29v its not actually fix to 3.3v. wonder why,,
my Vdd 5v,20M OSC, PIC 16f877a
i basically read adc value from ADXL330 accelerometer,,
ADC setup : ( ANALOG_RA3_REF ); ( ADC_CLOCK_DIV_32 ); |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 24, 2010 4:41 am |
|
|
How is the ref voltage generated?.
One possibility (for example), would be if you are using a voltage regulator chip, rather than a bandgap reference, you might be seeing the output oscillating (need to look with a scope, rather than a meter). Voltage regulators, are internally very high gain amplifiers, and as such need careful component choice, and board layout....
Other thing to look at. Where are you picking up the ground from, for your meter, and the different components. You might be seeing a problem in this area.
Best Wishes |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 4:56 am |
|
|
yes i'm using voltage regulator chip,
i'm using variable power supply and it give about 5++v to the chip
the ground from the supply |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 12:48 pm |
|
|
i try using 5k trimpot and the result is same, even without adjusting the trimpot, the value 'jumpy' |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 12:50 pm |
|
|
Post a short list of typical values so we can see what you mean by "jumpy". |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 12:58 pm |
|
|
hye,,
i tried adjust the trimpot at the middle, the value shown is 0+~200+~500+~700+~1023,, it goes up & down |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 1:02 pm |
|
|
1. What is your PIC ?
2. Post your compiler version.
3. Are you testing this in hardware or on a simulator (Proteus, etc). ? |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 1:10 pm |
|
|
16f877a, version 4.084
yes i'm testing on hardware |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 1:32 pm |
|
|
Connect the center tap of a 5K trimpot to pin A0 on your PIC and try
a simple program like this one. The top pin of the trimpot should go to
+5v and the bottom pin to Ground.
Code: |
#include <16F877A.H>
#device adc=10
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//============================
void main()
{
int16 adc_value;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
while(1)
{
adc_value = read_adc();
printf("%lu \n\r", adc_value);
delay_ms(500);
}
}
|
This program will display the A/D result on a serial terminal window
on your PC. |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 7:50 pm |
|
|
i need serial cable to connect the pic to pc right? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 8:13 pm |
|
|
Yes, and your board must have an RS232 interface chip, such as a
MAX232, etc. Also, your PC must have a COM port connector on the back. |
|
|
Guest
|
|
Posted: Sun Jan 24, 2010 9:30 pm |
|
|
What is your input source? Does your input pin require a pullup resistor? Does your input source require a buffering capacitor? If your voltage source is jumpy, that would be the first thing to fix. If you're using a DC power supply, try replacing it with either batteries, or a different power supply. Your ADC is constantly figuring the difference between ground (0V) and VREF (+V). If your voltage source, or VREF are jumpy, your result will also be. |
|
|
max23 Guest
|
|
Posted: Mon Jan 25, 2010 1:05 am |
|
|
Anonymous wrote: | Does your input pin require a pullup resistor? Does your input source require a buffering capacitor? |
how do i know this? |
|
|
|