|
|
View previous topic :: View next topic |
Author |
Message |
Nicolas
Joined: 29 Apr 2007 Posts: 4
|
odd behaviour 16f88 and adc |
Posted: Sun Apr 29, 2007 10:10 pm |
|
|
Odd behaviour with a 16f88 and using the built in adc.
For testing, just reading an AN1 and putting out the value to the pc via serial port. Using the internal rc (8mhz)
When I connect VDD to AN1, the ADC returns 990-992 (varies). Not the expected 1023. VSS to AN1 does return 0 properly.
The only way I can get it to return 1023 is if i apply a voltage Higher than VDD to AN1.
I tried running at 3.3v and 5v.
The voltage is stabalized with a 0.1uf cap and a 10uf cap.
Tried 3 different PIC's, same results.
(In simulation, it does properly return 1023)
Code: |
#include <16f88.h>
#fuses NOMCLR, NOBROWNOUT,INTRC_IO,NOFCMEN,NOIESO
#device adc = 10
#use delay(clock=8000000,internal) //8mhz
#use rs232(baud=4800, xmit=PIN_B6, rcv=PIN_B7,invert) //For testing
void main () {
long in_adc;
delay_ms(500); //Since using intrc+mclr is off - to allow programming
setup_adc_ports(sAN1|VSS_VDD );
setup_adc(ADC_CLOCK_INTERNAL );
delay_us(10);
set_adc_channel(1);
delay_us(10);
in_adc = read_adc();
printf("%Lu",in_adc);
}
|
Any ideas ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 29, 2007 11:03 pm |
|
|
Read this section of the 16F88 data sheet:
Quote: | Selecting the A/D Conversion Clock |
It says don't use the internal RC clock for the A/D. Instead use Fosc,
with the "Divide by 8" divisor. In other words, do this:
Code: | setup_adc(ADC_CLOCK_DIV_8); |
|
|
|
Nicolas
Joined: 29 Apr 2007 Posts: 4
|
|
Posted: Sun Apr 29, 2007 11:35 pm |
|
|
Thanks for the incredibly fast response.
Tried variouse different ADC_CLOCK's and still the same problem.
No change at all, which is somewhat strange.
Mind you that was using the Internal oscillator (8mhz).
I just tried an external OSC, and it works 100%.
Possibly the internal OSC is not tuned properly, or the ADC doesnt like running with an internal OSC. |
|
|
Nicolas
Joined: 29 Apr 2007 Posts: 4
|
|
Posted: Sun Apr 29, 2007 11:43 pm |
|
|
I moved the Serial lines, from B7/B6 to B4/B5
and used internal OSC.
It works 100% now.
New (works properly)
Code: |
#use rs232(baud=4800, xmit=PIN_B4, rcv=PIN_B5,invert) //For testing
|
Old: (doesnt work properly)
Code: |
#use rs232(baud=4800, xmit=PIN_B6, rcv=PIN_B7,invert) //For testing
|
I will have to investigate if its a PIC thing, or a CCS thing.
(Could have to do with RB6/7 being analog capable) |
|
|
Nicolas
Joined: 29 Apr 2007 Posts: 4
|
|
Posted: Mon Apr 30, 2007 12:07 am |
|
|
So i narrowed it down to the RS232 converter i was using.
The converter was not properly controlling the RCV line on the PC and was feeding a -12v to the pic, oviously because of the MUX on the AN lines, it caused weird problems.
In my case, incorrect ADC readings.
Thanks PCM Programmer, your suggestion has also reduced my TAD to almost perfect timing, so the ADC conversion is even more accurate now. |
|
|
|
|
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
|