Hey guys and gals
I really want to try to learn how to manipulate registers so I can get better speed and expand my knowledge of MCU's. I am not an avid programmer, so this is all uncharted territory for me.
Manipulating registers requires a lot of bit math, and I am trying to practice it. I thought a fun way to learn would be by using one of the simplest MCU's, the ATtiny 10. My goal for the project is to have it read an analog voltage, and if it is below a threshold, turn the output off. It will also read a switch and if the switch is high it will output a 75% duty cycle PWM signal on output. If switch is low it will output a 25% duty cycle PWM signal on output. (frequency can be very low, like 1Hz becuase it is controlling a small heater)
I have been following this excellent article, and have a question about one of the code used to interact with the ADC. To enable the ADC on PB0, this code is used:
ADMUX = 0<<MUX0; // ADC0 (PB0)
For this first line, I understand that it is shifting 0 into the ADMUX register by MUX0 positions. There are only two bits in the ADMUX register, so shouldn't it just be shifted twice to set both bits to 0? Why use MUX0 instead of (binary)10 or (decimal)2?
ADCSRA = 1<<ADEN | 3<<ADPS0; // Enable ADC, 125kHz clock
This second line is a bit more complicated.
The first part seems to shift in a 1 to the ADEN bit which enables the ADC.
There is then a | (or) symbol
The next part seems to set the ADPS0 register to a division factor of 8 by shifting a 3 in. (Since clock is 1MHz, so 1MHz/8 = 125kHz). What is the point of the | between the two statements on this line?
I really appreciate any help, I understand these are very basic questions. ![]()

