lpc17xx_dac.c (5557B)
1 /********************************************************************** 2 * $Id$ lpc17xx_dac.c 2010-05-21 3 *//** 4 * @file lpc17xx_dac.c 5 * @brief Contains all functions support for DAC firmware library on LPC17xx 6 * @version 2.0 7 * @date 21. May. 2010 8 * @author NXP MCU SW Application Team 9 * 10 * Copyright(C) 2010, NXP Semiconductor 11 * All rights reserved. 12 * 13 *********************************************************************** 14 * Software that is described herein is for illustrative purposes only 15 * which provides customers with programming information regarding the 16 * products. This software is supplied "AS IS" without any warranties. 17 * NXP Semiconductors assumes no responsibility or liability for the 18 * use of the software, conveys no license or title under any patent, 19 * copyright, or mask work right to the product. NXP Semiconductors 20 * reserves the right to make changes in the software without 21 * notification. NXP Semiconductors also make no representation or 22 * warranty that such application will be suitable for the specified 23 * use without further testing or modification. 24 * Permission to use, copy, modify, and distribute this software and its 25 * documentation is hereby granted, under NXP Semiconductors' 26 * relevant copyright in the software, without fee, provided that it 27 * is used in conjunction with NXP Semiconductors microcontrollers. This 28 * copyright, permission, and disclaimer notice must appear in all copies of 29 * this code. 30 **********************************************************************/ 31 32 /* Peripheral group ----------------------------------------------------------- */ 33 /** @addtogroup DAC 34 * @{ 35 */ 36 37 /* Includes ------------------------------------------------------------------- */ 38 #include "lpc17xx_dac.h" 39 #include "lpc17xx_clkpwr.h" 40 41 /* If this source file built with example, the LPC17xx FW library configuration 42 * file in each example directory ("lpc17xx_libcfg.h") must be included, 43 * otherwise the default FW library configuration file must be included instead 44 */ 45 #ifdef __BUILD_WITH_EXAMPLE__ 46 #include "lpc17xx_libcfg.h" 47 #else 48 #include "lpc17xx_libcfg_default.h" 49 #endif /* __BUILD_WITH_EXAMPLE__ */ 50 51 52 #ifdef _DAC 53 54 /* Public Functions ----------------------------------------------------------- */ 55 /** @addtogroup DAC_Public_Functions 56 * @{ 57 */ 58 59 /*********************************************************************//** 60 * @brief Initial ADC configuration 61 * - Maximum current is 700 uA 62 * - Value to AOUT is 0 63 * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC 64 * @return None 65 ***********************************************************************/ 66 void DAC_Init(LPC_DAC_TypeDef *DACx) 67 { 68 CHECK_PARAM(PARAM_DACx(DACx)); 69 /* Set default clock divider for DAC */ 70 // CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_DAC, CLKPWR_PCLKSEL_CCLK_DIV_4); 71 //Set maximum current output 72 DAC_SetBias(LPC_DAC,DAC_MAX_CURRENT_700uA); 73 } 74 75 /*********************************************************************//** 76 * @brief Update value to DAC 77 * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC 78 * @param[in] dac_value : value 10 bit to be converted to output 79 * @return None 80 ***********************************************************************/ 81 void DAC_UpdateValue (LPC_DAC_TypeDef *DACx,uint32_t dac_value) 82 { 83 uint32_t tmp; 84 CHECK_PARAM(PARAM_DACx(DACx)); 85 tmp = DACx->DACR & DAC_BIAS_EN; 86 tmp |= DAC_VALUE(dac_value); 87 // Update value 88 DACx->DACR = tmp; 89 } 90 91 /*********************************************************************//** 92 * @brief Set Maximum current for DAC 93 * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC 94 * @param[in] bias : 0 is 700 uA 95 * 1 350 uA 96 * @return None 97 ***********************************************************************/ 98 void DAC_SetBias (LPC_DAC_TypeDef *DACx,uint32_t bias) 99 { 100 CHECK_PARAM(PARAM_DAC_CURRENT_OPT(bias)); 101 DACx->DACR &=~DAC_BIAS_EN; 102 if (bias == DAC_MAX_CURRENT_350uA) 103 { 104 DACx->DACR |= DAC_BIAS_EN; 105 } 106 } 107 108 /*********************************************************************//** 109 * @brief To enable the DMA operation and control DMA timer 110 * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC 111 * @param[in] DAC_ConverterConfigStruct pointer to DAC_CONVERTER_CFG_Type 112 * - DBLBUF_ENA : enable/disable DACR double buffering feature 113 * - CNT_ENA : enable/disable timer out counter 114 * - DMA_ENA : enable/disable DMA access 115 * @return None 116 ***********************************************************************/ 117 void DAC_ConfigDAConverterControl (LPC_DAC_TypeDef *DACx,DAC_CONVERTER_CFG_Type *DAC_ConverterConfigStruct) 118 { 119 CHECK_PARAM(PARAM_DACx(DACx)); 120 DACx->DACCTRL &= ~DAC_DACCTRL_MASK; 121 if (DAC_ConverterConfigStruct->DBLBUF_ENA) 122 DACx->DACCTRL |= DAC_DBLBUF_ENA; 123 if (DAC_ConverterConfigStruct->CNT_ENA) 124 DACx->DACCTRL |= DAC_CNT_ENA; 125 if (DAC_ConverterConfigStruct->DMA_ENA) 126 DACx->DACCTRL |= DAC_DMA_ENA; 127 } 128 129 /*********************************************************************//** 130 * @brief Set reload value for interrupt/DMA counter 131 * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC 132 * @param[in] time_out time out to reload for interrupt/DMA counter 133 * @return None 134 ***********************************************************************/ 135 void DAC_SetDMATimeOut(LPC_DAC_TypeDef *DACx, uint32_t time_out) 136 { 137 CHECK_PARAM(PARAM_DACx(DACx)); 138 DACx->DACCNTVAL = DAC_CCNT_VALUE(time_out); 139 } 140 141 /** 142 * @} 143 */ 144 145 #endif /* _DAC */ 146 147 /** 148 * @} 149 */ 150 151 /* --------------------------------- End Of File ------------------------------ */