silly_cone:
I would like to demystify it for myself so I can actually utilize it effectively. If anyone can point me at a good resource to learn more about it, that would be awesome.
1. Physical Pin Diagram of ATtint10 MCU
Figure-1: Physical pin diagram
(1) By default, Pin-1, 3, 4, and 6 are digital IO pins of Port-B Register. From the following digram (Fig-2), we can view the 1-bit (Bit-2) structure of the 4-bit wide Port-B Register of ATtiny10 MCU.
Figure-2: 1-bit structure of Port-B Register of ATtiny10 MCU
(2) The PB0-PB3 IO lines of Port-B Register can be configured to work as analog channels (ADC0 - ADC3) for the internal 8-bit ADC (analog-to-digital converter) Module. Figure-3 depicts the internal structure of the ADC Module.
Figure-3: ADC Module of ATtiny10 MCU
2. Programming Procedure for the ADC Module
(1) Turn PB1-pin into ADC1 channel with the help of ADMUX Register
Figure-4: ADMUX Register of ATtiny10 MCU
To select ADC1 channel, MUX0-bit should be LH (1) and MUX1-bit should be LL (0). MUX1-bit is already at LL-state by default; so, it is enough to put LH at MUX0-bit position. We can execute one of the following instructions to select ADC1 channel.
ADMUX = 0b00000001; //pult LH at MUX0-bit and LL at MUX1-bit
ADMUX = 1<<MUX0; //this line puts LH(1) only at MUX0-bit without disturbing other bits of ADMUX Register
OR
bitWrite(ADMUX, 0, 1); //RegisreName. bitPosition, bitValue
OR
bitSet(ADMUX, 0); //RegisterName, bitPosition
(2) Enable the ADC Module and select conversion frequency with the help of ADCSRA Register
Figure-5: ADCSRA Register of ATtiny10 MCU
ADC Module becomes active (enabled) when LH is stored at ADEN (bit-7) of the ADCSRA Register. Conversion frequency is set at the standard 125 kHz with the help of ADPS[2:0] bits of ADCSRA Register. A value of ADPS[2:0] = {1, 1, 0} = {1, 1, 0} (ADC Clock Prescaler division factor is 64) will set the
conversion frequency at 125 kHz. We may execute one of the following instruction fo these purposes:
byte x = ADCSRA;
ADCSRA = x | 0b1000 0110; // ADEN(1) .(unaffected) . . . ADPS2(1), ADPS1(1), ADPS(0);
OR
//ADCSRA = 1<<ADEN | 3<<ADPS0; //
I really don't understand this part (3<<ADPS0) of the last instruction; somebody may explain it.
(3) Issue 'Start Conversion' command to the ADC by putting LH at the ADSC-bit of the ADCSRA Register of Fig-5. The following instruction stores LH at the ADSC-bit without affecting other bits of the ADCSRA Register.
ADCSRA = ADCSRA | 1<<ADSC; // Start conversion
(4) Wait until conversion is done. The ADCSC-bit remains at LH-state as long as the conversion is going ON; at the end of conversion, the ADSC-bit assumes LL-state. So, keep polling this bit for LL-state. We can execute one of the following instructions.
while(bitRead(ADCSRA, 6) != LOW)
{
;
}
OR
while (ADCSRA & 1<<ADSC); // Wait while conversion in progress
(5) At the end of conversion, read the ADC value and use it.
At the end of conversion, the digital value is stored in the ADCL Register (Fig-6) of the ADC Module. We can assign the value of the ADCL Register to any valid 8-bit variable by executing the following instruction:
Figure-6: ADCL Register of ADC Module of ATtiny10 MCU
byte x = ADCL;