STM8L15x Standard Peripherals Drivers: stm8l15x_adc.h Source File

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

stm8l15x_adc.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8l15x_adc.h
00004   * @author  MCD Application Team
00005   * @version V1.5.0
00006   * @date    13-May-2011
00007   * @brief   This file contains all the functions prototypes for the ADC 
00008   *          firmware library.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00013   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00014   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00015   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00016   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00017   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00018   *
00019   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00020   ******************************************************************************  
00021   */
00022 
00023 /* Define to prevent recursive inclusion -------------------------------------*/
00024 #ifndef __STM8L15x_ADC_H
00025 #define __STM8L15x_ADC_H
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm8l15x.h"
00029 
00030 /** @addtogroup STM8L15x_StdPeriph_Driver
00031   * @{
00032   */
00033   
00034 /** @addtogroup ADC
00035   * @{
00036   */ 
00037 /* Exported types ------------------------------------------------------------*/
00038 
00039 /** @defgroup ADC_Exported_Types
00040   * @{
00041   */
00042 
00043 
00044 /** @defgroup ADC_Channels 
00045   * @{
00046   */
00047 typedef enum
00048 {
00049   ADC_Channel_0           = ((uint16_t)0x0301), /*!< Channel 00 */
00050   ADC_Channel_1           = ((uint16_t)0x0302), /*!< Channel 01 */
00051   ADC_Channel_2           = ((uint16_t)0x0304), /*!< Channel 02 */
00052   ADC_Channel_3           = ((uint16_t)0x0308), /*!< Channel 03 */
00053   ADC_Channel_4           = ((uint16_t)0x0310), /*!< Channel 04 */
00054   ADC_Channel_5           = ((uint16_t)0x0320), /*!< Channel 05 */
00055   ADC_Channel_6           = ((uint16_t)0x0340), /*!< Channel 06 */
00056   ADC_Channel_7           = ((uint16_t)0x0380), /*!< Channel 07 */
00057 
00058   ADC_Channel_8           = ((uint16_t)0x0201), /*!< Channel 08 */
00059   ADC_Channel_9           = ((uint16_t)0x0202), /*!< Channel 09 */
00060   ADC_Channel_10          = ((uint16_t)0x0204), /*!< Channel 10 */
00061   ADC_Channel_11          = ((uint16_t)0x0208), /*!< Channel 11 */
00062   ADC_Channel_12          = ((uint16_t)0x0210), /*!< Channel 12 */
00063   ADC_Channel_13          = ((uint16_t)0x0220), /*!< Channel 13 */
00064   ADC_Channel_14          = ((uint16_t)0x0240), /*!< Channel 14 */
00065   ADC_Channel_15          = ((uint16_t)0x0280), /*!< Channel 15 */
00066 
00067   ADC_Channel_16          = ((uint16_t)0x0101), /*!< Channel 16 */
00068   ADC_Channel_17          = ((uint16_t)0x0102), /*!< Channel 17 */
00069   ADC_Channel_18          = ((uint16_t)0x0104), /*!< Channel 18 */
00070   ADC_Channel_19          = ((uint16_t)0x0108), /*!< Channel 19 */
00071   ADC_Channel_20          = ((uint16_t)0x0110), /*!< Channel 20 */
00072   ADC_Channel_21          = ((uint16_t)0x0120), /*!< Channel 21 */
00073   ADC_Channel_22          = ((uint16_t)0x0140), /*!< Channel 22 */
00074   ADC_Channel_23          = ((uint16_t)0x0180), /*!< Channel 23 */
00075 
00076   ADC_Channel_24          = ((uint16_t)0x0001), /*!< Channel 24 */
00077   ADC_Channel_25          = ((uint16_t)0x0002), /*!< Channel 25 */
00078   ADC_Channel_26          = ((uint16_t)0x0004), /*!< Channel 26 */
00079   ADC_Channel_27          = ((uint16_t)0x0008), /*!< Channel 27 */
00080 
00081   ADC_Channel_Vrefint     = ((uint16_t)0x0010), /*!< Vrefint Channel  */
00082   ADC_Channel_TempSensor  = ((uint16_t)0x0020), /*!< Temperature sensor Channel  */
00083 
00084   /* combination*/
00085   ADC_Channel_00To07      = ((uint16_t)0x03FF), /*!<select from channel00 to channel07 */
00086   ADC_Channel_08To15      = ((uint16_t)0x02FF), /*!<select from channel08 to channel15 */
00087   ADC_Channel_16To23      = ((uint16_t)0x01FF), /*!<select from channel16 to channel23 */
00088   ADC_Channel_24To27      = ((uint16_t)0x00FF)  /*!<select from channel24 to channel27 */
00089 
00090 }ADC_Channel_TypeDef;
00091 
00092 /**
00093   * @}
00094   */
00095   
00096 /** @defgroup ADC_Conversion_Mode
00097   * @{
00098   */
00099 typedef enum
00100 {
00101   ADC_ConversionMode_Single     = ((uint8_t)0x00), /*!< Single Conversion Mode */
00102   ADC_ConversionMode_Continuous = ((uint8_t)0x04)  /*!< Continuous Conversion Mode */
00103 }ADC_ConversionMode_TypeDef;
00104 
00105 #define IS_ADC_CONVERSION_MODE(MODE) (((MODE) == ADC_ConversionMode_Single) || \
00106                                       ((MODE) == ADC_ConversionMode_Continuous))
00107 /**
00108   * @}
00109   */
00110   
00111 /** @defgroup ADC_Resolution
00112   * @{
00113   */
00114 typedef enum
00115 {
00116   ADC_Resolution_12Bit = ((uint8_t)0x00), /*!< 12 bit resolution */
00117   ADC_Resolution_10Bit = ((uint8_t)0x20), /*!< 10 bit resolution */
00118   ADC_Resolution_8Bit  = ((uint8_t)0x40), /*!<  8 bit resolution */
00119   ADC_Resolution_6Bit  = ((uint8_t)0x60)  /*!<  6 bit resolution */
00120 }ADC_Resolution_TypeDef;
00121 
00122 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_Resolution_12Bit) || \
00123                                        ((RESOLUTION) == ADC_Resolution_10Bit) || \
00124                                        ((RESOLUTION) == ADC_Resolution_8Bit) || \
00125                                        ((RESOLUTION) == ADC_Resolution_6Bit))
00126 /**
00127   * @}
00128   */
00129   
00130 /** @defgroup ADC_Clock_Prescaler
00131   * @{
00132   */
00133 typedef enum
00134 {
00135   ADC_Prescaler_1 = ((uint8_t)0x00), /*!< ADC Clock frequency is divided by 1 */
00136   ADC_Prescaler_2 = ((uint8_t)0x80)  /*!< ADC Clock frequency is divided by 2 */
00137 }ADC_Prescaler_TypeDef;
00138 
00139 #define IS_ADC_PRESCALER(PRESCALER) (((PRESCALER) == ADC_Prescaler_1) || \
00140                                      ((PRESCALER) == ADC_Prescaler_2))
00141 /**
00142   * @}
00143   */
00144   
00145 /** @defgroup ADC_External_Trigger_Sensitivity
00146   * @{
00147   */
00148 typedef enum
00149 {
00150   ADC_ExtTRGSensitivity_Rising  = ((uint8_t)0x20), /*!< External Trigger Sensitivity is Rising Edge */
00151   ADC_ExtTRGSensitivity_Falling = ((uint8_t)0x40), /*!< External Trigger Sensitivity is Falling Edge */
00152   ADC_ExtTRGSensitivity_All     = ((uint8_t)0x60)  /*!< External Trigger Sensitivity is Falling and Rising Edge */
00153 }ADC_ExtTRGSensitivity_TypeDef;
00154 
00155 #define IS_ADC_EXT_TRG_SENSITIVITY(SENSITIVITY) (((SENSITIVITY) == ADC_ExtTRGSensitivity_Rising) || \
00156                                                  ((SENSITIVITY) == ADC_ExtTRGSensitivity_Falling) || \
00157                                                  ((SENSITIVITY) == ADC_ExtTRGSensitivity_All))
00158 /**
00159   * @}
00160   */
00161   
00162 /** @defgroup ADC_External_Event_Source_Selection
00163   * @{
00164   */
00165 typedef enum
00166 {
00167   ADC_ExtEventSelection_None     = ((uint8_t)0x00), /*!< Conversion starts only by software start */
00168   ADC_ExtEventSelection_Trigger1 = ((uint8_t)0x08), /*!< Trigger 1  Enables conversion */
00169   ADC_ExtEventSelection_Trigger2 = ((uint8_t)0x10), /*!< Trigger 2 Enables conversion */
00170   ADC_ExtEventSelection_Trigger3 = ((uint8_t)0x18)  /*!< Trigger 3 Enables conversion */
00171 }ADC_ExtEventSelection_TypeDef;
00172 
00173 #define IS_ADC_EXT_EVENT_SELECTION(SELECTION) (((SELECTION) == ADC_ExtEventSelection_None) || \
00174                                                ((SELECTION) == ADC_ExtEventSelection_Trigger1) || \
00175                                                ((SELECTION) == ADC_ExtEventSelection_Trigger2) || \
00176                                                ((SELECTION) == ADC_ExtEventSelection_Trigger3))
00177 /**
00178   * @}
00179   */
00180   
00181 /** @defgroup ADC_Group_Channel_Definition
00182   * @{
00183   */
00184 typedef enum
00185 {
00186   ADC_Group_SlowChannels = ((uint8_t)0x00), /*!<Slow Channels group(Channel 0 to 23) */
00187   ADC_Group_FastChannels = ((uint8_t)0x01)  /*!<Fast Channels group Channel 24 to 27, 
00188                                                 Channel Vrefint, Channel TempSensor)*/
00189 }ADC_Group_TypeDef;
00190 
00191 #define IS_ADC_GROUP(GROUP) (((GROUP) == ADC_Group_SlowChannels) || \
00192                              ((GROUP) == ADC_Group_FastChannels))
00193 /**
00194   * @}
00195   */
00196   
00197 /** @defgroup ADC_Sampling_Time
00198   * @{
00199   */
00200 typedef enum
00201 {
00202   ADC_SamplingTime_4Cycles   = ((uint8_t)0x00), /*!< Sampling Time Cycles is 4 */
00203   ADC_SamplingTime_9Cycles   = ((uint8_t)0x01), /*!< Sampling Time Cycles is 9 */
00204   ADC_SamplingTime_16Cycles  = ((uint8_t)0x02), /*!< Sampling Time Cycles is 16 */
00205   ADC_SamplingTime_24Cycles  = ((uint8_t)0x03), /*!< Sampling Time Cycles is 24 */
00206   ADC_SamplingTime_48Cycles  = ((uint8_t)0x04), /*!< Sampling Time Cycles is 48 */
00207   ADC_SamplingTime_96Cycles  = ((uint8_t)0x05), /*!< Sampling Time Cycles is 96 */
00208   ADC_SamplingTime_192Cycles = ((uint8_t)0x06), /*!< Sampling Time Cycles is 192 */
00209   ADC_SamplingTime_384Cycles = ((uint8_t)0x07)  /*!< Sampling Time Cycles is 384 */
00210 }ADC_SamplingTime_TypeDef;
00211 
00212 #define IS_ADC_SAMPLING_TIME_CYCLES(TIME) (((TIME) == ADC_SamplingTime_4Cycles) || \
00213                                            ((TIME) == ADC_SamplingTime_9Cycles) || \
00214                                            ((TIME) == ADC_SamplingTime_16Cycles) || \
00215                                            ((TIME) == ADC_SamplingTime_24Cycles) || \
00216                                            ((TIME) == ADC_SamplingTime_48Cycles) || \
00217                                            ((TIME) == ADC_SamplingTime_96Cycles) || \
00218                                            ((TIME) == ADC_SamplingTime_192Cycles) || \
00219                                            ((TIME) == ADC_SamplingTime_384Cycles))
00220 /**
00221   * @}
00222   */
00223   
00224 /** @defgroup  ADC_Analog_WatchDog_Channel_selection
00225   * @{
00226   */
00227 typedef enum
00228 {
00229   ADC_AnalogWatchdogSelection_Channel0  = ((uint8_t)0x00), /*!< AWD affected to Channel 0 */
00230   ADC_AnalogWatchdogSelection_Channel1  = ((uint8_t)0x01), /*!< AWD affected to Channel 1 */
00231   ADC_AnalogWatchdogSelection_Channel2  = ((uint8_t)0x02), /*!< AWD affected to Channel 2 */
00232   ADC_AnalogWatchdogSelection_Channel3  = ((uint8_t)0x03), /*!< AWD affected to Channel 3 */
00233   ADC_AnalogWatchdogSelection_Channel4  = ((uint8_t)0x04), /*!< AWD affected to Channel 4 */
00234   ADC_AnalogWatchdogSelection_Channel5  = ((uint8_t)0x05), /*!< AWD affected to Channel 5 */
00235   ADC_AnalogWatchdogSelection_Channel6  = ((uint8_t)0x06), /*!< AWD affected to Channel 6 */
00236   ADC_AnalogWatchdogSelection_Channel7  = ((uint8_t)0x07), /*!< AWD affected to Channel 7 */
00237   ADC_AnalogWatchdogSelection_Channel8  = ((uint8_t)0x08), /*!< AWD affected to Channel 8 */
00238   ADC_AnalogWatchdogSelection_Channel9  = ((uint8_t)0x09), /*!< AWD affected to Channel 9 */
00239   ADC_AnalogWatchdogSelection_Channel10 = ((uint8_t)0x0A), /*!< AWD affected to Channel 10 */
00240   ADC_AnalogWatchdogSelection_Channel11 = ((uint8_t)0x0B), /*!< AWD affected to Channel 11 */
00241   ADC_AnalogWatchdogSelection_Channel12 = ((uint8_t)0x0C), /*!< AWD affected to Channel 12 */
00242   ADC_AnalogWatchdogSelection_Channel13 = ((uint8_t)0x0D), /*!< AWD affected to Channel 13 */
00243   ADC_AnalogWatchdogSelection_Channel14 = ((uint8_t)0x0E), /*!< AWD affected to Channel 14 */
00244   ADC_AnalogWatchdogSelection_Channel15 = ((uint8_t)0x0F), /*!< AWD affected to Channel 15 */
00245   ADC_AnalogWatchdogSelection_Channel16 = ((uint8_t)0x10), /*!< AWD affected to Channel 16 */
00246   ADC_AnalogWatchdogSelection_Channel17 = ((uint8_t)0x11), /*!< AWD affected to Channel 17 */
00247   ADC_AnalogWatchdogSelection_Channel18 = ((uint8_t)0x12), /*!< AWD affected to Channel 18 */
00248   ADC_AnalogWatchdogSelection_Channel19 = ((uint8_t)0x13), /*!< AWD affected to Channel 19 */
00249   ADC_AnalogWatchdogSelection_Channel20 = ((uint8_t)0x14), /*!< AWD affected to Channel 20 */
00250   ADC_AnalogWatchdogSelection_Channel21 = ((uint8_t)0x15), /*!< AWD affected to Channel 21 */
00251   ADC_AnalogWatchdogSelection_Channel22 = ((uint8_t)0x16), /*!< AWD affected to Channel 22 */
00252   ADC_AnalogWatchdogSelection_Channel23 = ((uint8_t)0x17), /*!< AWD affected to Channel 23 */
00253 
00254   ADC_AnalogWatchdogSelection_Channel24  = ((uint8_t)0x18), /*!< AWD affected to Channel 24 */
00255   ADC_AnalogWatchdogSelection_Channel25  = ((uint8_t)0x19), /*!< AWD affected to Channel 25 */
00256   ADC_AnalogWatchdogSelection_Channel26  = ((uint8_t)0x1A), /*!< AWD affected to Channel 26 */
00257   ADC_AnalogWatchdogSelection_Channel27  = ((uint8_t)0x1B), /*!< AWD affected to Channel 27 */
00258 
00259   ADC_AnalogWatchdogSelection_Vrefint    = ((uint8_t)0x1C), /*!< AWD affected to Internal Vref Channel  */
00260   ADC_AnalogWatchdogSelection_TempSensor = ((uint8_t)0x1D)  /*!< AWD affected to Temperature Sensor Channel */
00261 }ADC_AnalogWatchdogSelection_TypeDef;
00262 
00263 #define IS_ADC_ANALOGWATCHDOG_SELECTION(CHANNEL) (((CHANNEL) <= 0x1D))
00264 /**
00265   * @}
00266   */
00267   
00268 /** @defgroup  ADC_Interrupts
00269   * @{
00270   */
00271 typedef enum
00272 {
00273   ADC_IT_EOC  = ((uint8_t)0x08), /*!< End of Conversion  Interrupt  */
00274   ADC_IT_AWD  = ((uint8_t)0x10), /*!< Analog WatchDog  Interrupt  */
00275   ADC_IT_OVER = ((uint8_t)0x80)  /*!< Over Run Interrupt  */
00276 }ADC_IT_TypeDef;
00277 
00278 #define IS_ADC_IT(IT) ((((IT) & (uint8_t)0x67) == 0x00) && ((IT) != 0x00))
00279 #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
00280                            ((IT) == ADC_IT_OVER))
00281 /**
00282   * @}
00283   */
00284   
00285 /** @defgroup  ADC_Flags
00286   * @{
00287   */
00288 typedef enum
00289 {
00290   ADC_FLAG_EOC  = ((uint8_t)0x01), /*!< End of Conversion  flag  */
00291   ADC_FLAG_AWD  = ((uint8_t)0x02), /*!< Analog WatchDog  flag  */
00292   ADC_FLAG_OVER = ((uint8_t)0x04)  /*!< Over Run flag  */
00293 }ADC_FLAG_TypeDef;
00294 
00295 #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xF8) == 0x00) && ((FLAG) != 0x00))
00296 #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_EOC) || ((FLAG) == ADC_FLAG_AWD) || \
00297                                ((FLAG) == ADC_FLAG_OVER))
00298 /**
00299   * @}
00300   */
00301 
00302 /**
00303   * @}
00304   */
00305 /* Exported constants --------------------------------------------------------*/  
00306 /* Exported Macros -----------------------------------------------------------*/
00307 /** @defgroup ADC_Exported_Macros
00308   * @{
00309   */
00310 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
00311 
00312 /**
00313   * @}
00314   */
00315 
00316 /* Exported functions --------------------------------------------------------*/
00317   
00318 /*  Function used to set the ADC configuration to the default reset state *****/
00319 void ADC_DeInit(ADC_TypeDef* ADCx);
00320 
00321 /* Initialization and Configuration functions *********************************/ 
00322 void ADC_Init(ADC_TypeDef* ADCx,
00323               ADC_ConversionMode_TypeDef ADC_ConversionMode,
00324               ADC_Resolution_TypeDef ADC_Resolution,
00325               ADC_Prescaler_TypeDef ADC_Prescaler);
00326 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00327 void ADC_SoftwareStartConv(ADC_TypeDef* ADCx);
00328 void ADC_ExternalTrigConfig(ADC_TypeDef* ADCx,
00329                             ADC_ExtEventSelection_TypeDef ADC_ExtEventSelection,
00330                             ADC_ExtTRGSensitivity_TypeDef ADC_ExtTRGSensitivity);
00331                             
00332 /* Analog Watchdog configuration functions ************************************/
00333 void ADC_AnalogWatchdogChannelSelect(ADC_TypeDef* ADCx,
00334                                      ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection);
00335 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
00336                                         uint16_t LowThreshold);
00337 void ADC_AnalogWatchdogConfig(ADC_TypeDef* ADCx,
00338                               ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection,
00339                               uint16_t HighThreshold,
00340                               uint16_t LowThreshold);
00341 
00342 /* Temperature Sensor & Vrefint (Voltage Reference internal) management functions */
00343 void ADC_TempSensorCmd(FunctionalState NewState);
00344 void ADC_VrefintCmd(FunctionalState NewState);
00345 
00346 /* Channels Configuration functions *******************************************/                              
00347 void ADC_ChannelCmd(ADC_TypeDef* ADCx, ADC_Channel_TypeDef ADC_Channels,
00348                     FunctionalState NewState);
00349 
00350 void ADC_SamplingTimeConfig(ADC_TypeDef* ADCx, ADC_Group_TypeDef ADC_GroupChannels,
00351                             ADC_SamplingTime_TypeDef ADC_SamplingTime);
00352 void ADC_SchmittTriggerConfig(ADC_TypeDef* ADCx, ADC_Channel_TypeDef ADC_Channels,
00353                               FunctionalState NewState);
00354 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
00355 
00356 
00357 
00358 /* Channels DMA Configuration function ****************************************/
00359 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00360 
00361 /* Interrupts and flags management functions **********************************/
00362 void ADC_ITConfig(ADC_TypeDef* ADCx, 
00363                   ADC_IT_TypeDef ADC_IT, 
00364                   FunctionalState NewState);
00365 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, ADC_FLAG_TypeDef ADC_FLAG);
00366 void ADC_ClearFlag(ADC_TypeDef* ADCx, ADC_FLAG_TypeDef ADC_FLAG);
00367 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, ADC_IT_TypeDef ADC_IT);
00368 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, ADC_IT_TypeDef ADC_IT);
00369 
00370 #endif /*__STM8L15x_ADC_H */
00371 
00372 /**
00373   * @}
00374   */
00375 
00376 /**
00377   * @}
00378   */
00379 
00380 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com