void HalAdcInit(void) { // Configure pin as ADC peripheral IOCON_PIO0_30 |= 3; // channel AD0 IOCON_PIO0_30 &= 0xFF7F; // Pin as analog PDRUNCFG_bit.ADC_PD = 0; // Enable Power on ADC SYSAHBCLKCTRL_bit.ADC = 1; // Enable ADC clock AD0CR_bit.CLKDIV = 3; // Divider (value + 1) for APB clock to have an ADC clock // less than 9 MHz // ADC clock = System clock / (CLKDIV + 1) // 33177600 / 4 // 8294400 Hz AD0CR_bit.SEL = 1; AD0CR_bit.BURST = 0; // Conversion are software controlled AD0CR_bit.START = 0; // A/D conversion stop }/*END HalAdcInit*/ |
void HalAdcTest2(void) { UVAR_16 i; UVAR_16 tab[400]; memset(tab, 0, sizeof(tab)); while (1) { for (i = 0; i < 400; i++) { AD0CR_bit.START = 1; while (AD0DR0_bit.DONE != 1); AD0CR_bit.START = 0; tab = AD0DR0_bit.RESULT; } } } |