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

A/D Newbie

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



Joined: 28 May 2006
Posts: 56

View user's profile Send private message

A/D Newbie
PostPosted: Sat Nov 25, 2006 4:15 pm     Reply with quote

I thought I knew how this was supposed to work. Hook a few resistors to AN0 (in parallel),
Code:
   
   setup_adc_ports( RA0_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel( 0 );

   while(TRUE){
      temp_ad = Read_ADC();
      delay_ms(5000);
      printf("Value:%d",temp_ad);
   }

and connect them, one at a time, to VCC.
I expected a different value for each resistor, and that the value for each resistor would be nearly identical each time I test it. Unfortunatly I never recieved the same values between tests of each resistor, and I couldn't see any correlation between resistor value and the value of temp_ad. and now I only get '0'.

I'm using a PIC16F876a @ 20mhz. I am also using a serial bootloader (the hex file was included with 'PicBoot' and 'PicBootPlus')
What am I doing wrong? How fast can I 'read_adc'? Do I always have to wait 5 seconds?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 26, 2006 12:39 pm     Reply with quote

Quote:

I thought I knew how this was supposed to work. Hook a few resistors to
AN0 (in parallel), and connect them, one at a time, to VCC.
I expected a different value for each resistor, and that the value for each
resistor would be nearly identical each time I test

The A/D measures voltage, not current.

You need to use a voltage divider for your tests.

Download the PicDem2-Plus User's Guide:
http://ww1.microchip.com/downloads/en/devicedoc/51275b.pdf
Go to page 19 and look in the upper left corner of the schematic.
You'll see a 5K trimpot (R16) connected to Pin RA0. That's what
you need to do.

They also have a 470 ohm series resistor. That's in there because
this is intended as a student learning board. If the trimpot was
set to the lower end, it would put ground on pin A0. If the student
made pin A0 into a high level output pin, it would be connected to
ground and this could damage or burn out the pin driver. The 470
ohm resistor limits the current to about 10 ma (max) in this case.
It doesn't affect the A/D operation.

Also, read this section in the 16F876A data sheet:
TABLE 17-14: A/D CONVERTER CHARACTERISTICS
It shows that the recommended impedance of the analog voltage
source is 2.5K and the maximum allowed is 10K. The circuit
shown in the PicDem2-Plus schematic meets those requirements.
In other words, don't make a voltage divider for your tests that
consists of two 47K resistors, with a tap in the middle going to pin A0.
The impedance must be kept within the limits given in the data sheet.
kd5uzz



Joined: 28 May 2006
Posts: 56

View user's profile Send private message

PostPosted: Fri Feb 23, 2007 9:32 pm     Reply with quote

The problem ended up being a faulty compiler. Upgraded to 3.22 and all is working as it should.
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