PICman
Joined: 02 Nov 2007 Posts: 26
|
...12F683: ADC working at 8 bit instead of 10 bits |
Posted: Thu Jan 15, 2009 6:14 pm |
|
|
Hi...
I'm beginning with the ADC in a PIC12F683...
Simplest design: One input and printout on serial port @ 9600,8,N,1
I put in a 20k trimpot between Vss and Vdd with wiper at pin 7 (An0) to test my setup with a screwdriver.
My bug is that i only get 8 bits ! The printout varies between 0x0000 and 0x00FF. 10 bits shall give me 0x0000 to 0x03FF.
I know, this is a newbie problem and i don't like to look as an annoying person, but i've read the CCS manual and the 12F683.h header and didn't find anything about the ADC resolution, and with a int16 variable for ADC output, it should give me a 10bit value (the 12F683 has a 10 bit ADC and i succedded in making the PWM work at 10 bits)
One last thing.... The manual (page 100) talks about an ADC_DONE interruption, but the compiler doesn't recognize it. Is there a way to initiate an interruption when the ADC has done it's work or is it better to simply add a delay after the "value=Read_ADC(ADC_START_AND_READ);" instruction ?
Thanks for your help !
Code: | /////////////////////////////////////////////////////////////////////////
// _________ _________ //
// __| \/ |__ //
// +5V |__|Vdd Vss|__| Masse //
// __| |__ //
// 8.0000 MHz |__|Ra5 Ra0/ICSPDAT|__| Entrée analogue (0) //
// __| |__ //
// Sortie 9600bps |__|Ra4 Ra1/ICSPCLK|__| //
// __| ____ |__ //
// +5V-/\/\-------|__|Ra3/MCLR/Vpp Ra2|__| //
// 47k |____________________| //
// //
// ADC: Premiers essais en ADC //
// ADC2: EC_IO @ 8.0000 MHz //
/////////////////////////////////////////////////////////////////////////
#include <12F683.h>
#FUSES WDT // Watch Dog Timer active
#FUSES EC_IO // External Osc with I/O
#FUSES NOCPD // No EE protection
#FUSES NOPROTECT // Code not protected from reading
#FUSES NOMCLR // No Master Clear on pin 4.
#FUSES PUT // Power Up Timer
#FUSES BROWNOUT // Reset when brownout detected
#FUSES IESO // Internal External Switch Over mode enabled
#FUSES FCMEN // Fail-safe clock monitor enabled
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A3,bits=8) // 9600,8,N 1
void main(void)
{
int16 value;
setup_port_a(sAN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0); // Lire An0 (broche 7)
do
{
delay_ms(50);
value=Read_ADC(ADC_START_AND_READ); //Lire Vin
printf("\n\r Value=%4lX",value); // Affiche "value" en HEX
restart_wdt(); // Woof !
}while (TRUE);
}
|
|
|