Go Down

Topic: Prescaler setting in Arduino Due (Read 2374 times) previous topic - next topic

bienle

Hi, I want to reduce the prescaler factor so that my Arduino Due takes less time for executing a command (analogRead() ). I had seen some sample codes for setting the prescaler in other Arduino boards, they use the ADCSRA register for doing that. But when I search in the datasheet of Arduino Due Atmega, that register does not exist.
So my question is : Is it possible to set the prescaler factor in Arduino Due ? And if yes, can someone help me with a simple code.

Thanks very much.

MarkT

That's not appropriate to the Due, which has a completely different architecture.
The chips already setup at the maximum clockspeed it supports.

If you want faster than the existing analogRead() you'll need to setup
times and DMA or interrupts to trigger conversions and store the results,
a minimum of 3 hours reading the datasheet (!)

IIRC the current Due analogRead() is 2us or less.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

bienle

Thank you @MarkT

Is it the same for every Arduino Due ? (If there are several arduino Due members. I don't know).
If it's  2us for an analogRead(), then it's perfect for me. But I had read some posts which say Due takes about 39us for an analogRead() in default setting. If I want to make it shorter, I can change something in the master clock MCLK. 

And by the way, what is IIRC o_O???? Thanks

ale16289

Hi this is an example of cide that I wrote in order to make ADC read faster
Code: [Select]
ADC->ADC_WPMR = 0x00;//Disables the write protect key, WPEN
  ADC->ADC_MR = 0x00000000;//clear all the before setted characteristics of ADC
  // set ADC prescaler to 8
  bitSet(ADC->ADC_MR,8); 
  bitSet(ADC->ADC_MR,9);
  ADC->ADC_CHDR |=0xC300;//disable channel 15,14,9,8 (not connected on Arduino Due)
  ADC->ADC_CHER |=0x3CFF;//enable remaining channel
  ADC->ADC_CGR |=gain2register;//set ADC gain
  delay(1000);//delay of 1 s for stability
  Serial.println(ADC->ADC_CGR); //I have to see the current gain, for debug
  Serial.println(ADC->ADC_CHSR); //I have to see 15615, for debug
  ADC->ADC_CR = 2; //start conversion

miaz

for prescaler 8

bitSet(ADC->ADC_MR,11)

setting 8,9 bits makes prescaler=2

Sadoo2010

#5
Nov 02, 2017, 11:54 am Last Edit: Nov 02, 2017, 12:01 pm by Sadoo2010
Hi
Please explain which number is exactly the prescale number?
Is the system clock divided by 8،9،11?
Do not need to be binary? Or ASCII Code?
What is the (->)
Where exactly is the prescale register location? Namely, in the ADC-Mode Register, you should immediately enter the Prescale value?
And I want to see the adc clock number after the split on my serial monitor,Can the place be read from the registry?  What is its name?
  (ADC->ADC_CR = 2; //start conversion) what is the 2 ?number of channel ?
Please guide me this is my email
Sadoo2010@gmail.com
I'm doing something that may helps others.
Thank you.

ard_newbie

There are several ways to trigger ADC conversions, and there are numerous example sketches of ADC conversions in this forum.

I suggest you read the ADC section of Sam3x datasheet in order to fully understand the example sketches.

Some of these examples:

PWM triggered ADC, reply #9:
https://forum.arduino.cc/index.php?topic=332795.0


ADC in freerun mode, reply #3:
https://forum.arduino.cc/index.php?topic=482205.0


ADC conversions triggered by a Timer Counter, reply #1:
https://forum.arduino.cc/index.php?
topic=487989.0



Go Up