Attiny84-measuring its own Vcc

Hello. I’ve been designing a product and wanted to do a selfcheck on poweron. So I needed a way, among other things, to check the VCC (I am using a DC/DC convertor-need to check if it works fine.)

I’ve modified code from here:

For it to work on attiny84:

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX =  0b00100001;// adc source=1.1 ref; adc ref (base for the 1023 maximum)=Vcc
  delay(2); // Wait for Vref to settle
  ADCSRA |= 1<<ADSC; // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;

5 mins of work, I know-but you guys might find it useful, since it’s a bit of a “hidden” feature. So yea, mostly pointing out it’s possible, since on the page I linked to it says it works only on atmega 168 and 328.

Thanks for sharing ! +1