ATMEL: adc_drv.h Source File

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

# adc_drv.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  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00031  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00039  */
    00040
    00041 #ifndef ADC_DRV_H
    00042 #define ADC_DRV_H
    00043
    00044 //_____ I N C L U D E S ____________________________________________________
    00045
    00046 #ifndef  ADHSM
    00047 #define  ADHSM   7
    00048 #endif
    00049
    00053 //_____ M A C R O S ________________________________________________________
    00054
    00058
    00062 #define Enable_adc()                         (ADCSRA |= (1<<ADEN))
    00064
    00068 #define Right_adjust_adc_result()            (ADMUX  &= ~(1<<ADLAR))
    00069 #define Left_adjust_adc_result()             (ADMUX  |=  (1<<ADLAR))
    00071
    00075 #define Enable_adc_high_speed_mode()         (ADCSRB |=  (1<<ADHSM))
    00076 #define Disable_adc_high_speed_mode()        (ADCSRB &= ~(1<<ADHSM))
    00078
    00079
    00083 #define Enable_internal_vref()               (ADMUX  |=  ((1<<REFS1)|(1<<REFS0)) )
    00084 #define Enable_external_vref()               (ADMUX  &= ~((1<<REFS1)|(1<<REFS0)) )
    00085 #define Enable_vcc_vref()                    (ADMUX  &= ~(1<<REFS1),          \
    00086                                               ADMUX  |=  (1<<REFS0) )
    00088
    00092 #define Enable_all_it()                      (SREG   |=  (0x80) )
    00093 #define Disable_all_it()                     (SREG   &= ~(0x80) )
    00094 #define Enable_adc_it()                      (ADCSRA |=  (1<<ADIE) )
    00095 #define Disable_adc_it()                     (ADCSRA &= ~(1<<ADIE) )
    00096 #define Clear_adc_flag()                     (ADCSRA &=  (1<<ADIF) )
    00098
    00102 #define Set_prescaler(prescaler)             (ADCSRA &= ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)),\
    00103                                               ADCSRA |=  (prescaler) )
    00105
    00109 #define Clear_adc_mux()                      (ADMUX  &= ~((1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0)) )
    00110 #define Select_adc_channel(channel)          (Clear_adc_mux(), ADMUX |= (channel) )
    00112
    00116
    00120 #define Start_conv()                          (ADCSRA |= (1<<ADSC) )
    00121 #define Start_conv_channel(channel)           (Select_adc_channel(channel), Start_conv() )
    00122 #define Start_amplified_conv()                (ADCSRB |= (1<<ADASCR) )
    00123 #define Stop_amplified_conv()                 (ADCSRB &= ~(1<<ADASCR) )
    00124 #define Start_amplified_conv_channel(channel) (Select_adc_channel(channel), Start_amplified_conv() )
    00126
    00130 #define Start_conv_idle()                    (SMCR   |=  (1<<SM0)|(1<<SE) )
    00131 #define Start_conv_idle_channel(channel)     (Select_adc_channel(channel), Start_conv_idle() )
    00132 #define Clear_sleep_mode()                   (SMCR   &= ~(1<<SM0)|(1<<SE) )
    00134
    00136
    00140 #define Adc_get_8_bits_result()               ((U8)(ADCH))
    00141 #define Adc_get_10_bits_result()              ((U16)(ADCL+((U16)(ADCH<<8))))
    00143
    00144
    00148 #define Disable_adc()                        (ADCSRA &= ~(1<<ADEN))
    00150
    00154 #define Is_adc_conv_finished()               ((ADCSRA &  (1<<ADIF)) ? TRUE : FALSE)
    00155 #define Is_adc_conv_not_finished()           ((ADCSRA | ~(1<<ADIF)) ? TRUE : FALSE)
    00157
    00159
    00160 //_____ D E F I N I T I O N S ______________________________________________
    00161
    00162 //_____ F U N C T I O N S __________________________________________________
    00166
    00171 void init_adc(void);
    00173
    00175
    00176 #endif  // ADC_DRV_H