View previous topic :: View next topic |
Author |
Message |
jonnylazer
Joined: 10 Feb 2008 Posts: 7
|
PIC ADC |
Posted: Sun Feb 10, 2008 3:33 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 3:45 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 5:10 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 7:31 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 7:55 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 8:01 pm |
|
|
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
|
|
Posted: Sun Feb 10, 2008 8:23 pm |
|
|
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
|
|
Posted: Thu Feb 14, 2008 7:32 pm |
|
|
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
|
|
Posted: Thu Feb 14, 2008 10:24 pm |
|
|
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
|
|
Posted: Fri Feb 15, 2008 3:16 am |
|
|
Thanks PCM....should have posted my PM here. Anyway, thanks again. |
|
|
jonnylazer
Joined: 10 Feb 2008 Posts: 7
|
|
Posted: Fri Feb 15, 2008 3:20 am |
|
|
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
|
|
Posted: Fri Feb 15, 2008 8:37 am |
|
|
I would guess that is so your eyes can focus on each reading before it scrolls off the edge of the screen. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|