Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Robotics Chat


Robotics Chat Specific to discussions about robots and the making of.

Reply
 
Thread Tools Display Modes
Old 16th February 2008, 02:23 AM   (permalink)
Default Setting up ADC in PIC16F684

This is a discussion for setting up the ADC module in PIC16F684. For detail operation of ADC please refer to Microchip data.

There are five registers involved in ADC operation: ANSEL, ADCON0, ADCON1, ADRESH, ADRESL. We only need to set up ANSEL, ADCON0 and ADCON1. The conversion result will be stored in ADSEH and ADSEL.

Please refer to block diagram (from Microchip data):

ADC_Block.JPG

We will set up the registers in the order of the red numbers in the diagram.

HTML Code:
(1)  Select analogue input. In our example, we chosed pin 11 of the chip,    
      which is AN2.
        
                               ANSEL=  0b00000100;

(2) Set CHS bits in ADCON0 to select the channel to connect to sample and  
     hold circuit. 
                  
                               ADCON0 <4:2>  =    _ _ _  0 1 0 _ _

(3) Set voltage reference source in ADCON0<6>.  0= VDD, 1= Vref pin. We 
     choose VDD as reference. So,

                                ADCON0 <6> =    _ 0 _ _ _ _ _ _ 

(4) Initiate ADC module by setting "1" in  ADCON0 <0>  ( doesn't mean A/D 
     conversion starts).
     Set DO/DONE bit in ADCON0<1> to off, not starting conversion yet. 
     ADCON0<1>= 0.   So,

                                ADCON0<1:0> =  _ _ _ _ _ _ 0 1

(5) Set A/D conversion format, left or right justified, in ADCON0<7>. The 
     result of the conversion is in 10 bits and will be stored in  ADRESH and 
    ADRESL register.  Left justified is :  xxxxxxxx   xx000000
                                          ADRESH      ADRESL
                                  
                            Right justified is: 000000xx   xxxxxxxx
                                                 ADRESH      ADRESL
    We choose left justified, so
      
                                ADCON0 <7> =  0 _ _ _ _ _ _ _

    To sum up for ADCON0:

                                ADCON0= 0b00001001; 

  
The setting with reference to the block diagram is complete.
When we want to start the conversion, we simply set GO/DONE bit to 1, ie 

(6)                             GODONE= 1;

 Next we have to set the conversion clock:

(7) Set the A/D conversion clock  (TAD)  in ADCON1 <6:4>.
     We have to ensure a mimimum of 1.6 uS TAD for proper A/D  operation.  
     For 4 MHz device frequency, we should select 8 Tosc (2.0 uS, which is >  
     minimum  requirement).  ADCON1 <6:4> =  001.   

                                 ADCON1= 00010000;  
      
     If we don't want to calulate this value, we can just set ADCON1 <6:4> to 
     x11. The TAD is 4 uS with this setting. 


To sum it all up, we only need three C statments to set up the ADC. 
Analogue input= AN2
Voltage reference source= VDD
Device OSC= 4MHz

C statments:
                 
                 
                     ANSEL=  0b00000100;
                     ADCON0= 0b00001001; 
                     ADCON1= 00010000;  
             
Note, the ADC setting for this chip is different to 16F87x.

Next we will use this setting and connect a POT to AN2 to control 8 LEDs......

PS.Can someone please tell me how to attach a bigger picture on the same page.
__________________
May the force be with you.


My project: Simple White Line Follower

http://au.youtube.com/watch?v=8Z_MmrdH4oc

http://i271.photobucket.com/albums/j...nefollower.jpg

Last edited by Wingmax; 16th February 2008 at 05:07 AM.
Wingmax is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
PIC12F675 ADC Circuit help. MERV Micro Controllers 4 16th January 2008 08:05 PM
ADC troubles andy257 General Electronics Chat 4 2nd December 2007 05:49 PM
Using Oscilloscopes mechie Electronic Theory 9 29th November 2007 09:48 PM
HS1101 capacitive humidity sensor; need nearly linear voltage to feed to a 1-wire ADC FirefighterBlu3 Electronic Projects Design/Ideas/Reviews 5 19th October 2007 11:06 PM
16F877 Timer0 Interrupt Affecting ADC sebana Micro Controllers 13 12th September 2007 09:42 AM



All times are GMT. The time now is 06:38 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.