Port Emonlib to Mega 2560

Hi,

I´m planning in using th eEmonlib on the ATmega 2560.

With which modifications should i be careful?

Is the Clock frequency (16MHz) a problem ?

Best regards

glyn.hudson's picture

Re: Port Emonlib to Mega 2560

The clock on the Atmega328 also runs at 16Mhz, I don't have any experience using the 2560. Please let us know how you get on. 

Robstar's picture

Re: Port Emonlib to Mega 2560

Atmega328  EmonLib.cpp

long EnergyMonitor::readVcc() {
  long result;
  ADMUX = _BV(REFS0) |  _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2);
  ADCSRA |= _BV(ADSC);
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result;
  return result;
}

 

change ->

Atmega2560 EmonLib.cpp

long EnergyMonitor::readVcc() {
  long result;
  ADMUX = _BV(REFS0) |  _BV(MUX5) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2);
  ADCSRA |= _BV(ADSC);
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result;
  return result;
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.