Is there an "ADC" register?

I'm troubleshooting some code and saw the following line:

value = ADC;

where value is a float. I'm really confused by this line because:

  • it's not a function as there are no parentheses
  • I don't see it defined as a macro
  • there is no "ADC" register in the AVR

I'm trying to understand what it does and where it came from. Has anyone ever used this or seen it in some header file? Thanks for any insights.

...which you forgot to post.
Or tell us anything about

ADC is usually something like

#define ADC     _SFR_MEM16(0x78)

Which board is this for? Arduino supports more than AVR boards.

Sorry, can't post the code (it's proprietary), and not necessary to answer my question. My question is basically, "What the heck does this do?" Yes, I think I know; it reads the ADCH and ADCL registers. But I can't be absolutely sure unless I understand where it comes from.

The #define statement you listed makes sense. But where is it?

This is for an Arduino Nano. (Processor is a 328P).

It's in one of the AVR include (.h) files installed on your computer

I know that it is:
int x = ADCW;//putting the value of ADCH and ADCL into x.

If you are on Windows
C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\iom328p.h

It looks that ADC and ADCW are the same.

#ifndef __ASSEMBLER__
#define ADC     _SFR_MEM16(0x78)
#define ADCW    _SFR_MEM16(0x78)

Yes, that is the answer to my question. Thank you!

Now I'll be able to sleep at night :slight_smile:

But, I have a query - why are you saying that ADC returns a float type value?

He didn't say that. He said he's troubleshooting some code that assigns the ADC value to a float called 'value'.

It's a good and valid question. I don't know if that's causing the issues I'm seeing, but for the sake of clean code, I should probably change that. I was wondering the same thing myself.

Ah, the joys of legacy code...

Fixed that for ya.

1 Like