acmp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /**************************************************************************//**
  2. * @file acmp.h
  3. * @version V1.00
  4. * $Revision: 5 $
  5. * $Date: 15/11/04 7:29p $
  6. * @brief NUC472/NUC442 Analog Comparator(ACMP) driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __ACMP_H__
  12. #define __ACMP_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
  18. @{
  19. */
  20. /** @addtogroup NUC472_442_ACMP_Driver ACMP Driver
  21. @{
  22. */
  23. /** @addtogroup NUC472_442_ACMP_EXPORTED_CONSTANTS ACMP Exported Constants
  24. @{
  25. */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* ACMP_CR constant definitions */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. #define ACMP_VNEG_PIN (0xFFUL) ///< Selecting the voltage of ACMP negative input pin as the source of ACMP V- \hideinitializer
  30. #define ACMP_VNEG_BANDGAP (0x00UL) ///< Selecting band-gap voltage as the source of ACMP V- \hideinitializer
  31. #define ACMP_VNEG_4_OVER_24_VDD (0x80UL) ///< Selecting 4/24 VDD as the source of ACMP V- \hideinitializer
  32. #define ACMP_VNEG_5_OVER_24_VDD (0x81UL) ///< Selecting 5/24 VDD as the source of ACMP V- \hideinitializer
  33. #define ACMP_VNEG_6_OVER_24_VDD (0x82UL) ///< Selecting 6/24 VDD as the source of ACMP V- \hideinitializer
  34. #define ACMP_VNEG_7_OVER_24_VDD (0x83UL) ///< Selecting 7/24 VDD as the source of ACMP V- \hideinitializer
  35. #define ACMP_VNEG_8_OVER_24_VDD (0x84UL) ///< Selecting 8/24 VDD as the source of ACMP V- \hideinitializer
  36. #define ACMP_VNEG_9_OVER_24_VDD (0x85UL) ///< Selecting 9/24 VDD as the source of ACMP V- \hideinitializer
  37. #define ACMP_VNEG_10_OVER_24_VDD (0x86UL) ///< Selecting 10/24 VDD as the source of ACMP V- \hideinitializer
  38. #define ACMP_VNEG_11_OVER_24_VDD (0x87UL) ///< Selecting 11/24 VDD as the source of ACMP V- \hideinitializer
  39. #define ACMP_VNEG_12_OVER_24_VDD (0x88UL) ///< Selecting 12/24 VDD as the source of ACMP V- \hideinitializer
  40. #define ACMP_VNEG_13_OVER_24_VDD (0x89UL) ///< Selecting 13/24 VDD as the source of ACMP V- \hideinitializer
  41. #define ACMP_VNEG_14_OVER_24_VDD (0x8AUL) ///< Selecting 14/24 VDD as the source of ACMP V- \hideinitializer
  42. #define ACMP_VNEG_15_OVER_24_VDD (0x8BUL) ///< Selecting 15/24 VDD as the source of ACMP V- \hideinitializer
  43. #define ACMP_VNEG_16_OVER_24_VDD (0x8CUL) ///< Selecting 16/24 VDD as the source of ACMP V- \hideinitializer
  44. #define ACMP_VNEG_17_OVER_24_VDD (0x8DUL) ///< Selecting 17/24 VDD as the source of ACMP V- \hideinitializer
  45. #define ACMP_VNEG_18_OVER_24_VDD (0x8EUL) ///< Selecting 18/24 VDD as the source of ACMP V- \hideinitializer
  46. #define ACMP_VNEG_19_OVER_24_VDD (0x8FUL) ///< Selecting 19/24 VDD as the source of ACMP V- \hideinitializer
  47. #define ACMP_VNEG_4_OVER_24_IREF (0xC0UL) ///< Selecting 4/24 IREF as the source of ACMP V- \hideinitializer
  48. #define ACMP_VNEG_5_OVER_24_IREF (0xC1UL) ///< Selecting 5/24 IREF as the source of ACMP V- \hideinitializer
  49. #define ACMP_VNEG_6_OVER_24_IREF (0xC2UL) ///< Selecting 6/24 IREF as the source of ACMP V- \hideinitializer
  50. #define ACMP_VNEG_7_OVER_24_IREF (0xC3UL) ///< Selecting 7/24 IREF as the source of ACMP V- \hideinitializer
  51. #define ACMP_VNEG_8_OVER_24_IREF (0xC4UL) ///< Selecting 8/24 IREF as the source of ACMP V- \hideinitializer
  52. #define ACMP_VNEG_9_OVER_24_IREF (0xC5UL) ///< Selecting 9/24 IREF as the source of ACMP V- \hideinitializer
  53. #define ACMP_VNEG_10_OVER_24_IREF (0xC6UL) ///< Selecting 10/24 IREF as the source of ACMP V- \hideinitializer
  54. #define ACMP_VNEG_11_OVER_24_IREF (0xC7UL) ///< Selecting 11/24 IREF as the source of ACMP V- \hideinitializer
  55. #define ACMP_VNEG_12_OVER_24_IREF (0xC8UL) ///< Selecting 12/24 IREF as the source of ACMP V- \hideinitializer
  56. #define ACMP_VNEG_13_OVER_24_IREF (0xC9UL) ///< Selecting 13/24 IREF as the source of ACMP V- \hideinitializer
  57. #define ACMP_VNEG_14_OVER_24_IREF (0xCAUL) ///< Selecting 14/24 IREF as the source of ACMP V- \hideinitializer
  58. #define ACMP_VNEG_15_OVER_24_IREF (0xCBUL) ///< Selecting 15/24 IREF as the source of ACMP V- \hideinitializer
  59. #define ACMP_VNEG_16_OVER_24_IREF (0xCCUL) ///< Selecting 16/24 IREF as the source of ACMP V- \hideinitializer
  60. #define ACMP_VNEG_17_OVER_24_IREF (0xCDUL) ///< Selecting 17/24 IREF as the source of ACMP V- \hideinitializer
  61. #define ACMP_VNEG_18_OVER_24_IREF (0xCEUL) ///< Selecting 18/24 IREF as the source of ACMP V- \hideinitializer
  62. #define ACMP_VNEG_19_OVER_24_IREF (0xCFUL) ///< Selecting 19/24 IREF as the source of ACMP V- \hideinitializer
  63. #define ACMP_HYSTERESIS_ENABLE (1UL << ACMP_CTL_HYSEN_Pos) ///< Enable hysteresis function \hideinitializer
  64. #define ACMP_HYSTERESIS_DISABLE (0UL) ///< Disable hysteresis function \hideinitializer
  65. #define ACMP_CH0_POSPIN_P0 (0UL) ///< Selecting ACMP0_P0 as ACMP Channel 0 positive input source \hideinitializer
  66. #define ACMP_CH0_POSPIN_P1 (1UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP0_P1 as ACMP Channel 0 positive input source \hideinitializer
  67. #define ACMP_CH0_POSPIN_P2 (2UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP0_P2 as ACMP Channel 0 positive input source \hideinitializer
  68. #define ACMP_CH0_POSPIN_P3 (3UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP0_P3 as ACMP Channel 0 positive input source \hideinitializer
  69. #define ACMP_CH0_POS_OPA0 (4UL << ACMP_CTL_POSSEL_Pos) ///< Selecting OPA0 as ACMP Channel 0 positive input source \hideinitializer
  70. #define ACMP_CH1_POSPIN_P0 (0UL) ///< Selecting ACMP1_P0 as ACMP Channel 1 positive input source \hideinitializer
  71. #define ACMP_CH1_POSPIN_P1 (1UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP1_P1 as ACMP Channel 1 positive input source \hideinitializer
  72. #define ACMP_CH1_POSPIN_P2 (2UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP1_P2 as ACMP Channel 1 positive input source \hideinitializer
  73. #define ACMP_CH1_POSPIN_P3 (3UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP1_P3 as ACMP Channel 1 positive input source \hideinitializer
  74. #define ACMP_CH1_POS_OPA1 (4UL << ACMP_CTL_POSSEL_Pos) ///< Selecting OPA1 as ACMP Channel 1 positive input source \hideinitializer
  75. #define ACMP_CH2_POSPIN_P0 (0UL) ///< Selecting ACMP2_P0 as ACMP Channel 2 positive input source \hideinitializer
  76. #define ACMP_CH2_POSPIN_P1 (1UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP2_P1 as ACMP Channel 2 positive input source \hideinitializer
  77. #define ACMP_CH2_POSPIN_P2 (2UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP2_P2 as ACMP Channel 2 positive input source \hideinitializer
  78. #define ACMP_CH2_POSPIN_P3 (3UL << ACMP_CTL_POSSEL_Pos) ///< Selecting ACMP2_P3 as ACMP Channel 2 positive input source \hideinitializer
  79. /*@}*/ /* end of group NUC472_442_ACMP_EXPORTED_CONSTANTS */
  80. /** @addtogroup NUC472_442_ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
  81. @{
  82. */
  83. /**
  84. * @brief This macro is used to select ACMP negative input source
  85. * @param[in] acmp The base address of ACMP module
  86. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  87. * @param[in] u32Src is comparator negative input selection. Including :
  88. * - \ref ACMP_VNEG_PIN
  89. * - \ref ACMP_VNEG_BANDGAP
  90. * - \ref ACMP_VNEG_4_OVER_24_VDD
  91. * - \ref ACMP_VNEG_5_OVER_24_VDD
  92. * - \ref ACMP_VNEG_6_OVER_24_VDD
  93. * - \ref ACMP_VNEG_7_OVER_24_VDD
  94. * - \ref ACMP_VNEG_8_OVER_24_VDD
  95. * - \ref ACMP_VNEG_9_OVER_24_VDD
  96. * - \ref ACMP_VNEG_10_OVER_24_VDD
  97. * - \ref ACMP_VNEG_11_OVER_24_VDD
  98. * - \ref ACMP_VNEG_12_OVER_24_VDD
  99. * - \ref ACMP_VNEG_13_OVER_24_VDD
  100. * - \ref ACMP_VNEG_14_OVER_24_VDD
  101. * - \ref ACMP_VNEG_15_OVER_24_VDD
  102. * - \ref ACMP_VNEG_16_OVER_24_VDD
  103. * - \ref ACMP_VNEG_17_OVER_24_VDD
  104. * - \ref ACMP_VNEG_18_OVER_24_VDD
  105. * - \ref ACMP_VNEG_19_OVER_24_VDD
  106. * - \ref ACMP_VNEG_4_OVER_24_IREF
  107. * - \ref ACMP_VNEG_5_OVER_24_IREF
  108. * - \ref ACMP_VNEG_6_OVER_24_IREF
  109. * - \ref ACMP_VNEG_7_OVER_24_IREF
  110. * - \ref ACMP_VNEG_8_OVER_24_IREF
  111. * - \ref ACMP_VNEG_9_OVER_24_IREF
  112. * - \ref ACMP_VNEG_10_OVER_24_IREF
  113. * - \ref ACMP_VNEG_11_OVER_24_IREF
  114. * - \ref ACMP_VNEG_12_OVER_24_IREF
  115. * - \ref ACMP_VNEG_13_OVER_24_IREF
  116. * - \ref ACMP_VNEG_14_OVER_24_IREF
  117. * - \ref ACMP_VNEG_15_OVER_24_IREF
  118. * - \ref ACMP_VNEG_16_OVER_24_IREF
  119. * - \ref ACMP_VNEG_17_OVER_24_IREF
  120. * - \ref ACMP_VNEG_18_OVER_24_IREF
  121. * - \ref ACMP_VNEG_19_OVER_24_IREF
  122. *
  123. * @return None
  124. * @note The V- setting is shared by all comparators if input source is not coming from PIN
  125. * \hideinitializer
  126. */
  127. #define ACMP_SET_NEG_SRC(acmp, u32ChNum, u32Src) do{\
  128. if(u32Src == ACMP_VNEG_PIN)\
  129. ACMP->CTL[u32ChNum] &= ~ACMP_CTL_NEGSEL_Msk;\
  130. else {\
  131. ACMP->CTL[u32ChNum] |= ACMP_CTL_NEGSEL_Msk;\
  132. ACMP->VREF = u32Src;\
  133. }\
  134. }while(0)
  135. /**
  136. * @brief This macro is used to enable hysteresis function
  137. * @param[in] acmp The base address of ACMP module
  138. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  139. * @return None
  140. * \hideinitializer
  141. */
  142. #define ACMP_ENABLE_HYSTERESIS(acmp, u32ChNum) (ACMP->CTL[u32ChNum] |= ACMP_CTL_HYSEN_Msk)
  143. /**
  144. * @brief This macro is used to disable hysteresis function
  145. * @param[in] acmp The base address of ACMP module
  146. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  147. * @return None
  148. * \hideinitializer
  149. */
  150. #define ACMP_DISABLE_HYSTERESIS(acmp, u32ChNum) (ACMP->CTL[u32ChNum] &= ~ACMP_CTL_HYSEN_Msk)
  151. /**
  152. * @brief This macro is used to enable interrupt
  153. * @param[in] acmp The base address of ACMP module
  154. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  155. * @return None
  156. * \hideinitializer
  157. */
  158. #define ACMP_ENABLE_INT(acmp, u32ChNum) (ACMP->CTL[u32ChNum] |= ACMP_CTL_ACMPIE_Msk)
  159. /**
  160. * @brief This macro is used to disable interrupt
  161. * @param[in] acmp The base address of ACMP module
  162. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  163. * @return None
  164. * \hideinitializer
  165. */
  166. #define ACMP_DISABLE_INT(acmp, u32ChNum) (ACMP->CTL[u32ChNum] &= ~ACMP_CTL_ACMPIE_Msk)
  167. /**
  168. * @brief This macro is used to enable ACMP
  169. * @param[in] acmp The base address of ACMP module
  170. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  171. * @return None
  172. * \hideinitializer
  173. */
  174. #define ACMP_ENABLE(acmp, u32ChNum) (ACMP->CTL[u32ChNum] |= ACMP_CTL_ACMPEN_Msk)
  175. /**
  176. * @brief This macro is used to disable ACMP
  177. * @param[in] acmp The base address of ACMP module
  178. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  179. * @return None
  180. * \hideinitializer
  181. */
  182. #define ACMP_DISABLE(acmp, u32ChNum) (ACMP->CTL[u32ChNum] &= ~ACMP_CTL_ACMPEN_Msk)
  183. /**
  184. * @brief This macro is used to get ACMP output value
  185. * @param[in] acmp The base address of ACMP module
  186. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  187. * @return 1 or 0
  188. * \hideinitializer
  189. */
  190. #define ACMP_GET_OUTPUT(acmp, u32ChNum) (ACMP->STATUS & (ACMP_STATUS_ACMPO0_Msk<<(u32ChNum))?1:0)
  191. /**
  192. * @brief This macro is used to get ACMP interrupt flag
  193. * @param[in] acmp The base address of ACMP module
  194. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  195. * @return ACMP interrupt occurred or not
  196. * \hideinitializer
  197. */
  198. #define ACMP_GET_INT_FLAG(acmp, u32ChNum) (ACMP->STATUS & (ACMP_STATUS_ACMPIF0_Msk<<(u32ChNum))?1:0)
  199. /**
  200. * @brief This macro is used to clear ACMP interrupt flag
  201. * @param[in] acmp The base address of ACMP module
  202. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  203. * @return None
  204. * \hideinitializer
  205. */
  206. #define ACMP_CLR_INT_FLAG(acmp, u32ChNum) (ACMP->STATUS = (ACMP_STATUS_ACMPIF0_Msk<<(u32ChNum)))
  207. /**
  208. * @brief This macro is used to select the V+ pin of ACMP
  209. * @param[in] acmp The base address of ACMP module
  210. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  211. * @param[in] u32Pin The input pin. For channel 0, valid values are \ref ACMP_CH0_POSPIN_P0,
  212. * \ref ACMP_CH0_POSPIN_P1, \ref ACMP_CH0_POSPIN_P2, \ref ACMP_CH0_POSPIN_P3, and \ref ACMP_CH0_POS_OPA0.
  213. * For channel 1, valid values are , \ref ACMP_CH1_POSPIN_P0, \ref ACMP_CH1_POSPIN_P1, \ref ACMP_CH1_POSPIN_P2,
  214. * \ref ACMP_CH1_POSPIN_P3, and \ref ACMP_CH1_POS_OPA1. For channel 2, valid values are , \ref ACMP_CH2_POSPIN_P0,
  215. * \ref ACMP_CH2_POSPIN_P1, \ref ACMP_CH2_POSPIN_P2, and \ref ACMP_CH2_POSPIN_P3.
  216. * @return None
  217. * @note Except this setting, multi-function pin also needs to be configured
  218. * \hideinitializer
  219. */
  220. #define ACMP_SELECT_P(acmp, u32ChNum, u32Pin) (ACMP->CTL[u32ChNum] = (ACMP->CTL[u32ChNum] & ~ACMP_CTL_POSSEL_Msk) | u32Pin)
  221. /**
  222. * @brief This macro is used to set the level of CRV (Comparator Reference Voltage)
  223. * @param[in] acmp The base address of ACMP module
  224. * @param[in] u32Level CRV level, possible values are
  225. * - \ref ACMP_VNEG_4_OVER_24_VDD
  226. * - \ref ACMP_VNEG_5_OVER_24_VDD
  227. * - \ref ACMP_VNEG_6_OVER_24_VDD
  228. * - \ref ACMP_VNEG_7_OVER_24_VDD
  229. * - \ref ACMP_VNEG_8_OVER_24_VDD
  230. * - \ref ACMP_VNEG_9_OVER_24_VDD
  231. * - \ref ACMP_VNEG_10_OVER_24_VDD
  232. * - \ref ACMP_VNEG_11_OVER_24_VDD
  233. * - \ref ACMP_VNEG_12_OVER_24_VDD
  234. * - \ref ACMP_VNEG_13_OVER_24_VDD
  235. * - \ref ACMP_VNEG_14_OVER_24_VDD
  236. * - \ref ACMP_VNEG_15_OVER_24_VDD
  237. * - \ref ACMP_VNEG_16_OVER_24_VDD
  238. * - \ref ACMP_VNEG_17_OVER_24_VDD
  239. * - \ref ACMP_VNEG_18_OVER_24_VDD
  240. * - \ref ACMP_VNEG_19_OVER_24_VDD
  241. * - \ref ACMP_VNEG_4_OVER_24_IREF
  242. * - \ref ACMP_VNEG_5_OVER_24_IREF
  243. * - \ref ACMP_VNEG_6_OVER_24_IREF
  244. * - \ref ACMP_VNEG_7_OVER_24_IREF
  245. * - \ref ACMP_VNEG_8_OVER_24_IREF
  246. * - \ref ACMP_VNEG_9_OVER_24_IREF
  247. * - \ref ACMP_VNEG_10_OVER_24_IREF
  248. * - \ref ACMP_VNEG_11_OVER_24_IREF
  249. * - \ref ACMP_VNEG_12_OVER_24_IREF
  250. * - \ref ACMP_VNEG_13_OVER_24_IREF
  251. * - \ref ACMP_VNEG_14_OVER_24_IREF
  252. * - \ref ACMP_VNEG_15_OVER_24_IREF
  253. * - \ref ACMP_VNEG_16_OVER_24_IREF
  254. * - \ref ACMP_VNEG_17_OVER_24_IREF
  255. * - \ref ACMP_VNEG_18_OVER_24_IREF
  256. * - \ref ACMP_VNEG_19_OVER_24_IREF
  257. * @return None
  258. * @note This macro does not enable CRV. Please use \ref ACMP_ENABLE_CRV to enable CRV.
  259. * \hideinitializer
  260. */
  261. #define ACMP_CRV_SEL(acmp, u32Level) (ACMP->VREF = (ACMP->VREF & ~(ACMP_VREF_CRVSSEL_Msk | ACMP_VREF_CRVCTL_Msk)) | (u32Level))
  262. /**
  263. * @brief This macro is used to enable CRV(Comparator Reference Voltage)
  264. * @param[in] acmp The base address of ACMP module
  265. * @return None
  266. * \hideinitializer
  267. */
  268. #define ACMP_ENABLE_CRV(acmp) (ACMP->VREF |= ACMP_VREF_IREFSEL_Msk)
  269. /**
  270. * @brief This macro is used to disable CRV(Comparator Reference Voltage)
  271. * @param[in] acmp The base address of ACMP module
  272. * @return None
  273. * \hideinitializer
  274. */
  275. #define ACMP_DISABLE_CRV(acmp) (ACMP->VREF &= ~ACMP_VREF_IREFSEL_Msk)
  276. /**
  277. * @brief This macro is used to enable ACMP output inverse function
  278. * @param[in] acmp The base address of ACMP module
  279. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  280. * @return None
  281. * \hideinitializer
  282. */
  283. #define ACMP_ENABLE_OUTPUT_INVERSE(acmp, u32ChNum) (ACMP->CTL[u32ChNum] |= ACMP_CTL_ACMPOINV_Msk)
  284. /**
  285. * @brief This macro is used to disable ACMP output inverse function
  286. * @param[in] acmp The base address of ACMP module
  287. * @param[in] u32ChNum The ACMP number, could 0, 1, or 2
  288. * @return None
  289. * \hideinitializer
  290. */
  291. #define ACMP_DISABLE_OUTPUT_INVERSE(acmp, u32ChNum) (ACMP->CTL[u32ChNum] &= ~ACMP_CTL_ACMPOINV_Msk)
  292. void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn);
  293. void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum);
  294. /*@}*/ /* end of group NUC472_442_ACMP_EXPORTED_FUNCTIONS */
  295. /*@}*/ /* end of group NUC472_442_ACMP_Driver */
  296. /*@}*/ /* end of group NUC472_442_Device_Driver */
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300. #endif //__ACMP_H__
  301. /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/