Electronics > Microcontrollers
adding H and L results together for ADC (AVR)
Simon:
I'm writing a little function so that I can easily get ADC results from the H and L register and straight into a single result. Is the following correct:
--- Code: ---uint16_t adc_result (void)
{
uint16_t result
result = (ADCH << 8) + ADCL;
return result;
}
--- End code ---
firewalker:
Just use ADC.
--- Code: --- while( ADCSRA & (1<<ADSC) ); // Wait until ADC conversion is complete.
result = ADC;
--- End code ---
Alexander.
Simon:
how do you mean just use ADC ? as far as i know there are no ADC libraries.......
My question is abut combining the two registers
firewalker:
Somewhere in the header files for every mcu there will be a statement like (iom328p.h)
--- Code: ---#define ADC _SFR_MEM16(0x78)
#define ADCW _SFR_MEM16(0x78)
--- End code ---
When you call ADC (16-bit), it will automatically serve you the combined content of the ADCH and ADCL registers.
Alexander.
Simon:
ok, i sort of see it but lets assume I'm really dumb. I see no code there that adds two 8 bit registers together to form one 16 bit variable, just some #defines
Navigation
[0] Message Index
[#] Next page
Go to full version