| Nano102_112 Series BSP V3.03.002 The Board Support Package for Nano102_112 Series

acmp.c
Go to the documentation of this file.
1 /**************************************************************************/
13 #include "Nano1X2Series.h"
14
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19
55 void ACMP_Open(ACMP_T *Acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn)
56 {
57 Acmp->CR[u32ChNum] = (Acmp->CR[u32ChNum] & ~ACMP_CR_CN_Msk) | (u32NegSrc>>24)<<ACMP_CR_CN_Pos;
58
59 if((u32NegSrc&(0xFFUL<<24))==ACMP_CR_CN_CRV)
60 Acmp->RVCR = (Acmp->RVCR & ~ACMP_RVCR_CRVS_Msk) | (u32NegSrc & 0x00FFFFFF) | ACMP_RVCR_CRV_EN_Msk;
61
62 Acmp->CR[u32ChNum] = (Acmp->CR[u32ChNum] & ~ACMP_CR_ACMP_HYSEN_Msk) | u32HysteresisEn;
63 Acmp->CR[u32ChNum] |= ACMP_CR_ACMPEN_Msk;
64 }
65
71 void ACMP_Close(ACMP_T *Acmp, uint32_t u32ChNum)
72 {
73 Acmp->CR[u32ChNum] &= ~ACMP_CR_ACMPEN_Msk;
74 }
75
102 void ACMP_SetSigmaDeltaConv(uint32_t u32TimerNum, uint32_t u32TriggerPolarity, uint32_t u32PosPin, uint32_t u32ChargePin)
103 {
104 ACMP->CR[0] =(ACMP->CR[0] & ~ACMP_CR_CPP0SEL_Msk) | u32PosPin;
105 ACMP->CR[0] &= ~ACMP_CR_CPO0_SEL_Msk;
106 ACMP->CR[0] &= ~ACMP_CR_ACMP0_INV_Msk;
107 ACMP->CR[0] |= ACMP_CR_ACOMP0_PN_AutoEx_Msk; //Auto Exchange Enabled
108 ACMP->CR[0] |= ACMP_CR_ACMP0_FILTER_Msk; //Enable internal RC filter
109 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_TMR_SEL_Msk) | (u32TimerNum);
110 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_MOD_SEL_Msk)| ACMP_MODCR0_MOD_SEL_SIGAMA_DELTA;
111 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_TMR_TRI_LV_Msk) | u32TriggerPolarity;
112 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_CH_DIS_PIN_SEL_Msk) | u32ChargePin ;
113 }
114
115
142 void ACMP_SetSlopeConv(uint32_t u32TimerNum, uint32_t u32TriggerPolarity, uint32_t u32PosPin, uint32_t u32ChargePin)
143 {
144 ACMP->CR[0] =(ACMP->CR[0] & ~ACMP_CR_CPP0SEL_Msk) | u32PosPin;
145 ACMP->CR[0] &= ~ACMP_CR_CPO0_SEL_Msk ; /* Comparator output is from internal path */
146 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_TMR_SEL_Msk) | u32TimerNum;
147 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_MOD_SEL_Msk)| ACMP_MODCR0_MOD_SEL_SLOPE;
148 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_TMR_TRI_LV_Msk) | u32TriggerPolarity;
149 ACMP->MODCR0 = (ACMP->MODCR0 & ~ACMP_MODCR0_CH_DIS_PIN_SEL_Msk) | u32ChargePin ; /* A Pin Can Only Do Discharging Work */
150 }
151
152 /* end of group NANO1X2_ACMP_EXPORTED_FUNCTIONS */
154 /* end of group NANO1X2_ACMP_Driver */
156 /* end of group NANO1X2_Device_Driver */
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
164
ACMP_SetSlopeConv
void ACMP_SetSlopeConv(uint32_t u32TimerNum, uint32_t u32TriggerPolarity, uint32_t u32PosPin, uint32_t u32ChargePin)
This function configure ACMP to slope mode.
Definition: acmp.c:142
ACMP_MODCR0_TMR_TRI_LV_Msk
#define ACMP_MODCR0_TMR_TRI_LV_Msk
Definition: Nano1X2Series.h:357
ACMP_MODCR0_MOD_SEL_SLOPE
#define ACMP_MODCR0_MOD_SEL_SLOPE
The comparator mode select slope mode.
Definition: acmp.h:61
ACMP_Close
void ACMP_Close(ACMP_T *, uint32_t u32ChNum)
This function close comparator.
Definition: acmp.c:71
ACMP_CR_ACMPEN_Msk
#define ACMP_CR_ACMPEN_Msk
Definition: Nano1X2Series.h:297
ACMP_CR_CN_Msk
#define ACMP_CR_CN_Msk
Definition: Nano1X2Series.h:306
ACMP_CR_CPP0SEL_Msk
#define ACMP_CR_CPP0SEL_Msk
Definition: Nano1X2Series.h:324
ACMP_Open
void ACMP_Open(ACMP_T *, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn)
This function open and configure comparator parameters.
Definition: acmp.c:55
ACMP_CR_CN_CRV
#define ACMP_CR_CN_CRV
The internal comparator reference voltage (CRV) is selected.
Definition: acmp.h:34
Nano1X2Series.h
Nano102/112 peripheral access layer header file. This file contains all the peripheral register's def...
ACMP_T
Definition: Nano1X2Series.h:156
ACMP_MODCR0_MOD_SEL_SIGAMA_DELTA
#define ACMP_MODCR0_MOD_SEL_SIGAMA_DELTA
The comparator mode select sigma-delta mode.
Definition: acmp.h:60
ACMP_T::CR
__IO uint32_t CR[2]
Definition: Nano1X2Series.h:206
ACMP_CR_ACMP0_INV_Msk
#define ACMP_CR_ACMP0_INV_Msk
Definition: Nano1X2Series.h:312
ACMP_RVCR_CRVS_Msk
#define ACMP_RVCR_CRVS_Msk
Definition: Nano1X2Series.h:342
ACMP_CR_ACMP_HYSEN_Msk
#define ACMP_CR_ACMP_HYSEN_Msk
Definition: Nano1X2Series.h:303
ACMP_CR_ACMP0_FILTER_Msk
#define ACMP_CR_ACMP0_FILTER_Msk
Definition: Nano1X2Series.h:318
ACMP_CR_CN_Pos
#define ACMP_CR_CN_Pos
Definition: Nano1X2Series.h:305
ACMP_MODCR0_TMR_SEL_Msk
#define ACMP_MODCR0_TMR_SEL_Msk
Definition: Nano1X2Series.h:354
ACMP_MODCR0_MOD_SEL_Msk
#define ACMP_MODCR0_MOD_SEL_Msk
Definition: Nano1X2Series.h:351
ACMP_CR_ACOMP0_PN_AutoEx_Msk
#define ACMP_CR_ACOMP0_PN_AutoEx_Msk
Definition: Nano1X2Series.h:315
ACMP_T::RVCR
__IO uint32_t RVCR
Definition: Nano1X2Series.h:249
ACMP_CR_CPO0_SEL_Msk
#define ACMP_CR_CPO0_SEL_Msk
Definition: Nano1X2Series.h:321
ACMP_MODCR0_CH_DIS_PIN_SEL_Msk
#define ACMP_MODCR0_CH_DIS_PIN_SEL_Msk
Definition: Nano1X2Series.h:360
ACMP
#define ACMP
Pointer to ACMP register structure.
Definition: Nano1X2Series.h:10648
ACMP_RVCR_CRV_EN_Msk
#define ACMP_RVCR_CRV_EN_Msk
Definition: Nano1X2Series.h:345
ACMP_SetSigmaDeltaConv
void ACMP_SetSigmaDeltaConv(uint32_t u32TimerNum, uint32_t u32TriggerPolarity, uint32_t u32PosPin, uint32_t u32ChargePin)
This function configure ACMP to sigma-delta mode.
Definition: acmp.c:102