Date: March 20, 2011 This library is created from "LPC17xx CMSIS-Compliant Standard Peripheral Firmware Driver Library (GNU, Keil, IAR) (Jan 28, 2011)", available from NXP's website, under "All microcontrollers support documents" [[http://ics.nxp.com/support/documents/microcontrollers/?type=software]] You will need to follow [[/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h]] while using this library Examples provided here [[/users/frank26080115/programs/LPC1700CMSIS_Examples/]] The beautiful thing is that NXP does not place copyright protection on any of the files in here Only a few modifications are made to make it compile with the mbed online compiler, I fixed some warnings as well. This is untested as of March 20, 2011 Forum post about this library: [[/forum/mbed/topic/2030/]]
lpc17xx_dac.c@0:84d7747641aa, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 18:45:15 2011 +0000
- Revision:
- 0:84d7747641aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:84d7747641aa | 1 | /** |
frank26080115 | 0:84d7747641aa | 2 | * @file lpc17xx_dac.c |
frank26080115 | 0:84d7747641aa | 3 | * @brief Contains all functions support for DAC firmware library on LPC17xx |
frank26080115 | 0:84d7747641aa | 4 | * @version 2.0 |
frank26080115 | 0:84d7747641aa | 5 | * @date 21. May. 2010 |
frank26080115 | 0:84d7747641aa | 6 | * @author NXP MCU SW Application Team |
frank26080115 | 0:84d7747641aa | 7 | ************************************************************************** |
frank26080115 | 0:84d7747641aa | 8 | * Software that is described herein is for illustrative purposes only |
frank26080115 | 0:84d7747641aa | 9 | * which provides customers with programming information regarding the |
frank26080115 | 0:84d7747641aa | 10 | * products. This software is supplied "AS IS" without any warranties. |
frank26080115 | 0:84d7747641aa | 11 | * NXP Semiconductors assumes no responsibility or liability for the |
frank26080115 | 0:84d7747641aa | 12 | * use of the software, conveys no license or title under any patent, |
frank26080115 | 0:84d7747641aa | 13 | * copyright, or mask work right to the product. NXP Semiconductors |
frank26080115 | 0:84d7747641aa | 14 | * reserves the right to make changes in the software without |
frank26080115 | 0:84d7747641aa | 15 | * notification. NXP Semiconductors also make no representation or |
frank26080115 | 0:84d7747641aa | 16 | * warranty that such application will be suitable for the specified |
frank26080115 | 0:84d7747641aa | 17 | * use without further testing or modification. |
frank26080115 | 0:84d7747641aa | 18 | **********************************************************************/ |
frank26080115 | 0:84d7747641aa | 19 | |
frank26080115 | 0:84d7747641aa | 20 | /* Peripheral group ----------------------------------------------------------- */ |
frank26080115 | 0:84d7747641aa | 21 | /** @addtogroup DAC |
frank26080115 | 0:84d7747641aa | 22 | * @{ |
frank26080115 | 0:84d7747641aa | 23 | */ |
frank26080115 | 0:84d7747641aa | 24 | |
frank26080115 | 0:84d7747641aa | 25 | /* Includes ------------------------------------------------------------------- */ |
frank26080115 | 0:84d7747641aa | 26 | #include "lpc17xx_dac.h" |
frank26080115 | 0:84d7747641aa | 27 | #include "lpc17xx_clkpwr.h" |
frank26080115 | 0:84d7747641aa | 28 | |
frank26080115 | 0:84d7747641aa | 29 | /* If this source file built with example, the LPC17xx FW library configuration |
frank26080115 | 0:84d7747641aa | 30 | * file in each example directory ("lpc17xx_libcfg.h") must be included, |
frank26080115 | 0:84d7747641aa | 31 | * otherwise the default FW library configuration file must be included instead |
frank26080115 | 0:84d7747641aa | 32 | */ |
frank26080115 | 0:84d7747641aa | 33 | #ifdef __BUILD_WITH_EXAMPLE__ |
frank26080115 | 0:84d7747641aa | 34 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:84d7747641aa | 35 | #else |
frank26080115 | 0:84d7747641aa | 36 | #include "lpc17xx_libcfg_default.h" |
frank26080115 | 0:84d7747641aa | 37 | #endif /* __BUILD_WITH_EXAMPLE__ */ |
frank26080115 | 0:84d7747641aa | 38 | |
frank26080115 | 0:84d7747641aa | 39 | |
frank26080115 | 0:84d7747641aa | 40 | #ifdef _DAC |
frank26080115 | 0:84d7747641aa | 41 | |
frank26080115 | 0:84d7747641aa | 42 | /* Public Functions ----------------------------------------------------------- */ |
frank26080115 | 0:84d7747641aa | 43 | /** @addtogroup DAC_Public_Functions |
frank26080115 | 0:84d7747641aa | 44 | * @{ |
frank26080115 | 0:84d7747641aa | 45 | */ |
frank26080115 | 0:84d7747641aa | 46 | |
frank26080115 | 0:84d7747641aa | 47 | /*********************************************************************//** |
frank26080115 | 0:84d7747641aa | 48 | * @brief Initial ADC configuration |
frank26080115 | 0:84d7747641aa | 49 | * - Maximum current is 700 uA |
frank26080115 | 0:84d7747641aa | 50 | * - Value to AOUT is 0 |
frank26080115 | 0:84d7747641aa | 51 | * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC |
frank26080115 | 0:84d7747641aa | 52 | * @return None |
frank26080115 | 0:84d7747641aa | 53 | ***********************************************************************/ |
frank26080115 | 0:84d7747641aa | 54 | void DAC_Init(LPC_DAC_TypeDef *DACx) |
frank26080115 | 0:84d7747641aa | 55 | { |
frank26080115 | 0:84d7747641aa | 56 | CHECK_PARAM(PARAM_DACx(DACx)); |
frank26080115 | 0:84d7747641aa | 57 | /* Set default clock divider for DAC */ |
frank26080115 | 0:84d7747641aa | 58 | // CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_DAC, CLKPWR_PCLKSEL_CCLK_DIV_4); |
frank26080115 | 0:84d7747641aa | 59 | //Set maximum current output |
frank26080115 | 0:84d7747641aa | 60 | DAC_SetBias(LPC_DAC,DAC_MAX_CURRENT_700uA); |
frank26080115 | 0:84d7747641aa | 61 | } |
frank26080115 | 0:84d7747641aa | 62 | |
frank26080115 | 0:84d7747641aa | 63 | /*********************************************************************//** |
frank26080115 | 0:84d7747641aa | 64 | * @brief Update value to DAC |
frank26080115 | 0:84d7747641aa | 65 | * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC |
frank26080115 | 0:84d7747641aa | 66 | * @param[in] dac_value : value 10 bit to be converted to output |
frank26080115 | 0:84d7747641aa | 67 | * @return None |
frank26080115 | 0:84d7747641aa | 68 | ***********************************************************************/ |
frank26080115 | 0:84d7747641aa | 69 | void DAC_UpdateValue (LPC_DAC_TypeDef *DACx,uint32_t dac_value) |
frank26080115 | 0:84d7747641aa | 70 | { |
frank26080115 | 0:84d7747641aa | 71 | uint32_t tmp; |
frank26080115 | 0:84d7747641aa | 72 | CHECK_PARAM(PARAM_DACx(DACx)); |
frank26080115 | 0:84d7747641aa | 73 | tmp = DACx->DACR & DAC_BIAS_EN; |
frank26080115 | 0:84d7747641aa | 74 | tmp |= DAC_VALUE(dac_value); |
frank26080115 | 0:84d7747641aa | 75 | // Update value |
frank26080115 | 0:84d7747641aa | 76 | DACx->DACR = tmp; |
frank26080115 | 0:84d7747641aa | 77 | } |
frank26080115 | 0:84d7747641aa | 78 | |
frank26080115 | 0:84d7747641aa | 79 | /*********************************************************************//** |
frank26080115 | 0:84d7747641aa | 80 | * @brief Set Maximum current for DAC |
frank26080115 | 0:84d7747641aa | 81 | * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC |
frank26080115 | 0:84d7747641aa | 82 | * @param[in] bias : 0 is 700 uA |
frank26080115 | 0:84d7747641aa | 83 | * 1 350 uA |
frank26080115 | 0:84d7747641aa | 84 | * @return None |
frank26080115 | 0:84d7747641aa | 85 | ***********************************************************************/ |
frank26080115 | 0:84d7747641aa | 86 | void DAC_SetBias (LPC_DAC_TypeDef *DACx,uint32_t bias) |
frank26080115 | 0:84d7747641aa | 87 | { |
frank26080115 | 0:84d7747641aa | 88 | CHECK_PARAM(PARAM_DAC_CURRENT_OPT(bias)); |
frank26080115 | 0:84d7747641aa | 89 | DACx->DACR &=~DAC_BIAS_EN; |
frank26080115 | 0:84d7747641aa | 90 | if (bias == DAC_MAX_CURRENT_350uA) |
frank26080115 | 0:84d7747641aa | 91 | { |
frank26080115 | 0:84d7747641aa | 92 | DACx->DACR |= DAC_BIAS_EN; |
frank26080115 | 0:84d7747641aa | 93 | } |
frank26080115 | 0:84d7747641aa | 94 | } |
frank26080115 | 0:84d7747641aa | 95 | |
frank26080115 | 0:84d7747641aa | 96 | /*********************************************************************//** |
frank26080115 | 0:84d7747641aa | 97 | * @brief To enable the DMA operation and control DMA timer |
frank26080115 | 0:84d7747641aa | 98 | * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC |
frank26080115 | 0:84d7747641aa | 99 | * @param[in] DAC_ConverterConfigStruct pointer to DAC_CONVERTER_CFG_Type |
frank26080115 | 0:84d7747641aa | 100 | * - DBLBUF_ENA : enable/disable DACR double buffering feature |
frank26080115 | 0:84d7747641aa | 101 | * - CNT_ENA : enable/disable timer out counter |
frank26080115 | 0:84d7747641aa | 102 | * - DMA_ENA : enable/disable DMA access |
frank26080115 | 0:84d7747641aa | 103 | * @return None |
frank26080115 | 0:84d7747641aa | 104 | ***********************************************************************/ |
frank26080115 | 0:84d7747641aa | 105 | void DAC_ConfigDAConverterControl (LPC_DAC_TypeDef *DACx,DAC_CONVERTER_CFG_Type *DAC_ConverterConfigStruct) |
frank26080115 | 0:84d7747641aa | 106 | { |
frank26080115 | 0:84d7747641aa | 107 | CHECK_PARAM(PARAM_DACx(DACx)); |
frank26080115 | 0:84d7747641aa | 108 | DACx->DACCTRL &= ~DAC_DACCTRL_MASK; |
frank26080115 | 0:84d7747641aa | 109 | if (DAC_ConverterConfigStruct->DBLBUF_ENA) |
frank26080115 | 0:84d7747641aa | 110 | DACx->DACCTRL |= DAC_DBLBUF_ENA; |
frank26080115 | 0:84d7747641aa | 111 | if (DAC_ConverterConfigStruct->CNT_ENA) |
frank26080115 | 0:84d7747641aa | 112 | DACx->DACCTRL |= DAC_CNT_ENA; |
frank26080115 | 0:84d7747641aa | 113 | if (DAC_ConverterConfigStruct->DMA_ENA) |
frank26080115 | 0:84d7747641aa | 114 | DACx->DACCTRL |= DAC_DMA_ENA; |
frank26080115 | 0:84d7747641aa | 115 | } |
frank26080115 | 0:84d7747641aa | 116 | |
frank26080115 | 0:84d7747641aa | 117 | /*********************************************************************//** |
frank26080115 | 0:84d7747641aa | 118 | * @brief Set reload value for interrupt/DMA counter |
frank26080115 | 0:84d7747641aa | 119 | * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC |
frank26080115 | 0:84d7747641aa | 120 | * @param[in] time_out time out to reload for interrupt/DMA counter |
frank26080115 | 0:84d7747641aa | 121 | * @return None |
frank26080115 | 0:84d7747641aa | 122 | ***********************************************************************/ |
frank26080115 | 0:84d7747641aa | 123 | void DAC_SetDMATimeOut(LPC_DAC_TypeDef *DACx, uint32_t time_out) |
frank26080115 | 0:84d7747641aa | 124 | { |
frank26080115 | 0:84d7747641aa | 125 | CHECK_PARAM(PARAM_DACx(DACx)); |
frank26080115 | 0:84d7747641aa | 126 | DACx->DACCNTVAL = DAC_CCNT_VALUE(time_out); |
frank26080115 | 0:84d7747641aa | 127 | } |
frank26080115 | 0:84d7747641aa | 128 | |
frank26080115 | 0:84d7747641aa | 129 | /** |
frank26080115 | 0:84d7747641aa | 130 | * @} |
frank26080115 | 0:84d7747641aa | 131 | */ |
frank26080115 | 0:84d7747641aa | 132 | |
frank26080115 | 0:84d7747641aa | 133 | #endif /* _DAC */ |
frank26080115 | 0:84d7747641aa | 134 | |
frank26080115 | 0:84d7747641aa | 135 | /** |
frank26080115 | 0:84d7747641aa | 136 | * @} |
frank26080115 | 0:84d7747641aa | 137 | */ |
frank26080115 | 0:84d7747641aa | 138 | |
frank26080115 | 0:84d7747641aa | 139 | /* --------------------------------- End Of File ------------------------------ */ |