These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /*****
frank26080115 0:bf7b9fba3924 2 * @file dac_sinewave_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to use DAC to generate a sine wave
frank26080115 0:bf7b9fba3924 4 * using DMA to transfer data
frank26080115 0:bf7b9fba3924 5 * @version 2.0
frank26080115 0:bf7b9fba3924 6 * @date 04. June. 2010
frank26080115 0:bf7b9fba3924 7 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 8 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 9 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 10 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 11 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 12 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 13 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 14 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 15 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 16 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 17 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 18 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 19 **********************************************************************/
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_dac.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_gpdma.h"
frank26080115 0:bf7b9fba3924 24
frank26080115 0:bf7b9fba3924 25 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 26 /** @defgroup DAC_SineWave SineWave
frank26080115 0:bf7b9fba3924 27 * @ingroup DAC_Examples
frank26080115 0:bf7b9fba3924 28 * @{
frank26080115 0:bf7b9fba3924 29 */
frank26080115 0:bf7b9fba3924 30
frank26080115 0:bf7b9fba3924 31 /************************** PRIVATE MACROS *************************/
frank26080115 0:bf7b9fba3924 32 /** DMA size of transfer */
frank26080115 0:bf7b9fba3924 33 #define DMA_SIZE 60
frank26080115 0:bf7b9fba3924 34 #define NUM_SINE_SAMPLE 60
frank26080115 0:bf7b9fba3924 35 #define SINE_FREQ_IN_HZ 60
frank26080115 0:bf7b9fba3924 36 #define PCLK_DAC_IN_MHZ 25 //CCLK divided by 4
frank26080115 0:bf7b9fba3924 37
frank26080115 0:bf7b9fba3924 38 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 39 GPDMA_Channel_CFG_Type GPDMACfg;
frank26080115 0:bf7b9fba3924 40
frank26080115 0:bf7b9fba3924 41 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 42 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 43 * @brief c_entry: Main DAC program body
frank26080115 0:bf7b9fba3924 44 * @param[in] None
frank26080115 0:bf7b9fba3924 45 * @return int
frank26080115 0:bf7b9fba3924 46 **********************************************************************/
frank26080115 0:bf7b9fba3924 47 int c_entry(void)
frank26080115 0:bf7b9fba3924 48 {
frank26080115 0:bf7b9fba3924 49 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 50 DAC_CONVERTER_CFG_Type DAC_ConverterConfigStruct;
frank26080115 0:bf7b9fba3924 51 GPDMA_LLI_Type DMA_LLI_Struct;
frank26080115 0:bf7b9fba3924 52 uint32_t tmp;
frank26080115 0:bf7b9fba3924 53 uint32_t i;
frank26080115 0:bf7b9fba3924 54 uint32_t sin_0_to_90_16_samples[16]={\
frank26080115 0:bf7b9fba3924 55 0,1045,2079,3090,4067,\
frank26080115 0:bf7b9fba3924 56 5000,5877,6691,7431,8090,\
frank26080115 0:bf7b9fba3924 57 8660,9135,9510,9781,9945,10000\
frank26080115 0:bf7b9fba3924 58 };
frank26080115 0:bf7b9fba3924 59 uint32_t dac_sine_lut[NUM_SINE_SAMPLE];
frank26080115 0:bf7b9fba3924 60 /*
frank26080115 0:bf7b9fba3924 61 * Init DAC pin connect
frank26080115 0:bf7b9fba3924 62 * AOUT on P0.26
frank26080115 0:bf7b9fba3924 63 */
frank26080115 0:bf7b9fba3924 64 PinCfg.Funcnum = 2;
frank26080115 0:bf7b9fba3924 65 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 66 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 67 PinCfg.Pinnum = 26;
frank26080115 0:bf7b9fba3924 68 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 69 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 70
frank26080115 0:bf7b9fba3924 71 //Prepare DAC sine look up table
frank26080115 0:bf7b9fba3924 72 for(i=0;i<NUM_SINE_SAMPLE;i++)
frank26080115 0:bf7b9fba3924 73 {
frank26080115 0:bf7b9fba3924 74 if(i<=15)
frank26080115 0:bf7b9fba3924 75 {
frank26080115 0:bf7b9fba3924 76 dac_sine_lut[i] = 512 + 512*sin_0_to_90_16_samples[i]/10000;
frank26080115 0:bf7b9fba3924 77 if(i==15) dac_sine_lut[i]= 1023;
frank26080115 0:bf7b9fba3924 78 }
frank26080115 0:bf7b9fba3924 79 else if(i<=30)
frank26080115 0:bf7b9fba3924 80 {
frank26080115 0:bf7b9fba3924 81 dac_sine_lut[i] = 512 + 512*sin_0_to_90_16_samples[30-i]/10000;
frank26080115 0:bf7b9fba3924 82 }
frank26080115 0:bf7b9fba3924 83 else if(i<=45)
frank26080115 0:bf7b9fba3924 84 {
frank26080115 0:bf7b9fba3924 85 dac_sine_lut[i] = 512 - 512*sin_0_to_90_16_samples[i-30]/10000;
frank26080115 0:bf7b9fba3924 86 }
frank26080115 0:bf7b9fba3924 87 else
frank26080115 0:bf7b9fba3924 88 {
frank26080115 0:bf7b9fba3924 89 dac_sine_lut[i] = 512 - 512*sin_0_to_90_16_samples[60-i]/10000;
frank26080115 0:bf7b9fba3924 90 }
frank26080115 0:bf7b9fba3924 91 dac_sine_lut[i] = (dac_sine_lut[i]<<6);
frank26080115 0:bf7b9fba3924 92 }
frank26080115 0:bf7b9fba3924 93 //Prepare DMA link list item structure
frank26080115 0:bf7b9fba3924 94 DMA_LLI_Struct.SrcAddr= (uint32_t)dac_sine_lut;
frank26080115 0:bf7b9fba3924 95 DMA_LLI_Struct.DstAddr= (uint32_t)&(LPC_DAC->DACR);
frank26080115 0:bf7b9fba3924 96 DMA_LLI_Struct.NextLLI= (uint32_t)&DMA_LLI_Struct;
frank26080115 0:bf7b9fba3924 97 DMA_LLI_Struct.Control= DMA_SIZE
frank26080115 0:bf7b9fba3924 98 | (2<<18) //source width 32 bit
frank26080115 0:bf7b9fba3924 99 | (2<<21) //dest. width 32 bit
frank26080115 0:bf7b9fba3924 100 | (1<<26) //source increment
frank26080115 0:bf7b9fba3924 101 ;
frank26080115 0:bf7b9fba3924 102
frank26080115 0:bf7b9fba3924 103 /* GPDMA block section -------------------------------------------- */
frank26080115 0:bf7b9fba3924 104 /* Initialize GPDMA controller */
frank26080115 0:bf7b9fba3924 105 GPDMA_Init();
frank26080115 0:bf7b9fba3924 106
frank26080115 0:bf7b9fba3924 107 // Setup GPDMA channel --------------------------------
frank26080115 0:bf7b9fba3924 108 // channel 0
frank26080115 0:bf7b9fba3924 109 GPDMACfg.ChannelNum = 0;
frank26080115 0:bf7b9fba3924 110 // Source memory
frank26080115 0:bf7b9fba3924 111 GPDMACfg.SrcMemAddr = (uint32_t)(dac_sine_lut);
frank26080115 0:bf7b9fba3924 112 // Destination memory - unused
frank26080115 0:bf7b9fba3924 113 GPDMACfg.DstMemAddr = 0;
frank26080115 0:bf7b9fba3924 114 // Transfer size
frank26080115 0:bf7b9fba3924 115 GPDMACfg.TransferSize = DMA_SIZE;
frank26080115 0:bf7b9fba3924 116 // Transfer width - unused
frank26080115 0:bf7b9fba3924 117 GPDMACfg.TransferWidth = 0;
frank26080115 0:bf7b9fba3924 118 // Transfer type
frank26080115 0:bf7b9fba3924 119 GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P;
frank26080115 0:bf7b9fba3924 120 // Source connection - unused
frank26080115 0:bf7b9fba3924 121 GPDMACfg.SrcConn = 0;
frank26080115 0:bf7b9fba3924 122 // Destination connection
frank26080115 0:bf7b9fba3924 123 GPDMACfg.DstConn = GPDMA_CONN_DAC;
frank26080115 0:bf7b9fba3924 124 // Linker List Item - unused
frank26080115 0:bf7b9fba3924 125 GPDMACfg.DMALLI = (uint32_t)&DMA_LLI_Struct;
frank26080115 0:bf7b9fba3924 126 // Setup channel with given parameter
frank26080115 0:bf7b9fba3924 127 GPDMA_Setup(&GPDMACfg);
frank26080115 0:bf7b9fba3924 128
frank26080115 0:bf7b9fba3924 129 DAC_ConverterConfigStruct.CNT_ENA =SET;
frank26080115 0:bf7b9fba3924 130 DAC_ConverterConfigStruct.DMA_ENA = SET;
frank26080115 0:bf7b9fba3924 131 DAC_Init(LPC_DAC);
frank26080115 0:bf7b9fba3924 132 /* set time out for DAC*/
frank26080115 0:bf7b9fba3924 133 tmp = (PCLK_DAC_IN_MHZ*1000000)/(SINE_FREQ_IN_HZ*NUM_SINE_SAMPLE);
frank26080115 0:bf7b9fba3924 134 DAC_SetDMATimeOut(LPC_DAC,tmp);
frank26080115 0:bf7b9fba3924 135 DAC_ConfigDAConverterControl(LPC_DAC, &DAC_ConverterConfigStruct);
frank26080115 0:bf7b9fba3924 136
frank26080115 0:bf7b9fba3924 137 // Enable GPDMA channel 0
frank26080115 0:bf7b9fba3924 138 GPDMA_ChannelCmd(0, ENABLE);
frank26080115 0:bf7b9fba3924 139
frank26080115 0:bf7b9fba3924 140 while (1);
frank26080115 0:bf7b9fba3924 141
frank26080115 0:bf7b9fba3924 142 return 1;
frank26080115 0:bf7b9fba3924 143 }
frank26080115 0:bf7b9fba3924 144 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 145 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 146 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 147 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 148 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 149 int main(void)
frank26080115 0:bf7b9fba3924 150 {
frank26080115 0:bf7b9fba3924 151 return c_entry();
frank26080115 0:bf7b9fba3924 152 }
frank26080115 0:bf7b9fba3924 153
frank26080115 0:bf7b9fba3924 154 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 155 /*******************************************************************************
frank26080115 0:bf7b9fba3924 156 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 157 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 158 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 159 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 160 * @return None
frank26080115 0:bf7b9fba3924 161 *******************************************************************************/
frank26080115 0:bf7b9fba3924 162 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 163 {
frank26080115 0:bf7b9fba3924 164 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 165 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 /* Infinite loop */
frank26080115 0:bf7b9fba3924 168 while(1);
frank26080115 0:bf7b9fba3924 169 }
frank26080115 0:bf7b9fba3924 170 #endif
frank26080115 0:bf7b9fba3924 171 /*
frank26080115 0:bf7b9fba3924 172 * @}
frank26080115 0:bf7b9fba3924 173 */