CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

jumpy adc value

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
max23
Guest







jumpy adc value
PostPosted: Sat Jan 23, 2010 10:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 23, 2010 11:06 pm     Reply with quote

See these threads:
http://www.ccsinfo.com/forum/viewtopic.php?t=41183
http://www.ccsinfo.com/forum/viewtopic.php?t=34725&start=18
http://www.ccsinfo.com/forum/viewtopic.php?t=29307
http://www.ccsinfo.com/forum/viewtopic.php?t=36918

If that doesn't help, then post your reference voltage,
and post a description of the circuit which creates it.

Also post the Vdd voltage on the PIC, and the PIC's
oscillator frequency.
max23
Guest







PostPosted: Sun Jan 24, 2010 4:14 am     Reply with quote

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







PostPosted: Sun Jan 24, 2010 4:41 am     Reply with quote

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







PostPosted: Sun Jan 24, 2010 4:56 am     Reply with quote

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







PostPosted: Sun Jan 24, 2010 12:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 12:50 pm     Reply with quote

Post a short list of typical values so we can see what you mean by "jumpy".
max23
Guest







PostPosted: Sun Jan 24, 2010 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 1:02 pm     Reply with quote

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







PostPosted: Sun Jan 24, 2010 1:10 pm     Reply with quote

16f877a, version 4.084
yes i'm testing on hardware
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 1:32 pm     Reply with quote

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







PostPosted: Sun Jan 24, 2010 7:50 pm     Reply with quote

i need serial cable to connect the pic to pc right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 8:13 pm     Reply with quote

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








PostPosted: Sun Jan 24, 2010 9:30 pm     Reply with quote

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







PostPosted: Mon Jan 25, 2010 1:05 am     Reply with quote

Anonymous wrote:
Does your input pin require a pullup resistor? Does your input source require a buffering capacitor?


how do i know this?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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