1 /**************************************************************************//**
2 * @file acmp.c
3 * @version V1.00
4 * @brief M480 series Analog Comparator(ACMP) driver source file
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 * @copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #include "NuMicro.h"
10
11
12 /** @addtogroup Standard_Driver Standard Driver
13 @{
14 */
15
16 /** @addtogroup ACMP_Driver ACMP Driver
17 @{
18 */
19
20
21 /** @addtogroup ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
22 @{
23 */
24
25
26 /**
27 * @brief Configure the specified ACMP module
28 *
29 * @param[in] acmp The pointer of the specified ACMP module
30 * @param[in] u32ChNum Comparator number.
31 * @param[in] u32NegSrc Comparator negative input selection. Including:
32 * - \ref ACMP_CTL_NEGSEL_PIN
33 * - \ref ACMP_CTL_NEGSEL_CRV
34 * - \ref ACMP_CTL_NEGSEL_VBG
35 * - \ref ACMP_CTL_NEGSEL_DAC
36 * @param[in] u32HysSel The hysteresis function option. Including:
37 * - \ref ACMP_CTL_HYSTERESIS_30MV
38 * - \ref ACMP_CTL_HYSTERESIS_20MV
39 * - \ref ACMP_CTL_HYSTERESIS_10MV
40 * - \ref ACMP_CTL_HYSTERESIS_DISABLE
41 *
42 * @return None
43 *
44 * @details Configure hysteresis function, select the source of negative input and enable analog comparator.
45 */
ACMP_Open(ACMP_T * acmp,uint32_t u32ChNum,uint32_t u32NegSrc,uint32_t u32HysSel)46 void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysSel)
47 {
48 volatile int32_t delay;
49
50 acmp->CTL[u32ChNum] = (acmp->CTL[u32ChNum] & (~(ACMP_CTL_NEGSEL_Msk | ACMP_CTL_HYSSEL_Msk | ACMP_CTL_MODESEL_Msk))) | (2 << ACMP_CTL_MODESEL_Pos) | (u32NegSrc | u32HysSel | ACMP_CTL_ACMPEN_Msk);
51
52 /* Delay for analog macro stable */
53 for(delay = SystemCoreClock / 0x40000; delay > 0; delay--) {}
54 }
55
56 /**
57 * @brief Close analog comparator
58 *
59 * @param[in] acmp The pointer of the specified ACMP module
60 * @param[in] u32ChNum Comparator number.
61 *
62 * @return None
63 *
64 * @details This function will clear ACMPEN bit of ACMP_CTL register to disable analog comparator.
65 */
ACMP_Close(ACMP_T * acmp,uint32_t u32ChNum)66 void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum)
67 {
68 acmp->CTL[u32ChNum] &= (~ACMP_CTL_ACMPEN_Msk);
69 }
70
71
72
73 /*@}*/ /* end of group ACMP_EXPORTED_FUNCTIONS */
74
75 /*@}*/ /* end of group ACMP_Driver */
76
77 /*@}*/ /* end of group Standard_Driver */
78
79 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
80
81