Go Down

Topic: Return the actual ADC clock (Read 553 times) previous topic - next topic

pedrolopes746

hello

the following function return the actual ADC clock:

Parameters:
    p_adc -   Pointer to an ADC instance.
       ul_mck -    Main clock of the device (in Hz)


uint32_t adc_get_actual_adc_clock(const Adc *p_adc, const uint32_t ul_mck)
{
   uint32_t ul_adcfreq;
   uint32_t ul_prescal;

   /* ADCClock = MCK / ( (PRESCAL+1) * 2 ) */
   ul_prescal = ((p_adc->ADC_MR & ADC_MR_PRESCAL_Msk) >> ADC_MR_PRESCAL_Pos);
   ul_adcfreq = ul_mck / ((ul_prescal + 1) * 2);
   return ul_adcfreq;
}

my doubt lies in const Adc *p_adc.
could someone give an example of application

Palliser

Hola pedrolopes746,

AFAIK, for all of the SAM3 microcontrollers, const Adc *p_adc points to 'ADC' which is the address of the ADC Control Register (ADC_CR) (0x400C0000U).
As you mentioned in your post, the routine returns a clock value. For the Arduino Due case this value in Hz is 21000000. Four times smaller of the main clock, normally, 84MHz.

The calculation of the ACD clock frequency is very simple:

Quote
ul_adcfreq = ul_mck / ((ul_prescal + 1) * 2);

where          ul_mck is the main frequency of the board = 84000000
                 ul_prescal is a 32-bit clock prescaler set to 1 (0xffu << 8)



Here a raw example sketch for Due:

Code: [Select]
int ACTUAL_ADC_CLK;
void setup() {
 Serial.begin(9600);
}

void loop() {
 // get and print current ADC clock (in Hz):
 ACTUAL_ADC_CLK = adc_get_actual_adc_clock(ADC, SystemCoreClock);
 Serial.println(ACTUAL_ADC_CLK);
 while (1) {}
}


The output:

Quote
21000000


Regards!

pedrolopes746


Go Up