Pages: 1 [2]   Go Down
Author Topic: Feedback Controller Implementation Best Practices  (Read 1123 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
/* 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
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.
« Last Edit: November 11, 2012, 11:53:03 pm by Coding Badly » Logged

Pages: 1 [2]   Go Up
Jump to: