Pages: [1]   Go Down
Author Topic: Return the actual ADC clock  (Read 521 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 << smiley-cool


Here a raw example sketch for Due:

Code:
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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your response
Logged

Pages: [1]   Go Up
Jump to: