Go Down

Topic: Feedback Controller Implementation Best Practices (Read 1 time) previous topic - next topic

Coding Badly

#15
Nov 12, 2012, 05:51 am Last Edit: Nov 12, 2012, 05:53 am by Coding Badly Reason: 1
Should I put the delay after ADMUX |= (1<<REFS0) | (1<<REFS1); or after   ADCSRA |= 1<<ADEN;// Enable the ADR ? I think the delay should be placed after the ADC is enabled; isn't it?


Yes.  To ensure the code is now and will always be correct you should delay after the internal voltage reference is turned on; which is after setting ADMUX / REFSn and setting ADCSRA / ADEN.

Quote
[font=Courier New]/* From the datasheet: Voltage reference and input channel selections will not go into effect until ADEN is set.  Setting ADEN should be the first thing you do. */
  ADCSRA |= 1<<ADEN;// Enable the ADR
[/font]

I don't see any problem with that. First I specify the voltage reference and then, I start the ADC with the desired configuration. If ADEN is not set, the voltage reference and the input channel don't make any sense - the ADC is shut down.


I was under the impression that changing ADC registers was restricted until ADEN was set.  I was wrong.  What you are doing is not a problem.

However, moving the ADCSRA / ADEN and ADMUX / REFSn code to the earliest possible point allows the internal voltage reference to warm-up while you perform other initialization; the warm-up can be done in parallel with other things.  If that matters in your application.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy