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 support@ccsinfo.com

PIC ADC

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



Joined: 10 Feb 2008
Posts: 7

View user's profile Send private message

PIC ADC
PostPosted: Sun Feb 10, 2008 3:33 pm     Reply with quote

Hi all,
I hope someone is able to help me. Im using the ADC on a PIC16f916 as part of my final year project. At the moment im just trying to sample one channel and send the 8 bit result to 8 LED's connected to channel B. The problem is two fold...even if I ground the input channel I still get a reading of binary 1 which equates to 19.7mV. The major problem is that all of my readings (from the LED's) seem to be around 80mV to high when compared to my voltmeter readings. BTW im using a bench power supply to vary my voltage.

ill post my code if anyone wants to help

thanks for reading and I hope you can help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 3:45 pm     Reply with quote

Post a short test program. Be sure to post all the #include, #fuses,
and #use statements. Post all the variable declarations. You should
be able to do this with about 10 lines of code.
jonnylazer



Joined: 10 Feb 2008
Posts: 7

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 5:10 pm     Reply with quote

here is the part of my program that is relevant to my prob...

#INCLUDE <16f916.h>
#DEVICE ADC=8
#DEFINE DEVICEOSC 4000000
#fuses HS,NOWDT,PUT,NOPROTECT,BROWNOUT,
#use delay(clock=DEVICEOSC)



void main(void) {
int value;

// set up
setup_adc( ADC_CLOCK_DIV_8); // the adc
setup_adc_ports(ALL_ANALOG);
set_adc_channel( 0 );

do {

delay_us(30);
value = read_ADC();
output_b(value);


}
while(true);
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 7:31 pm     Reply with quote

How are you using your voltmeter? Measure from the PIC analog ground pin to the A/D channel pin. If possible put your probe on the pin where it leaves the package, before it enters a solder joint or socket pin.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 7:55 pm     Reply with quote

I modified your code slightly and programmed it into a 16F917, which
is a similar PIC. I tested it on a on a PicDem2-Plus board, which has
a 5K trimpot connected to the AN0 pin. I turned the trimpot down to
zero ohms and the A/D reads 0. So it's working correctly. This is with
compiler vs. 4.066. Here's the output:
Quote:

8a
8a
8a
8a
8a
13
00
00
00
00
00
00


Code:
#include <16F917.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main()
{
int8 value;

setup_adc(ADC_CLOCK_DIV_8); 
setup_adc_ports(sAN0 );
set_adc_channel(0);

while(1)
  {
   delay_us(30);
   value = read_adc();

   //output_b(value);
   printf("%x \n\r", value);
   delay_ms(500);
  }

while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 8:01 pm     Reply with quote

Quote:
BTW im using a bench power supply to vary my voltage.

What does this mean ? Are you changing the Vdd voltage on your PIC,
or the A/D voltage going to pin AN0 ?

I suggest that you use a 5K trimpot to supply the test voltage for the A/D.
Connect one end of the pot to +5v (PIC's Vdd voltage) and the other end
to ground. Connect the wiper to the AN0 pin on the PIC. Then it will
be the same as the PicDem2-Plus board. The trimpot value should be
10K or less. Don't use a 50K pot.
jonnylazer



Joined: 10 Feb 2008
Posts: 7

View user's profile Send private message

PostPosted: Sun Feb 10, 2008 8:23 pm     Reply with quote

Thanks for the input, unfortunately I dont have trimpot at hand. I will have to 'borrow' one from Uni in the morning. So, judging by the fact that it worked for you I assume any problem I have is a hardware one?

I will post again tomorrow when ive tried your suggestion.

cheers mate.
Guest








PostPosted: Thu Feb 14, 2008 7:32 pm     Reply with quote

I would take a look at your ground paths. Make sure all of your circuit grounds go to a single node. Without seeing your circuit and layout its tough to tell if it could be hardware, but it sounds like your PIC thinks that the A/D converter port is not going to ground when you connect it to ground. Also check your bypassing; these fast ADCs need a stiff supply.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 14, 2008 10:24 pm     Reply with quote

He sent me a PM that he put in the trimpot and it worked OK.
His problem is solved.
jonnylazer



Joined: 10 Feb 2008
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 15, 2008 3:16 am     Reply with quote

Thanks PCM....should have posted my PM here. Anyway, thanks again.
jonnylazer



Joined: 10 Feb 2008
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 15, 2008 3:20 am     Reply with quote

One final question PCM....why add the 'DELAY_ms(500)' to the routine....is it RS232 ??
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 15, 2008 8:37 am     Reply with quote

I would guess that is so your eyes can focus on each reading before it scrolls off the edge of the screen. Wink
_________________
The search for better is endless. Instead simply find very good and get the job done.
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