ADMUX register oddity

It is certainly confusing. For the newer series tinyAVR more care is taken with the bit position and bit map mnemonics. MUX2 here means mux bit position 2 and not mux channel 2.

To achieve this:

REFS1	REFS0	ADLAR	REFS2	MUX3	MUX2	MUX1	MUX0
  1       0       0       1      0       0       1       0

you could use this:

ADMUX = (1<<REFS2)|(0<<REFS1)|(0<<ADLAR) | (0<<MUX3) | (0<<MUX2) | (1<<MUX1) | (0<<MUX0);

Where there are redundant placeholders for the unset bits.

Note that this trick with the redundant placeholders works only when the register value is zero as in the case of say a simple assignment. For example, | (0<<ADLAR) cannot set the bit to 0 if it currently has a value of 1.

1 Like

In Arduino Forum, we program ATtiny85 and other MCUs using Arduino IDE. Procure the following ATtiny85 Dev Boards and learn/enjoy the Programming of ATtiny85 MCU using C++ and Register level codes.
DigisparkAttiny85Board
Attiny85DevBoard

1<<2 == 4


Figure-1:

Refer to Fig-1, if you set MUX2-bit HIGH (assume MUX1 = LOW, MUX0 = LOW), which ADC channel of ATtiny85 is going to be select -- is it not ADC4? The following pin diagram (Fig-2) of ATtiny85 indicates the MCU has these ADC channels: ADC0, ADC1, ADC2, and ADC3. The data sheets also support it (Fig-3).

If you play around with a non-existent channel, then you might experince any kind of unpredictable outcome!


Figure-2:


Figure-3:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.