Go Down

### Topic: change ADC clock (Read 5232 times)previous topic - next topic

#### pedrolopes746

##### Aug 23, 2013, 11:03 am
hello,

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

void setup() {

Serial.begin(9600);

// 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).

}

void loop() {

while (1) {}

}

The program output is 291666 Hz (292KHz).

#### groundFungus

#1
##### Aug 23, 2013, 11:12 am
Quote
The program output is  291666

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

#### pedrolopes746

#2
##### Aug 23, 2013, 11:44 am
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) the return value would be 21000000 since it is the maximum frequency adc.

#### Gericom

#3
##### Aug 23, 2013, 12:25 pm

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.

#### pedrolopes746

#4
##### Aug 23, 2013, 01:28 pm
any idea how sampling frequency to a specific value ?

#### Gericom

#5
##### Aug 23, 2013, 02:18 pm
I think you have to set the ul_mck to 25000 and ul_adc_clock to SystemCoreClock / 2

#6

It doesn't work.

#### Gericom

#7
##### Aug 23, 2013, 03:47 pm

It doesn't work.

What is the frequency if you do that?

#8
164004 Hz

#### groundFungus

#9
##### Aug 23, 2013, 04:16 pm
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.

#### Gericom

#10
##### Aug 23, 2013, 06:57 pm

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.

#### pedrolopes746

#11
##### Aug 23, 2013, 07:32 pm
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."

#### Palliser

#12
##### Aug 23, 2013, 08:00 pm
Code: [Select]
`  ACTUAL_ADC_CLK = adc_get_actual_adc_clock(ADC, SystemCoreClock/11.6666);`

#### pedrolopes746

#13
##### Aug 23, 2013, 08:32 pm
the output is 1800120
I wanted 25000

the maximum I can get is 164000.

#14