ADC VS ADCW to read the ACD result as a word

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have seen the use of ADC suggested in several replies to read the ADC peripheral result as a word instead of a byte as in ADCL and ADCH.

Why the ADC and not the ADCW?

According to the header I opened (mega88) the difference is

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

So ADCW will always work while ADC will only work when __ASSEMBLER__ is not defined (or is my understanding wrong?).
And what is __ASSEMBLER__ , what does it stand for and when should I expect to see it defined?

Alex

p.s. I forgot to mention I use winavr

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

__ASSEMBLER__ is defined when you "compile" assembler programs with avr-gcc (avr-as). See for example the combined asm and C example in the manual.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Different compilers use different conventions for naming the pseudo-16bit registers. e.g.
Rowley uses TCNT1W, OC1AW, ADCW, EEARW, ...
Codevision uses TCNT1, OC1A, ADCW, EEAR, ...
Note that Codevision only defines the '16-bit' name if is in IN/OUT space. e.g. tiny2313, mega32, ...

GCC has a similar inconsistency. However with GCC, you use the same for ASM or C. You simply use the relevant macros.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always recommend ADCW. The reason ADC does not work when using assembler is that it conflicts with ADd with Carry.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was using codevision before starting with winavr so I was already used to ADCW and I wasn't actually even aware of the ADC alternative until I saw it suggested in threads here.

So ADCW is preferred and it seems that it is even used with the same name in several different compilers while I'm not sure if ADC is defined.

Thank you all

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I prefer ADC. That best reflects what it contains, i.e. the result of an ADC conversion.

ADC is the whole value. ADCL and ADCH contains partial values, and the H/L suffix indicates which part.

If ADCW was to be used - then the partial ones would be named ADCWH and ADCWL.

ADC is also what is used in the datasheets.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's a personal preference thing mostly. Like Sid I prefer just "ADC" to "ADCW". For GCC at least I think most headers have both:

E:\WinAVR-20100110\avr\include\avr>grep -w "#define ADCW" io*.h | wc -l
     74

E:\WinAVR-20100110\avr\include\avr>grep -w "#define ADC" io*.h | wc -l
     76

I suppose if you were writing .S (so __ASSEMBLER__ were defined) then you wouldn't get the choice and it would have to be ADCW.

In beginner threads here where they are monkeying about trying to join ADCL/ADCH (and usually getting the read or der wrong - it's a 50:50 guess!) it maybe just makes more sense to say ADC rather than ADCW as the composite name to avoid the inevitable follow up question as to what the 'W' stands for (again it's a little sad if they cannot guess "Word"!).