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);
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;
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 
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
#define ACMP_MODCR0_TMR_TRI_LV_Msk
#define ACMP_MODCR0_MOD_SEL_SLOPE
The comparator mode select slope mode.
Definition: acmp.h:61
void ACMP_Close(ACMP_T *, uint32_t u32ChNum)
This function close comparator.
Definition: acmp.c:71
#define ACMP_CR_ACMPEN_Msk
#define ACMP_CR_CN_Msk
#define ACMP_CR_CPP0SEL_Msk
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
#define ACMP_CR_CN_CRV
The internal comparator reference voltage (CRV) is selected.
Definition: acmp.h:34
Nano102/112 peripheral access layer header file. This file contains all the peripheral register's def...
#define ACMP_MODCR0_MOD_SEL_SIGAMA_DELTA
The comparator mode select sigma-delta mode.
Definition: acmp.h:60
__IO uint32_t CR[2]
#define ACMP_CR_ACMP0_INV_Msk
#define ACMP_RVCR_CRVS_Msk
#define ACMP_CR_ACMP_HYSEN_Msk
#define ACMP_CR_ACMP0_FILTER_Msk
#define ACMP_CR_CN_Pos
#define ACMP_MODCR0_TMR_SEL_Msk
#define ACMP_MODCR0_MOD_SEL_Msk
#define ACMP_CR_ACOMP0_PN_AutoEx_Msk
__IO uint32_t RVCR
#define ACMP_CR_CPO0_SEL_Msk
#define ACMP_MODCR0_CH_DIS_PIN_SEL_Msk
#define ACMP
Pointer to ACMP register structure.
#define ACMP_RVCR_CRV_EN_Msk
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