Mini51 BSP  V3.02.002
The Board Support Package for Mini51 Series
adc.c
Go to the documentation of this file.
1 /**************************************************************************/
12 #include "Mini51Series.h"
13 
38 void ADC_Open(ADC_T *adc,
39  uint32_t u32InputMode,
40  uint32_t u32OpMode,
41  uint32_t u32ChMask)
42 {
43 
44  ADC->ADCR = 0; // A clean start.
45  ADC->ADCHER = (ADC->ADCHER & ~ADC_ADCHER_CHEN_Msk) | u32ChMask;
46  return;
47 }
48 
54 void ADC_Close(ADC_T *adc)
55 {
56  SYS->IPRSTC2 |= SYS_IPRSTC2_ADC_RST_Msk;
57  SYS->IPRSTC2 &= ~SYS_IPRSTC2_ADC_RST_Msk;
58  return;
59 
60 }
61 
77  uint32_t u32Source,
78  uint32_t u32Param)
79 {
81  if(u32Source == ADC_TRIGGER_BY_EXT_PIN)
82  {
83  ADC->ADCR |= u32Source | u32Param | ADC_ADCR_TRGEN_Msk;
84  }
85  else
86  {
87  ADC->ADTDCR = (ADC->ADTDCR & ~ADC_ADTDCR_PTDT_Msk) | u32Param;
88  ADC->ADCR |= u32Source | ADC_ADCR_TRGEN_Msk;
89  }
90  return;
91 }
92 
99 {
101  return;
102 }
103 
124  uint32_t u32ChNum,
125  uint32_t u32SampleTime)
126 {
127  ADC->ADSAMP = (ADC->ADSAMP & ~ADC_ADSAMP_SAMPCNT_Msk) | u32SampleTime;
128 }
129 
141 void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
142 {
143  if(u32Mask & ADC_ADF_INT)
144  ADC->ADCR |= ADC_ADCR_ADIE_Msk;
145  if(u32Mask & ADC_CMP0_INT)
146  ADC->ADCMPR[0] |= ADC_ADCMPR_CMPIE_Msk;
147  if(u32Mask & ADC_CMP1_INT)
148  ADC->ADCMPR[1] |= ADC_ADCMPR_CMPIE_Msk;
149 
150  return;
151 }
152 
164 void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
165 {
166  if(u32Mask & ADC_ADF_INT)
167  ADC->ADCR &= ~ADC_ADCR_ADIE_Msk;
168  if(u32Mask & ADC_CMP0_INT)
169  ADC->ADCMPR[0] &= ~ADC_ADCMPR_CMPIE_Msk;
170  if(u32Mask & ADC_CMP1_INT)
171  ADC->ADCMPR[1] &= ~ADC_ADCMPR_CMPIE_Msk;
172 
173  return;
174 }
175 
176 
177  /* end of group MINI51_ADC_EXPORTED_FUNCTIONS */
179  /* end of group MINI51_ADC_Driver */
181  /* end of group MINI51_Device_Driver */
183 
184 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
void ADC_Open(ADC_T *adc, uint32_t u32InputMode, uint32_t u32OpMode, uint32_t u32ChMask)
This API configures ADC module to be ready for convert the input from selected channel.
Definition: adc.c:38
#define ADC_CMP1_INT
Definition: adc.h:43
#define ADC_ADCMPR_CMPIE_Msk
Definition: Mini51Series.h:874
#define ADC_ADTDCR_PTDT_Msk
Definition: Mini51Series.h:910
#define ADC_RISING_EDGE_TRIGGER
Definition: adc.h:40
void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
Enable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:141
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
void ADC_EnableHWTrigger(ADC_T *adc, uint32_t u32Source, uint32_t u32Param)
Configure the hardware trigger condition and enable hardware trigger.
Definition: adc.c:76
#define ADC_ADCR_ADIE_Msk
Definition: Mini51Series.h:826
void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
Disable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:164
#define ADC
Pointer to ADC register structure.
void ADC_SetExtraSampleTime(ADC_T *adc, uint32_t u32ChNum, uint32_t u32SampleTime)
Set ADC sample time for designated channel.
Definition: adc.c:123
#define SYS
Pointer to SYS register structure.
#define ADC_ADSAMP_SAMPCNT_Msk
Definition: Mini51Series.h:913
void ADC_DisableHWTrigger(ADC_T *adc)
Disable hardware trigger ADC function.
Definition: adc.c:98
#define ADC_ADCHER_CHEN_Msk
Definition: Mini51Series.h:841
#define ADC_ADF_INT
Definition: adc.h:41
void ADC_Close(ADC_T *adc)
Disable ADC module.
Definition: adc.c:54
#define ADC_CMP0_INT
Definition: adc.h:42
#define ADC_TRIGGER_BY_PWM
Definition: adc.h:38
#define SYS_IPRSTC2_ADC_RST_Msk
#define ADC_ADCR_TRGEN_Msk
Definition: Mini51Series.h:835
#define ADC_TRIGGER_BY_EXT_PIN
Definition: adc.h:37