Skip to content

getTemperatureInternal() for tiny 84 #1

@SuperJerry69

Description

@SuperJerry69

Original GetTemperature fct is only for atmega 328 ...

int8_t` getTemperatureInternal() {

 //reads internal internal temp with 1V1 reference
  #if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) // 
    ADMUX = (1<<REFS1) | (1<<MUX5)| (1<<MUX1); //turn 1.1V reference and select ADC8 For ATtiny84
    #elif (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)// -40°=230lsb +25°=300lsb +85=370lsb
    ADMUX = (1<<REFS1) | (1<<MUX3)| (1<<MUX2)| (1<<MUX1)| (1<<MUX0); //turn 1.1V reference and select ADC4 For ATtiny85
  #elif defined(__AVR_ATmega1284P__)
      // For ATmega1284 not working
  #else // -45°=242mV +25=314mV +85°=380mV
   ADMUX =  (1<<REFS0) |(1<<REFS1) | (1<<MUX3); //turn 1.1V reference and select ADC8  for atmega 328p
  #endif

  delay(5); //wait for internal reference to settle
  // start the conversion
  ADCSRA |= bit(ADSC);
  //sbi(ADCSRA, ADSC);
  // ADSC is cleared when the conversion finishes
  while (ADCSRA & bit(ADSC));
  //while (bit_is_set(ADCSRA, ADSC));
  uint8_t low  = ADCL;
  uint8_t high = ADCH;
  //discard first reading
  ADCSRA |= bit(ADSC);
  while (ADCSRA & bit(ADSC));
  low  = ADCL;
  high = ADCH;
  int a = (high << 8) | low;
  return a - 270; //return temperature in C , x1100/1024=1,074 ....
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions