1 /**********************************************************************
\r
2 * $Id$ lpc18xx_dac.c 2011-06-02
\r
4 * @file lpc18xx_dac.c
\r
5 * @brief Contains all functions support for DAC firmware library on LPC18xx
\r
7 * @date 02. June. 2011
\r
8 * @author NXP MCU SW Application Team
\r
10 * Copyright(C) 2011, NXP Semiconductor
\r
11 * All rights reserved.
\r
13 ***********************************************************************
\r
14 * Software that is described herein is for illustrative purposes only
\r
15 * which provides customers with programming information regarding the
\r
16 * products. This software is supplied "AS IS" without any warranties.
\r
17 * NXP Semiconductors assumes no responsibility or liability for the
\r
18 * use of the software, conveys no license or title under any patent,
\r
19 * copyright, or mask work right to the product. NXP Semiconductors
\r
20 * reserves the right to make changes in the software without
\r
21 * notification. NXP Semiconductors also make no representation or
\r
22 * warranty that such application will be suitable for the specified
\r
23 * use without further testing or modification.
\r
24 **********************************************************************/
\r
26 /* Peripheral group ----------------------------------------------------------- */
\r
31 /* Includes ------------------------------------------------------------------- */
\r
32 #include "lpc18xx_dac.h"
\r
33 #include "lpc18xx_cgu.h"
\r
35 /* If this source file built with example, the LPC18xx FW library configuration
\r
36 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
37 * otherwise the default FW library configuration file must be included instead
\r
39 #ifdef __BUILD_WITH_EXAMPLE__
\r
40 #include "lpc18xx_libcfg.h"
\r
42 #include "lpc18xx_libcfg_default.h"
\r
43 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
48 /* Public Functions ----------------------------------------------------------- */
\r
49 /** @addtogroup DAC_Public_Functions
\r
53 /*********************************************************************//**
\r
54 * @brief Initial ADC configuration
\r
55 * - Maximum current is 700 uA
\r
56 * - Value to AOUT is 0
\r
57 * @param[in] DACx pointer to LPC_DAC_Type, should be: LPC_DAC
\r
59 ***********************************************************************/
\r
60 void DAC_Init(LPC_DAC_Type *DACx)
\r
62 CHECK_PARAM(PARAM_DACx(DACx));
\r
63 /* Set default clock divider for DAC */
\r
64 //LPC_CGU->BASE_VPB3_CLK = (SRC_PL160M_0<<24) | (1<<11); // ABP3 base clock use PLL1 and auto block
\r
65 CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_APB3);
\r
66 //Set maximum current output
\r
67 DAC_SetBias(LPC_DAC,DAC_MAX_CURRENT_700uA);
\r
70 /*********************************************************************//**
\r
71 * @brief Update value to DAC
\r
72 * @param[in] DACx pointer to LPC_DAC_Type, should be: LPC_DAC
\r
73 * @param[in] dac_value value 10 bit to be converted to output
\r
75 ***********************************************************************/
\r
76 void DAC_UpdateValue (LPC_DAC_Type *DACx,uint32_t dac_value)
\r
79 CHECK_PARAM(PARAM_DACx(DACx));
\r
80 tmp = DACx->CR & DAC_BIAS_EN;
\r
81 tmp |= DAC_VALUE(dac_value);
\r
86 /*********************************************************************//**
\r
87 * @brief Set Maximum current for DAC
\r
88 * @param[in] DACx pointer to LPC_DAC_Type, should be: LPC_DAC
\r
89 * @param[in] bias Using Bias value, should be:
\r
93 ***********************************************************************/
\r
94 void DAC_SetBias (LPC_DAC_Type *DACx,uint32_t bias)
\r
96 CHECK_PARAM(PARAM_DAC_CURRENT_OPT(bias));
\r
97 DACx->CR &=~DAC_BIAS_EN;
\r
98 if (bias == DAC_MAX_CURRENT_350uA)
\r
100 DACx->CR |= DAC_BIAS_EN;
\r
104 /*********************************************************************//**
\r
105 * @brief To enable the DMA operation and control DMA timer
\r
106 * @param[in] DACx pointer to LPC_DAC_Type, should be: LPC_DAC
\r
107 * @param[in] DAC_ConverterConfigStruct pointer to DAC_CONVERTER_CFG_Type
\r
108 * - DBLBUF_ENA :enable/disable DACR double buffering feature
\r
109 * - CNT_ENA :enable/disable timer out counter
\r
110 * - DMA_ENA :enable/disable DMA access
\r
112 ***********************************************************************/
\r
113 void DAC_ConfigDAConverterControl (LPC_DAC_Type *DACx,DAC_CONVERTER_CFG_Type *DAC_ConverterConfigStruct)
\r
115 CHECK_PARAM(PARAM_DACx(DACx));
\r
116 DACx->CTRL &= ~DAC_DACCTRL_MASK;
\r
117 if (DAC_ConverterConfigStruct->DBLBUF_ENA)
\r
118 DACx->CTRL |= DAC_DBLBUF_ENA;
\r
119 if (DAC_ConverterConfigStruct->CNT_ENA)
\r
120 DACx->CTRL |= DAC_CNT_ENA;
\r
121 if (DAC_ConverterConfigStruct->DMA_ENA)
\r
122 DACx->CTRL |= DAC_DMA_ENA;
\r
125 /*********************************************************************//**
\r
126 * @brief Set reload value for interrupt/DMA counter
\r
127 * @param[in] DACx pointer to LPC_DAC_Type, should be: LPC_DAC
\r
128 * @param[in] time_out time out to reload for interrupt/DMA counter
\r
130 ***********************************************************************/
\r
131 void DAC_SetDMATimeOut(LPC_DAC_Type *DACx, uint32_t time_out)
\r
133 CHECK_PARAM(PARAM_DACx(DACx));
\r
134 DACx->CNTVAL = DAC_CCNT_VALUE(time_out);
\r
147 /* --------------------------------- End Of File ------------------------------ */
\r