I am trying to understand the functioning of the ADC on my UC3 device and having followed several posts, I got here.
The code is from a project in which the originator had the following setting for clocks:
OSC0 - 16MHz
PLL0 - 96Mhz
MainClock - 48MHz
PBA/PBB Clock -24MHz
CLK_ADC = PBA CLK = 24Mhz
static void setMainClock(void)
//// Enable the external Osc0 of 16Mhz
////Enable the PLL at 96MHz
pm_pll_setup(&AVR32_PM, 0, 2, 0, 0, 16);
//////PLL output VCO frequency at 48MHz
//pm_pll_set_option(&AVR32_PM, 0, 0, 1, 0);
pm_pll_set_option(&AVR32_PM, 0, 1, 1, 0);
///////Wait for PLL0 locked
//////Set PBA and PBB clocks by 2 from main clock at 24 MHz
pm_cksel(&AVR32_PM, 1, 0, 1, 0, 0, 0); //default
/////Set PLL0 as main clock to 48MHz
pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCSEL_PLL0); //default
AVR32_ADC.mr |= 0x4 << AVR32_ADC_MR_PRESCAL_OFFSET; // ~ 4.8 MHz
From the "AVR32_ADC.mr |= 0x4 << AVR32_ADC_MR_PRESCAL_OFFSET; // ~ 4.8 MHz" is this correctly 4.8MHz or 2.4MHz? My calculations says it is 2.4MHz but the comments indicate 4.8MHz. And I am now somehow confused.
Also, how do I set/change sampling frequency of an UC3's ADC. The originator claimed he was using a sampling frequency 250Hz, but I can not see where to set such frequency. Please guide me.