void Init_ADC (uint8_t Frequency)
{
LPC_SYSCON->PDRUNCFG &= ~(0x1<<4); //power the ADC (sec. 3.5.35)
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13); //enable clock for ADC (sec. 3.5.14)
LPC_IOCON->R_PIO0_11 &= 0xFFFFFF78; //clear FUNC field for pin 32, set to analog input (sec. 7.4.28)
LPC_IOCON->R_PIO0_11 |= (1<<1); //set to ADC mode for pin 32 (sec. 7.4.28)
LPC_IOCON->R_PIO1_0&= 0xFFFFFF78; //clear FUNC field for pin 33, set to analog input (sec. 7.4.29)
LPC_IOCON->R_PIO1_0 |= (1<<1); //set to ADC mode for pin 33 (sec. 7.4.29)
LPC_ADC->CR = 0x0B03; //select ADC channel AD0 (pin 32) and AD1 (pin33), set up clock (sec 25.5.1)
}
uint16_t ADC_Read (uint8_t Channel)
{
uint16_t Data = 0;
LPC_ADC->CR |= (1<<24); //start conversion by setting "Start Conversion Now" bit (sec. 25.5.1)
while((LPC_ADC->DR[Channel] < 0x7FFFFFFF));//wait for "done" bit to be set (sec. 25.5.4)
Data = (LPC_ADC->DR[Channel] & 0xFFC0) >> 6;
return (Data);
} |