uint16_t dataADC1; Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7, IOCON_FUNC2 | IOCON_ADMODE_EN | IOCON_MODE_INACT); ADC_CLOCK_SETUP_T adcClockCfg; Chip_ADC_Init(LPC_ADC, &adcClockCfg); Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, ENABLE); while(1) { /* Start A/D conversion */ Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT) != SET); /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, &dataADC1); } |
/* Initialize the ADC peripheral and the ADC setup structure to default value */ void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup) { uint8_t div; uint32_t cr = 0; uint32_t clk; Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC_PD); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC); pADC->INTEN = 0;/* Disable all interrupts */ cr |= ADC_CR_PDN; ADCSetup->adcRate = ADC_MAX_SAMPLE_RATE; ADCSetup->bitsAccuracy = ADC_10BITS; clk = 11; ADCSetup->burstMode = false; div = getClkDiv(pADC, false, ADCSetup->adcRate, clk); cr |= ADC_CR_CLKDIV(div); cr |= ADC_CR_BITACC(ADCSetup->bitsAccuracy); pADC->CR = cr; } |
/* Initialize the ADC peripheral and the ADC setup structure to default value */ void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup) { uint8_t div; uint32_t cr = 0; uint32_t clk; Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC_PD); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC); pADC->INTEN = 0;/* Disable all interrupts */ //cr |= ADC_CR_PDN; ADCSetup->adcRate = ADC_MAX_SAMPLE_RATE; ADCSetup->bitsAccuracy = ADC_10BITS; clk = 11; ADCSetup->burstMode = false; div = getClkDiv(pADC, false, ADCSetup->adcRate, clk); cr |= ADC_CR_CLKDIV(div); cr |= ADC_CR_BITACC(ADCSetup->bitsAccuracy); pADC->CR = cr; } |