/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return None **********************************************************************/ void c_entry(void) { volatile uint32_t tmp; #if !__DMA_USED__ uint32_t adc_value; #endif uint8_t quit; EXTI_InitTypeDef EXTICfg; #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #endif GPIO_Init(); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Init ADC pin connect * AD0.2 on P0.25 */ PINSEL_ConfigPin(BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO); PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI /* * Init ADC pin connect * AD0.3 on P0.26 */ PINSEL_ConfigPin(0, 26, 1); PINSEL_SetAnalogPinMode(0,26,ENABLE); #endif /* Configuration for ADC: * select: ADC channel 2 * ADC channel 3 * ADC conversion rate = 400KHz */ ADC_Init(LPC_ADC, 400000); ADC_ChannelCmd(LPC_ADC,BRD_ADC_PREPARED_CHANNEL,ENABLE); #ifdef LPC177x_8x_ADC_BURST_MULTI ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE); #endif #ifdef LPC177x_8x_ADC_INJECT_TEST //Config P2.10 as EINT0 PINSEL_ConfigPin(2,10,1); EXTI_Init(); EXTICfg.EXTI_Line = EXTI_EINT0; /* edge sensitive */ EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE; EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE; EXTI_Config(&EXTICfg); GPIO_SetDir(LED_PORT,LED_PIN,1); GPIO_SetValue(LED_PORT,LED_PIN); NVIC_EnableIRQ(EINT0_IRQn); #endif #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory - unused GPDMACfg.SrcMemAddr = 0; // Destination memory GPDMACfg.DstMemAddr = (uint32_t)s_buf; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width - unused GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_ADC; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); while(1) { for(tmp = 0; tmp < 0x1000; tmp++); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; for(tmp = 0; tmp < DMA_SIZE; tmp++) { s_buf[tmp] = 0; } //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); GPDMA_Setup(&GPDMACfg); // Enable GPDMA channel 1 GPDMA_ChannelCmd(0, ENABLE); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0)); GPDMA_ChannelCmd(0, DISABLE); for(tmp = 0; tmp < DMA_SIZE; tmp++) { if(s_buf[tmp] & ADC_GDR_DONE_FLAG) { _DBG("ADC value on channel "); _DBD(ADC_GDR_CH(s_buf[tmp])); _DBG(": "); _DBD32(ADC_GDR_RESULT(s_buf[tmp]));_DBG_(""); } } if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #else //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); while(1) { adc_value = ADC_ChannelGetData(LPC_ADC,BRD_ADC_PREPARED_CHANNEL); _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL); _DBG(": "); _DBD32(adc_value); _DBG_(""); #ifdef LPC177x_8x_ADC_BURST_MULTI adc_value = ADC_ChannelGetData(LPC_ADC,_ADC_CHANNEL_n); _DBG("ADC value on channel 3: "); _DBD32(adc_value); _DBG_(""); #endif // Wait for a while for(tmp = 0; tmp < 1500000; tmp++); if(_DG_NONBLOCK(&quit) && (quit == 'Q' || quit == 'q')) break; } #endif /*__DMA_USED__*/ _DBG_("Demo termination!!!"); ADC_DeInit(LPC_ADC); GPIO_Deinit(); }
/*********************************************************************//** * @brief c_entry: Main ADC program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; #ifdef MCB_LPC_1768_ADC_BURST_MULTI PINSEL_CFG_Type PinCfg1; #endif uint32_t tmp; uint32_t adc_value; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Because the potentiometer on different boards (MCB & IAR) connect * with different ADC channel, so we have to configure correct ADC channel * on each board respectively. * If you want to check other ADC channels, you have to wire this ADC pin directly * to potentiometer pin (please see schematic doc for more reference) */ #ifdef MCB_LPC_1768 /* * Init ADC pin connect * AD0.2 on P0.25 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 25; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); #ifdef MCB_LPC_1768_ADC_BURST_MULTI /* * Init ADC pin connect * AD0.3 on P0.26 */ PinCfg1.Funcnum = 1; PinCfg1.OpenDrain = 0; PinCfg1.Pinmode = 0; PinCfg1.Pinnum = 26; PinCfg1.Portnum = 0; PINSEL_ConfigPin(&PinCfg1); #endif #elif defined (IAR_LPC_1768) /* select P1.31 as AD0.5 */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 31; PinCfg.Portnum = 1; PINSEL_ConfigPin(&PinCfg); #endif /* Configuration for ADC: * select: ADC channel 2 (if using MCB1700 board) * ADC channel 5 (if using IAR-LPC1768 board) * ADC conversion rate = 200KHz */ ADC_Init(LPC_ADC, 200000); ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE); #ifdef MCB_LPC_1768_ADC_BURST_MULTI ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE); #endif #ifdef MCB_LPC17XX_ADC_INJECT_TEST FIO_ByteSetDir(1, 3, POLL_LED, 1); FIO_ByteClearValue(1, 3, POLL_LED); // Enable GPIO interrupt P2.10 GPIO_IntCmd(2,(1<<10),1); NVIC_EnableIRQ(EINT3_IRQn); #endif //Start burst conversion ADC_BurstCmd(LPC_ADC,ENABLE); while(1) { #ifdef MCB_LPC_1768 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2); _DBG("ADC value on channel 2: "); #elif defined (IAR_LPC_1768) adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5); _DBG("ADC value on channel 5: "); #endif _DBD32(adc_value); _DBG_(""); #ifdef MCB_LPC_1768_ADC_BURST_MULTI adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_3); _DBG("ADC value on channel 3: "); _DBD32(adc_value); _DBG_(""); #endif // Wait for a while for(tmp = 0; tmp < 1500000; tmp++); } ADC_DeInit(LPC_ADC); return (0); }