The chip can be set in comparator mode, the result will be a digital signal.
You want to read an analog channel.
Yep, I figured that part out.
Table 26-4 is how to select the channel for the lower bits of the ADMUX register.
And that’s where I was stuck. I know 0xC0, and I know what that converts to, 1100 0000. Looking at that whole section, I now read:
Bit 7 6 5 4 3 2 1 0
REFS1 REFS2 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0
Value 1 1 0 0 0 0 0 0
REFS1:0 both being set means internal 2.56V reference with an external cap on AREF
ADLAR having 0 written to it means the result is right adjusted
MUX4:0 all being 0 translates to ADC0
The ‘conversion’ line actually only starts the ADC.
If you read about the ADCSRA register (chapter 26.9.2) in the datasheet, you read:
ADEN : ADC enable, it must be ‘1’ to enable the ADC.
ADPS2, ADPS1 : prescaler bits, how fast or how slow the ADC should be.
ADSC : ADC start conversion. After this bit is set, the ADC starts it analog to digital converstion.
I was just going over that part, trying to understand what each bit does.
1<<ADEN” is how bit ‘ADEN’ is set to ‘1’.
That is how it was defined by Atmel and the avr gcc compiler.
Arduino has a macro for that: “
bitSet( ADCSRA, ADEN);” or “
ADCSRA = bit( ADEN) | bit( ADSC);”
I understood how things were being enabled, just not how to read what was being done. So following that line and the documentation, I read:
ADCSRA = (1<<ADEN) | ((1<<ADPS2) | (1<<ADPS1)) | (1<<ADSC);
1<<ADEN = Enable ADC
1<<ADPS2 and 1<<ADPS1 = division factor 64 (initial values dictates that ADPS0 is set to 0)
1<<ADSC = starts conversion
How are you doing so far ? does this make it better to understand ?
It’s slowly coming to my aging brain … it’s getting there.