Pages: [1] 2   Go Down
Author Topic: change ADC clock  (Read 1088 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,

I needed set sampling frequency = 25 KHz .
I used the sequinte code:


int ACTUAL_ADC_CLK;

void setup() {

 Serial.begin(9600);

 analogReadResolution(12);
 
//uint32_t adc_init(Adc *p_adc, const uint32_t ul_mck, const uint32_t ul_adc_clock, const uint32_t ul_startuptime)
// ul_mck Main clock of the device (value in Hz).
 // ul_adc_clock Analog-to-Digital conversion clock (in Hz).
 //ul_startuptime ADC startup time value (value in us).
 
adc_init(ADC, SystemCoreClock, 25000, 12);

}

void loop() {

 //return adc clock
  ACTUAL_ADC_CLK = adc_get_actual_adc_clock(ADC, SystemCoreClock);
  Serial.println(ACTUAL_ADC_CLK);
  while (1) {} 
 
}


The program output is 291666 Hz (292KHz).





Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The program output is  291666

ACTUAL_ADC_CLK is an int.  How can an int be 291666?
Logged

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

I do not know
the program must return the value of adc clock in Hz, ie should return 25000 and not 291666.

removing the following line of code (adc_init (ADC, SystemCoreClock, 25000, 12)smiley-wink the return value would be 21000000 since it is the maximum frequency adc.
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 123
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The program output is  291666

ACTUAL_ADC_CLK is an int.  How can an int be 291666?
Why not? An int is 32 bit.
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

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

any idea how sampling frequency to a specific value ?
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 123
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you have to set the ul_mck to 25000 and ul_adc_clock to SystemCoreClock / 2
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

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


It doesn't work.
   
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 123
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


It doesn't work.
   

What is the frequency if you do that?
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

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

164004 Hz
Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote from: groundfungus on Today at 02:12:41 am
Quote
The program output is  291666

ACTUAL_ADC_CLK is an int.  How can an int be 291666?
Why not? An int is 32 bit.

int is 2 bytes.  16 bit, ±32K.  Long is 4 bytes.  32 bits.
Logged

The Netherlands
Offline Offline
Full Member
***
Karma: 1
Posts: 123
MKDS hacker and Programmer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote from: groundfungus on Today at 02:12:41 am
Quote
The program output is  291666

ACTUAL_ADC_CLK is an int.  How can an int be 291666?
Why not? An int is 32 bit.

int is 2 bytes.  16 bit, ±32K.  Long is 4 bytes.  32 bits.
I thought that was on an original arduino. On a due int is 32bit as far as I know.
Logged

Subscribe my youtube channel: http://www.youtube.com/user/MKDS3

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

I think the clock in adc arduino due is limited to 164kHz.

the manual of arduino due says:

"The ADC clock range is between MCK/2, if PRESCAL is 0, and MCK/512, if PRESCAL is set to
255 (0xFF). PRESCAL must be programmed in order to provide an ADC clock frequency
according to the parameters given in the product Electrical Characteristics section."
Logged

Venezuela
Offline Offline
Sr. Member
****
Karma: 12
Posts: 433
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  ACTUAL_ADC_CLK = adc_get_actual_adc_clock(ADC, SystemCoreClock/11.6666);
Logged

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

the output is 1800120
I wanted 25000

the maximum I can get is 164000.
Logged

Venezuela
Offline Offline
Sr. Member
****
Karma: 12
Posts: 433
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I overlooked you quote from the Atmel's manual but I believe you already gave yourself the answer: ADC can't be 25KHz. ADC minimum possible value is MCK/255 and the maximum is MCK/2. For 25000, your Master Clock Frequency should be 6375000. The function sysclk_get_main_hz() gives you the MCK for the SAM3X8E which is 84000000 (12nS). Thus, your desire ADC clock can be reached. May be we could help you a bit more if you tell us why you need 25KHz for your ADC clock? Regards!
Logged

Pages: [1] 2   Go Up
Jump to: