Hi,
I gather from the data sheet that the temperature from the temp sensor on attiny is located as a ninth entry to the ADC and that there are eight pins capable of analogRead connected to ADC0 to ADC7. I have also found this:
typedef enum
{
ADC_Input_ADC0 = B000000,
ADC_Input_ADC1 = B000001,
ADC_Input_ADC2 = B000010,
ADC_Input_ADC3 = B000011,
ADC_Input_ADC4 = B000100,
ADC_Input_ADC5 = B000101,
ADC_Input_ADC6 = B000110,
ADC_Input_ADC7 = B000111,
ADC_Input_GND = B100000, // 0V (AGND)
ADC_Input_1p1 = B100001, // 1.1V (I Ref)
ADC_Input_ADC8 = B100010, // For temperature sensor.
ADC_Input_Pos0_Neg0_20x = B100011, // For offset calibration, only.
ADC_Input_Pos0_Neg1_1x = B001000,
ADC_Input_Pos0_Neg1_20x = B001001,
ADC_Input_Pos0_Neg3_1x = B001010,
ADC_Input_Pos0_Neg3_20x = B001011,
ADC_Input_Pos1_Neg0_1x = B101000,
ADC_Input_Pos1_Neg0_20x = B101001,
ADC_Input_Pos1_Neg2_1x = B001100,
ADC_Input_Pos1_Neg2_20x = B001101,
ADC_Input_Pos1_Neg3_1x = B001110,
ADC_Input_Pos1_Neg3_20x = B001111,
ADC_Input_Pos2_Neg1_1x = B101100,
ADC_Input_Pos2_Neg1_20x = B101101,
ADC_Input_Pos2_Neg3_1x = B010000,
ADC_Input_Pos2_Neg3_20x = B010001,
ADC_Input_Pos3_Neg0_1x = B101010,
ADC_Input_Pos3_Neg0_20x = B101011,
ADC_Input_Pos3_Neg1_1x = B101110,
ADC_Input_Pos3_Neg1_20x = B101111,
ADC_Input_Pos3_Neg2_1x = B110000,
ADC_Input_Pos3_Neg2_20x = B110001,
ADC_Input_Pos3_Neg3_1x = B100100, // For offset calibration, only.
ADC_Input_Pos3_Neg3_20x = B100101, // For offset calibration, only.
ADC_Input_Pos3_Neg4_1x = B010010,
ADC_Input_Pos3_Neg4_20x = B010011,
ADC_Input_Pos3_Neg5_1x = B010100,
ADC_Input_Pos3_Neg5_20x = B010101,
ADC_Input_Pos3_Neg6_1x = B010110,
ADC_Input_Pos3_Neg6_20x = B010111,
ADC_Input_Pos3_Neg7_1x = B011000,
ADC_Input_Pos3_Neg7_20x = B011001,
ADC_Input_Pos4_Neg3_1x = B110010,
ADC_Input_Pos4_Neg3_20x = B110011,
ADC_Input_Pos4_Neg5_1x = B011010,
ADC_Input_Pos4_Neg5_20x = B011011,
ADC_Input_Pos5_Neg3_1x = B110100,
ADC_Input_Pos5_Neg3_20x = B110101,
ADC_Input_Pos5_Neg4_1x = B111010,
ADC_Input_Pos5_Neg4_20x = B111011,
ADC_Input_Pos5_Neg6_1x = B011100,
ADC_Input_Pos5_Neg6_20x = B011101,
ADC_Input_Pos6_Neg3_1x = B110110,
ADC_Input_Pos6_Neg3_20x = B110111,
ADC_Input_Pos6_Neg5_1x = B111100,
ADC_Input_Pos6_Neg5_20x = B111101,
ADC_Input_Pos6_Neg7_1x = B011110,
ADC_Input_Pos6_Neg7_20x = B011111,
ADC_Input_Pos7_Neg3_1x = B111000,
ADC_Input_Pos7_Neg3_20x = B111001,
ADC_Input_Pos7_Neg6_1x = B111110,
ADC_Input_Pos7_Neg6_20x = B111111,
ADC_Input_Pos7_Neg7_1x = B100110, // For offset calibration, only.
ADC_Input_Pos7_Neg7_20x = B100111 // For offset calibration, only.
}
adc_ic_t;
__attribute__((always_inline)) static inline void ADC_SetInputChannel( adc_ic_t ic )
{
ADMUX = (ADMUX & ~MASK6(MUX5,MUX4,MUX3,MUX2,MUX1,MUX0)) | (ic << MUX0);
}
in core_adc.h within the TINY core.
As expected the value ADC8 is described in the list as referring to the temp reading.
From the coding in "wiring_analog.cpp" for analogRead I get that the ADC_SetInputChannel() function defined in the code above is the function that decides which of the input to the ADC that should be converted.
The code for the analogRead function is:
int analogRead(uint8_t pin)
{
#if defined( CORE_ANALOG_FIRST )
if ( pin >= CORE_ANALOG_FIRST ) pin -= CORE_ANALOG_FIRST; // allow for channel or pin numbers
#endif
// fix? Validate pin?
ADC_SetVoltageReference( analog_reference );
ADC_SetInputChannel( pin );
ADC_StartConversion();
while( ADC_ConversionInProgress() );
return( ADC_GetDataRegister() );
}
Since the the first eight entries in the enumeration adc_ic_t refers to the analog pin inputs am I right to think that since the temp sensor is the eleventh entry I could use analogRead(10) to get the temperature reading?
Or am I just very confused??? ![]()
/H