My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lpc17xx_dac.c 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /* Peripheral group ----------------------------------------------------------- */
  32. /** @addtogroup DAC
  33. * @{
  34. */
  35. /* Includes ------------------------------------------------------------------- */
  36. #include "lpc17xx_dac.h"
  37. #include "lpc17xx_clkpwr.h"
  38. /* If this source file built with example, the LPC17xx FW library configuration
  39. * file in each example directory ("lpc17xx_libcfg.h") must be included,
  40. * otherwise the default FW library configuration file must be included instead
  41. */
  42. #ifdef __BUILD_WITH_EXAMPLE__
  43. #include "lpc17xx_libcfg.h"
  44. #else
  45. #include "lpc17xx_libcfg_default.h"
  46. #endif /* __BUILD_WITH_EXAMPLE__ */
  47. #ifdef _DAC
  48. /* Public Functions ----------------------------------------------------------- */
  49. /** @addtogroup DAC_Public_Functions
  50. * @{
  51. */
  52. /*********************************************************************//**
  53. * @brief Initial ADC configuration
  54. * - Maximum current is 700 uA
  55. * - Value to AOUT is 0
  56. * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
  57. * @return None
  58. ***********************************************************************/
  59. void DAC_Init(LPC_DAC_TypeDef *DACx)
  60. {
  61. CHECK_PARAM(PARAM_DACx(DACx));
  62. /* Set default clock divider for DAC */
  63. // CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_DAC, CLKPWR_PCLKSEL_CCLK_DIV_4);
  64. //Set maximum current output
  65. DAC_SetBias(LPC_DAC,DAC_MAX_CURRENT_700uA);
  66. }
  67. /*********************************************************************//**
  68. * @brief Update value to DAC
  69. * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
  70. * @param[in] dac_value : value 10 bit to be converted to output
  71. * @return None
  72. ***********************************************************************/
  73. void DAC_UpdateValue (LPC_DAC_TypeDef *DACx,uint32_t dac_value)
  74. {
  75. uint32_t tmp;
  76. CHECK_PARAM(PARAM_DACx(DACx));
  77. tmp = DACx->DACR & DAC_BIAS_EN;
  78. tmp |= DAC_VALUE(dac_value);
  79. // Update value
  80. DACx->DACR = tmp;
  81. }
  82. /*********************************************************************//**
  83. * @brief Set Maximum current for DAC
  84. * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
  85. * @param[in] bias : 0 is 700 uA
  86. * 1 350 uA
  87. * @return None
  88. ***********************************************************************/
  89. void DAC_SetBias (LPC_DAC_TypeDef *DACx,uint32_t bias)
  90. {
  91. CHECK_PARAM(PARAM_DAC_CURRENT_OPT(bias));
  92. DACx->DACR &=~DAC_BIAS_EN;
  93. if (bias == DAC_MAX_CURRENT_350uA)
  94. {
  95. DACx->DACR |= DAC_BIAS_EN;
  96. }
  97. }
  98. /*********************************************************************//**
  99. * @brief To enable the DMA operation and control DMA timer
  100. * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
  101. * @param[in] DAC_ConverterConfigStruct pointer to DAC_CONVERTER_CFG_Type
  102. * - DBLBUF_ENA : enable/disable DACR double buffering feature
  103. * - CNT_ENA : enable/disable timer out counter
  104. * - DMA_ENA : enable/disable DMA access
  105. * @return None
  106. ***********************************************************************/
  107. void DAC_ConfigDAConverterControl (LPC_DAC_TypeDef *DACx,DAC_CONVERTER_CFG_Type *DAC_ConverterConfigStruct)
  108. {
  109. CHECK_PARAM(PARAM_DACx(DACx));
  110. DACx->DACCTRL &= ~DAC_DACCTRL_MASK;
  111. if (DAC_ConverterConfigStruct->DBLBUF_ENA)
  112. DACx->DACCTRL |= DAC_DBLBUF_ENA;
  113. if (DAC_ConverterConfigStruct->CNT_ENA)
  114. DACx->DACCTRL |= DAC_CNT_ENA;
  115. if (DAC_ConverterConfigStruct->DMA_ENA)
  116. DACx->DACCTRL |= DAC_DMA_ENA;
  117. }
  118. /*********************************************************************//**
  119. * @brief Set reload value for interrupt/DMA counter
  120. * @param[in] DACx pointer to LPC_DAC_TypeDef, should be: LPC_DAC
  121. * @param[in] time_out time out to reload for interrupt/DMA counter
  122. * @return None
  123. ***********************************************************************/
  124. void DAC_SetDMATimeOut(LPC_DAC_TypeDef *DACx, uint32_t time_out)
  125. {
  126. CHECK_PARAM(PARAM_DACx(DACx));
  127. DACx->DACCNTVAL = DAC_CCNT_VALUE(time_out);
  128. }
  129. /**
  130. * @}
  131. */
  132. #endif /* _DAC */
  133. /**
  134. * @}
  135. */
  136. /* --------------------------------- End Of File ------------------------------ */