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

dac.c
Go to the documentation of this file.
1 /**************************************************************************/
12 #include "Nano100Series.h"
13
40 void DAC_Open(DAC_T *dac, uint32_t u32Ch, uint32_t u32TrgSrc)
41 {
42 uint32_t u32Delay;
43
44 // DAC needs 6 us to stable after power on
45 u32Delay = CLK_GetHCLKFreq() * 6 / 1000000;
46 if(u32Delay == 0)
47 u32Delay++;
48 if(u32Ch == 0)
49 DAC->CTL0 = (u32Delay << DAC_CTL_DACPWONSTBCNT_Pos) | u32TrgSrc | DAC_CTL_DACEN_Msk;
50 else
51 DAC->CTL1 = (u32Delay << DAC_CTL_DACPWONSTBCNT_Pos) | u32TrgSrc | DAC_CTL_DACEN_Msk;
52
53 // DAC needs 2 us to stable after convert.
54 u32Delay = CLK_GetHCLKFreq() * 2 / 1000000;
55 if(u32Delay == 0)
56 u32Delay++;
57 DAC->COMCTL = (DAC->COMCTL & ~DAC_COMCTL_WAITDACCONV_Msk) | u32Delay;
58 }
59
67 void DAC_Close(DAC_T *dac, uint32_t u32Ch)
68 {
69 if(u32Ch == 0)
70 {
71 DAC->CTL0 &= ~DAC_CTL_DACEN_Msk;
72 }
73 else
74 {
75 DAC->CTL1 &= ~DAC_CTL_DACEN_Msk;
76 }
77
78 }
79
80
94 int DAC_SetDelayTime(DAC_T *dac, uint32_t u32Delay)
95 {
96 uint32_t u32Dly;
97
98 // DAC needs 2 us to stable after DAC convert, calculate minimal setting
99 u32Dly = CLK_GetHCLKFreq() * 2 / 1000000;
100 if(u32Dly == 0)
101 u32Dly++;
102
103 if(u32Delay < u32Dly) // return error id stable time is shorter than 2us
104 return -1;
105 DAC->COMCTL = (DAC->COMCTL & ~DAC_COMCTL_WAITDACCONV_Msk) | u32Delay;
106 return 0;
107 }
108
109
110
111 /* end of group NANO100_DAC_EXPORTED_FUNCTIONS */
113 /* end of group NANO100_DAC_Driver */
115 /* end of group NANO100_Device_Driver */
117
118 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
DAC
#define DAC
Pointer to DAC register structure.
Definition: Nano100Series.h:11690
DAC_Open
void DAC_Open(DAC_T *dac, uint32_t u32Ch, uint32_t u32TrgSrc)
This function make a DAC channel ready to convert.
Definition: dac.c:40
CLK_GetHCLKFreq
uint32_t CLK_GetHCLKFreq(void)
This function get HCLK frequency. The frequency unit is Hz.
Definition: clk.c:119
Nano100Series.h
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
DAC_T
Definition: Nano100Series.h:1477
DAC_CTL_DACEN_Msk
#define DAC_CTL_DACEN_Msk
Definition: Nano100Series.h:1636
DAC_SetDelayTime
int DAC_SetDelayTime(DAC_T *dac, uint32_t u32Delay)
Set delay time for DAC to become stable.
Definition: dac.c:94
DAC_Close
void DAC_Close(DAC_T *dac, uint32_t u32Ch)
Disable DAC analog power.
Definition: dac.c:67
DAC_COMCTL_WAITDACCONV_Msk
#define DAC_COMCTL_WAITDACCONV_Msk
Definition: Nano100Series.h:1660
DAC_CTL_DACPWONSTBCNT_Pos
#define DAC_CTL_DACPWONSTBCNT_Pos
Definition: Nano100Series.h:1644