%calculate LTC2946 EM constants used in embedded coe
%For hotel EM
% base(new I2CDevice.Configuration(0xDE >> 1, 20), EnergyMonitorLTC2946.VoltageSource.SensePlus, 25.0, 0.50)  //25 milliVolts/LSB from data sheet and 0.50 milliAmps/LSB from 0.05 ohm sense resistor on schematic

% milliVoltsPerLSB = millivoltspercount;
% milliAmpsPerLSB = milliampspercount;
% microWattsPerLSB = milliAmpsPerLSB * milliVoltsPerLSB;
% milliSecondsPerLSB = 16.39543;
% uCoulombsPerLSB = milliAmpsPerLSB * milliSecondsPerLSB;
% milliJoulesPerLSB = microWattsPerLSB * 65536 * milliSecondsPerLSB;

milliVoltsPerLSB = 25.0;
milliAmpsPerLSB = .5;
microWattsPerLSB = milliAmpsPerLSB * milliVoltsPerLSB;
milliSecondsPerLSB = 16.39543;
uCoulombsPerLSB = milliAmpsPerLSB * milliSecondsPerLSB;
milliJoulesPerLSB = microWattsPerLSB * 65536 * milliSecondsPerLSB;
fprintf(1, "          CPF Code mV/LSB: %f   mA/LSB: %f   uW/LSB: %f   mSec/LSB: %f   mCoulcombs/LSB: %f   mJoulesPerLSB: %f\r\n", ...
    milliVoltsPerLSB, milliAmpsPerLSB, microWattsPerLSB, milliSecondsPerLSB, uCoulombsPerLSB, milliJoulesPerLSB);

RSense = 0.005;
DataSheetmilliVoltsPerLSB = 25.0;
DataSheetmilliAmpsPerLSB = 0.025 / RSense;
DataSheetmicroWattsPerLSB = DataSheetmilliAmpsPerLSB * milliVoltsPerLSB;
DataSheetmilliSecondsPerLSB = milliSecondsPerLSB;
DataSheetuCoulombsPerLSB = DataSheetmilliAmpsPerLSB * 16 * milliSecondsPerLSB;
DataSheetmilliJoulesPerLSB = DataSheetmicroWattsPerLSB * 65536 * milliSecondsPerLSB;
fprintf(1, "RSense = %f  mV/LSB: %f   mA/LSB: %f   uW/LSB: %f   mSec/LSB: %f   mCoulcombs/LSB: %f   mJoulesPerLSB: %f\r\n", ...
    RSense, DataSheetmilliVoltsPerLSB, DataSheetmilliAmpsPerLSB, DataSheetmicroWattsPerLSB, DataSheetmilliSecondsPerLSB, DataSheetuCoulombsPerLSB, DataSheetmilliJoulesPerLSB);

RSense = 0.05;
DataSheetmilliVoltsPerLSB = 25.0;
DataSheetmilliAmpsPerLSB = 0.025 / RSense;
DataSheetmicroWattsPerLSB = DataSheetmilliAmpsPerLSB * milliVoltsPerLSB;
DataSheetmilliSecondsPerLSB = milliSecondsPerLSB;
DataSheetuCoulombsPerLSB = DataSheetmilliAmpsPerLSB * 16 *milliSecondsPerLSB;
DataSheetmilliJoulesPerLSB = DataSheetmicroWattsPerLSB * 65536 * milliSecondsPerLSB;
fprintf(1, "RSense = %f  mV/LSB: %f   mA/LSB: %f   uW/LSB: %f   mSec/LSB: %f   mCoulcombs/LSB: %f   mJoulesPerLSB: %f\r\n", ...
    RSense, DataSheetmilliVoltsPerLSB, DataSheetmilliAmpsPerLSB, DataSheetmicroWattsPerLSB, DataSheetmilliSecondsPerLSB, DataSheetuCoulombsPerLSB, DataSheetmilliJoulesPerLSB);

r1 = 1000000;
r2 = 53600;
ratio1 = r2/(r1+r2);
ratio2 = (r2*0.99)/((r1*1.01) + (r2*0.99));
a = ratio1/ratio2;
ratio3 = (r2*1.01)/((r1*0.99) + (r2*1.01));
b = ratio3/ratio1;