Welcome! Log In Create A New Profile

Advanced

adc conversion optimizations tonokip

Posted by jamesdanielv 
Re: adc conversion optimizations tonokip
July 12, 2011 01:28AM
does sample adc return a 10 bit value automatically? that seems so much easier.



if anything try this



byte low=ADCL;
byte high=ADCH;
int sample=(high<<2)|(low); //

also for my adc example code above, i need to add a flag that indicated a conversion is in process. sometimes currently the adc does not complete before another conversion is restarted, and it messes up the order of what adc register is being read.... looking into and will post a fix shortly.


edit::here is a bit of wordage. sorry for the eye sore. what i think was happening is your code was reading the data in the wrong order.



The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltage reference and
input channel selections will not go into effect until ADEN is set. The ADC does not consume
power when ADEN is cleared, so it is recommended to switch off the ADC before entering power
saving sleep modes.
The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and
ADCL. By default, the result is presented right adjusted, but can optionally be presented left
adjusted by setting the ADLAR bit in ADMUX.
If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read
ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data
Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers
is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is
read, neither register is updated and the result from the conversion is lost. When ADCH is read,
ADC access to the ADCH and ADCL Registers is re-enabled.
The ADC has its own interrupt which can be triggered when a conversion completes. When ADC
access to the Data Registers is prohibited between reading of ADCH and ADCL, the interrupt
will trigger even if the result is lost.

Edited 1 time(s). Last edit at 07/12/2011 04:16AM by jamesdanielv.
Sorry, only registered users may post in this forum.

Click here to login