adc_internal.h

00001 /* 
00002 
00003   @file adc_internal.h
00004   
00005   @author Nicolas Champagne-Williamson
00006 
00007 */
00008 
00009 #ifndef __H_ADC_INT__
00010 #define __H_ADC_INT__
00011 
00012 
00016 typedef struct adci_exponential_filter{
00017   int average; 
00018   int count; 
00019   char coeff; 
00020 } ADCI_FILTER;
00021 
00025 typedef enum adci_channels{
00026   ADCI_CH_0 = 0,
00027   ADCI_CH_1,
00028   ADCI_CH_2,
00029   ADCI_CH_3
00030 } ADCI_CHAN;
00031 
00035 typedef enum adci_stati{
00036   ADCI_DONE = 0, 
00037   ADCI_NOT_DONE 
00038 } ADCI_STATUS;
00039 
00040 #define ADCI_NULL (-1) 
00041 #define ADCI_NO_FILTER (0) 
00044 // ********** Function Declarations **********
00045 //Public Functions
00046 void adci_init(int coeff0, int coeff1, int coeff2, int coeff3);
00047 int adci_get_result(ADCI_CHAN channel); //Returns the int value from the given channel's filter
00048 void adci_convert_all(void); //Converts the given channel and adds the value to the filter
00049 void adci_isr(void) __irq; //interrupt called when an ADC conversion has completed
00050 //Private Functions
00051 void adci_efilter_add(volatile ADCI_FILTER *f, short num); //Adds the given value to the given filter
00052 void adci_init_channel(ADCI_CHAN chan, int coeff); //initializes the adci channel
00053 volatile ADCI_FILTER* adci_get_filter(ADCI_CHAN); //returns the filter of the given channel
00054 void adci_convert_next(void);
00055 
00056 
00057 /* HARDWARE SOURCE SETUP - Only put channels you wish to read from.
00058   
00059   // *******************************************************************************
00060   // Initialize Internal ADC 
00061   // *******************************************************************************
00062   //Burst mode setup (old)
00063   //ADCR = 0x0021C700|(ADCI_CH0_READ)|(ADCI_CH1_READ << 1)|(ADCI_CH2_READ << 2)|(ADCI_CH3_READ << 3);
00064   //Interrupt driven setup - CLKDIV = 199; bit21 is ADC enabled; 
00065   //Which channels to read from; if you want to read from a channel, set its value to 1
00066   #define ADCI_CH0_READ 0
00067   #define ADCI_CH1_READ 0
00068   #define ADCI_CH2_READ 0
00069   #define ADCI_CH3_READ 0
00070   ADCR = (1<<21)|(199<<8) & ~ADCR_RB;
00071   //Set Pins to be AINx if reading from that channel
00072   if (ADCI_CH0_READ) {
00073     PINSEL1 &= ~(3<<22);
00074     PINSEL1 |= (1<<22);
00075   }  //AIN0 on pin P0.27
00076   if (ADCI_CH1_READ) {
00077     PINSEL1 &= ~(3<<24);
00078     PINSEL1 |= (1<<24);
00079   }  //AIN1 on pin P0.28 
00080   if (ADCI_CH2_READ) {
00081     PINSEL1 &= ~(3<<26);
00082     PINSEL1 |= (1<<26);
00083   }  //AIN2 on pin P0.29
00084   if (ADCI_CH3_READ) {
00085     PINSEL1 &= ~(3<<28);
00086     PINSEL1 |= (1<<28);
00087   }  //AIN3 on pin P0.30  
00088   //adci interrupts for conversion completions
00089   ADINTEN = (1<<8)//(ADCI_CH0_READ)|(ADCI_CH1_READ << 1)|(ADCI_CH2_READ << 2)|(ADCI_CH3_READ << 3)
00090       & ~ADINTEN_RB;
00091 
00092 */
00093 
00094 #endif
00095 
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3