| MINI51DE_BSP V3.02.004 The Board Support Package for Mini51DE Series MCU

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
76 void ADC_EnableHWTrigger(ADC_T *adc,
77 uint32_t u32Source,
78 uint32_t u32Param)
79{
80 ADC->ADCR &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_ADCR_TRGEN_Msk);
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
98 void ADC_DisableHWTrigger(ADC_T *adc)
99{
100 ADC->ADCR &= ~(ADC_TRIGGER_BY_PWM | ADC_RISING_EDGE_TRIGGER | ADC_ADCR_TRGEN_Msk);
101 return;
102}
103
123 void ADC_SetExtraSampleTime(ADC_T *adc,
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. ***/
Mini51Series.h
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
SYS_IPRSTC2_ADC_RST_Msk
#define SYS_IPRSTC2_ADC_RST_Msk
Definition: Mini51Series.h:1593
ADC_ADF_INT
#define ADC_ADF_INT
Definition: adc.h:41
ADC_CMP0_INT
#define ADC_CMP0_INT
Definition: adc.h:42
ADC_TRIGGER_BY_PWM
#define ADC_TRIGGER_BY_PWM
Definition: adc.h:38
ADC_TRIGGER_BY_EXT_PIN
#define ADC_TRIGGER_BY_EXT_PIN
Definition: adc.h:37
ADC_CMP1_INT
#define ADC_CMP1_INT
Definition: adc.h:43
ADC_RISING_EDGE_TRIGGER
#define ADC_RISING_EDGE_TRIGGER
Definition: adc.h:40
ADC_EnableHWTrigger
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
ADC_Close
void ADC_Close(ADC_T *adc)
Disable ADC module.
Definition: adc.c:54
ADC_SetExtraSampleTime
void ADC_SetExtraSampleTime(ADC_T *adc, uint32_t u32ChNum, uint32_t u32SampleTime)
Set ADC sample time for designated channel.
Definition: adc.c:123
ADC_Open
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
ADC_DisableInt
void ADC_DisableInt(ADC_T *adc, uint32_t u32Mask)
Disable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:164
ADC_DisableHWTrigger
void ADC_DisableHWTrigger(ADC_T *adc)
Disable hardware trigger ADC function.
Definition: adc.c:98
ADC_EnableInt
void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)
Enable the interrupt(s) selected by u32Mask parameter.
Definition: adc.c:141
ADC_ADCMPR_CMPIE_Msk
#define ADC_ADCMPR_CMPIE_Msk
Definition: Mini51Series.h:555
ADC_ADCR_ADIE_Msk
#define ADC_ADCR_ADIE_Msk
Definition: Mini51Series.h:507
ADC_ADCR_TRGEN_Msk
#define ADC_ADCR_TRGEN_Msk
Definition: Mini51Series.h:516
ADC
#define ADC
Pointer to ADC register structure.
Definition: Mini51Series.h:5732
SYS
#define SYS
Pointer to SYS register structure.
Definition: Mini51Series.h:5735
ADC_T
Definition: Mini51Series.h:290