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

...12F683: ADC working at 8 bit instead of 10 bits

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



Joined: 02 Nov 2007
Posts: 26

View user's profile Send private message

...12F683: ADC working at 8 bit instead of 10 bits
PostPosted: Thu Jan 15, 2009 6:14 pm     Reply with quote

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);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 15, 2009 6:23 pm     Reply with quote

https://www.ccsinfo.com/forum/viewtopic.php?p=2073
PICman



Joined: 02 Nov 2007
Posts: 26

View user's profile Send private message

PostPosted: Thu Jan 15, 2009 6:39 pm     Reply with quote

Thanks a lot for this so fast response !
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