Skip to content
Snippets Groups Projects
Commit 36ce942b authored by Evan Paul Mladina's avatar Evan Paul Mladina
Browse files

pbv3_debug toggles multiplexer readings on the AMAC (no longer reads directly...

pbv3_debug toggles multiplexer readings on the AMAC (no longer reads directly from AMAC). Fancy load allows for external load readings on mass tester.
parent 9cab0fc3
No related branches found
No related tags found
3 merge requests!27Print status of AMAC/(Multiplexer) values for mass or single testbenches,!26Implement variable load scan on the mass tester active board,!24Active board multiplexer debug
Pipeline #1409969 failed
#include <memory>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
#include <nlohmann/json.hpp>
#include <sys/stat.h>
#include <dirent.h>
#include "AgilentPs.h"
#include "Bk85xx.h"
#include "I2CDevCom.h"
#include "PCA9548ACom.h"
#include "PBv3TBMassive.h"
#include "PBv3ConfigTools.h"
#include "AgilentPs.h"
#include "I2CDevCom.h"
#include "PCA9548ACom.h"
#include "PBv3TB.h"
#include "ComIOException.h"
#include "EndeavourComException.h"
#include "EndeavourCom.h"
#include "DAC5574.h"
#include "Logger.h"
#include "AD799X.h"
#include "GenericPs.h"
using nlohmann::json;
loglevel_e loglevel = logINFO;
std::string configfile= "";
int main(int argc, char* argv[])
{
if (argc < 3)
{
std::cout << "Not enough parameters!" << std::endl;
std::cout << "Parameters needed: <PBidx> <filename>" << std::endl;
return -1;
}
std::string fileName = argv[2];
json testSum;
logger(logINFO) << "Results stored in " << fileName;
std::fstream outfile(fileName, std::ios::out);
if(!outfile.is_open())
{
logger(logERROR) << "Unable to create results file " << fileName;
return 2;
}
int pb = strtol(argv[1], NULL, 10);
/*
try
{
ps.init();
ps.setCh(1);
ps.setRange(20);
ps.setVoltage(1.5);
ps.setCurrent(5);
}
catch(const std::string& e)
{
logger(logERROR) << e;
return 1;
}
*/
// Prog ID set during init (require power-up to be set)
std::shared_ptr<PBv3TBMassive> tb;
std::string agiDev="/dev/ttyUSB0";
try
{
tb=std::make_shared<PBv3TBMassive>(agiDev, 10);
}
catch(const std::string& e)
{
logger(logERROR) << "Exiting due to failure initializing testbench";
return 1;
}
//Init Agilent
logger(logINFO) << "Init Agilent PS";
AgilentPs ps(agiDev, 10);
logger(logINFO) << "Turn on power supply.";
tb->powerLVOn();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
// Init Load
logger(logINFO) << "Init BK DCDC Load";
std::string bkDev="/dev/ttyUSB1";
Bk85xx dc(bkDev);
dc.setRemote();
dc.setRemoteSense(false);
dc.setModeCC();
dc.setCurrent(0);
testSum["testType"] = "DCDCEFFICIENCY";
testSum["passed"] = true;
//Init Com
json config;
if(!configfile.empty())
{
std::ifstream fh_in(configfile);
if(fh_in.is_open())
fh_in >> config;
}
logger(logINFO) << "Init AMAC";
std::shared_ptr<AMACv2> amac=tb->getPB(pb);
try {
amac->init();
PBv3ConfigTools::configAMAC(amac, config, false);
amac->initRegisters();
PBv3ConfigTools::saveConfigAMAC(amac, config);
} catch(EndeavourComException &e) {
logger(logERROR) << "Unable to initialize AMACv2";
logger(logERROR) << e.what();
return 1;
}
//
// Initialize
// Set load to 0
try
{
dc.setCurrent(0);
dc.turnOn();
}
catch(std::string &s)
{
logger(logERROR) << s;
testSum["error"] = s;
return testSum;
}
tb->setVin(11);
logger(logINFO) << " --> Turn off DCDC ..";
try
{
amac->wrField(&AMACv2::DCDCen, 0);
amac->wrField(&AMACv2::DCDCenC, 0);
}
catch(EndeavourComException &e)
{
logger(logERROR) << e.what();
testSum["error"] = e.what();
return testSum;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
logger(logINFO) << " --> Get baseline current: (" << tb->getVinCurrent() << ")A";
double Iin_offset = tb->getVinCurrent();
std::cout << Iin_offset << std::endl;
testSum["results"]["IINOFFSET"] = Iin_offset;
logger(logINFO) << " --> Turn on DCDC ...";
try
{
amac->wrField(&AMACv2::DCDCen, 1);
amac->wrField(&AMACv2::DCDCenC, 1);
}
catch(EndeavourComException &e)
{
logger(logERROR) << e.what();
testSum["error"] = e.what();
return testSum;
}
//unsigned dwell_time = .1; //s
unsigned dwell_time_s = .005; //s
unsigned dwell_time = 5; //s
testSum["properties"]["DWELLTIMELONG" ] = dwell_time;
testSum["properties"]["DWELLTIMESHORT"] = dwell_time_s;
logger(logINFO) << " --> Starting measurement ...";
std::cout << "Vin" << "\t" << "Iin" << "\t" << "Vout" << "\t" << "Iout" << "\t" << "IoutSense" << "\t" << "Vdcdc"
<< "\t" << "VddLr" << "\t" << "DCDCin" << "\t" << "NTC" << "\t"
<< "Cur10V" << "\t" << "Cur1V" << "\t" << "PTAT" << "\t" << "Efficiency" << "\t" << "EfficiencySense" << std::endl;
// Set sub-channel
try
{
amac->wrField(&AMACv2::Ch12Mux, 0); //a
amac->wrField(&AMACv2::Ch13Mux, 0); //a
}
catch(EndeavourComException &e)
{
logger(logERROR) << e.what();
return testSum;
}
// Loop over currents
int index = 0;
for (double iout=0;iout<=3500;iout+=100)
{
//allowing system to reach thermal equilibrium
std::this_thread::sleep_for(std::chrono::seconds(dwell_time));
logger(logDEBUG) << " --> Setting " << iout << "mA load!";
// Set Current
dc.setCurrent(iout);
// Wait for temp and everything to settle
std::this_thread::sleep_for(std::chrono::seconds(dwell_time_s));
// Read AMAC values
int Vdcdc, VddLr, DCDCin, NTC, Cur10V, Cur1V, PTAT;
try
{
Vdcdc = amac->rdField(&AMACv2::Ch0Value);
VddLr = amac->rdField(&AMACv2::Ch1Value);
DCDCin = amac->rdField(&AMACv2::Ch2Value);
NTC = amac->rdField(&AMACv2::Ch9Value);
Cur10V = amac->rdField(&AMACv2::Ch12Value);
Cur1V = amac->rdField(&AMACv2::Ch13Value);
PTAT = amac->rdField(&AMACv2::Ch15Value);
}
catch(EndeavourComException &e)
{
logger(logERROR) << e.what();
testSum["error"] = e.what();
return testSum;
}
double Vin = tb->getVin();
double Iin = tb->getVinCurrent();
double IoutSense = tb->getIload(pb);
double Vout = 0;
try
{
Vout = tb->getVout(pb);
}
catch(std::string &s)
{
logger(logERROR) << s;
testSum["error"] = s;
return testSum;
}
double efficiency = (Vout*iout*1e-6)/(Vin*(Iin-Iin_offset));
double efficiencySense = (Vout*IoutSense*1e-3)/(Vin*(Iin-Iin_offset));
//double efficiency = (1.5*iout*1e-3)/(Vin*(Iin-Iin_offset));
std::cout << Vin << "\t" << Iin << "\t" << Vout << "\t" << iout << "\t" << IoutSense << "\t" << Vdcdc
<< "\t" << VddLr << "\t" << DCDCin << "\t" << NTC << "\t"
<< Cur10V << "\t" << Cur1V << "\t" << PTAT << "\t" << efficiency << "\t" << efficiencySense << std::endl;
testSum["results"]["VIN" ][index] = Vin;
testSum["results"]["IIN" ][index] = Iin;
testSum["results"]["VOUT" ][index] = Vout*1e-3;
testSum["results"]["IOUT" ][index] = iout*1e-3;
testSum["results"]["IOUTSENSE" ][index] = IoutSense;
testSum["results"]["AMACVDCDC" ][index] = Vdcdc;
testSum["results"]["AMACVDDLR" ][index] = VddLr;
testSum["results"]["AMACDCDCIN" ][index] = DCDCin;
testSum["results"]["AMACNTCPB" ][index] = NTC;
testSum["results"]["AMACCUR10V" ][index] = Cur10V;
testSum["results"]["AMACCUR1V" ][index] = Cur1V;
testSum["results"]["AMACPTAT" ][index] = PTAT;
testSum["results"]["EFFICIENCY" ][index] = efficiency;
testSum["results"]["EFFICIENCYSENSE"][index] = efficiencySense;
index++;
}
logger(logINFO) << " --> Done!! Turng off load!";
// Revert to old state
amac->initRegisters();
dc.setCurrent(0);
ps.turnOff();
outfile << std::setw(4) << testSum << std::endl;
outfile.close();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment