- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# adc.h

Go to the documentation of this file.

    00001 /*This file is prepared for Doxygen automatic documentation generation.*/
    00013
    00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
    00015  *
    00016  * Redistribution and use in source and binary forms, with or without
    00017  * modification, are permitted provided that the following conditions are met:
    00018  *
    00019  * 1. Redistributions of source code must retain the above copyright notice,
    00020  * this list of conditions and the following disclaimer.
    00021  *
    00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00023  * this list of conditions and the following disclaimer in the documentation
    00024  * and/or other materials provided with the distribution.
    00025  *
    00026  * 3. The name of Atmel may not be used to endorse or promote products derived
    00027  * from this software without specific prior written permission.
    00028  *
    00029  * 4. This software may only be redistributed and used in connection with an Atmel
    00030  * AVR product.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */#ifndef ADC_H
    00043 #define ADC_H
    00044
    00045 //******************************************************************************
    00046 // ADC setup
    00047 //******************************************************************************
    00048
    00049 //IBAT measurement
    00050
    00051 #if (TARGET_BOARD == MEGAU4EK)
    00052   #define   R_SHUNT_OHMS 1
    00053   #define   R1_OHMS 10     // ADC1,ADC0 divider: R1*(R1 + R2)
    00054   #define   R2_OHMS 30
    00055   #define   VREF_I 246L    // ADC voltage reference for IBAT (x100)
    00056   #define   VREF_V 2462L   // ADC voltage reference for IBAT (x1000)
    00057 #endif
    00058
    00059 #if (TARGET_BOARD == BC101)
    00060   #define   R_SHUNT_OHMS 1
    00061   #define   R1_OHMS 13     // ADC1,ADC0 divider: R1*(R1 + R2)
    00062   #define   R2_OHMS 10
    00063   #define   VREF_I 256L    // ADC voltage reference for IBAT (x100)
    00064   #define   VREF_V 2560L   // ADC voltage reference for IBAT (x1000)
    00065
    00066 #endif
    00067
    00068 #if (TARGET_BOARD == EVK527)
    00069   #define   R_SHUNT_OHMS 1
    00070   #define   R1_OHMS 13     // ADC1,ADC0 divider: R1*(R1 + R2)
    00071   #define   R2_OHMS 10
    00072   #define   VREF_I 256L    // ADC voltage reference for IBAT (x100)
    00073   #define   VREF_V 2560L   // ADC voltage reference for IBAT (x1000)
    00074 #endif
    00075
    00076 #define ADC_GAIN 10         // ADC gain x10
    00077 #define ADC_ACCURACY 512L  // 8 bits accuracy in differential mode
    00078
    00079 //Result in mV x1000 = (vref x100)(ADC gain x10)
    00080 #define I_SCALE_1 ((R1_OHMS + R2_OHMS)*(VREF_I))
    00081 #define I_SCALE_2 (R_SHUNT_OHMS * R1_OHMS * ADC_ACCURACY)
    00082
    00083 #define VBAT_SCALE_1 (long)((R1_OHMS + R2_OHMS)*(VREF_V))
    00084 #define VBAT_SCALE_2  (long)(R1_OHMS * ADC_ACCURACY * 2)
    00085
    00086 //******************************************************************************
    00087 // Global variables
    00088 //******************************************************************************
    00089 //cgs extern __eeprom unsigned char VBAT_RANGE;
    00090 extern unsigned char VBAT_RANGE;
    00091 extern volatile ADC_Status_t ADCS;
    00092
    00093
    00094 //******************************************************************************
    00095 // Function prototypes
    00096 //******************************************************************************
    00097 #ifdef __GNUC__
    00098  ISR(ADC_vect);
    00099 #else
    00100 #pragma vector = ADC_vect
    00101 __interrupt void ADC_ISR(void);
    00102 #endif
    00103
    00104 unsigned int ScaleU(unsigned int data);
    00105 unsigned int ScaleI(unsigned int data);
    00106 void ADC_Wait(void);
    00107 void ADC_Init(void);
    00108
    00109 #endif // ADC_H