mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
updated max1932, modified ltc2620
This commit is contained in:
1
slsDetectorServers/ctbDetectorServer/common.h
Symbolic link
1
slsDetectorServers/ctbDetectorServer/common.h
Symbolic link
@ -0,0 +1 @@
|
||||
../slsDetectorServer/common.h
|
@ -473,40 +473,42 @@ void setupDetector() {
|
||||
now_ptr = 0;
|
||||
|
||||
|
||||
resetPLL();
|
||||
resetCore();
|
||||
resetPeripheral();
|
||||
cleanFifos();
|
||||
resetPLL();
|
||||
resetCore();
|
||||
resetPeripheral();
|
||||
cleanFifos();
|
||||
|
||||
// set spi defines
|
||||
AD7689_SetDefines(ADC_SPI_REG, ADC_SPI_SLOW_VAL_REG, ADC_SPI_SLOW_SRL_CNV_MSK, ADC_SPI_SLOW_SRL_CLK_MSK, ADC_SPI_SLOW_SRL_DT_MSK, ADC_SPI_SLOW_SRL_DT_OFST);
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MAX_VOLTAGE_MV);
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST);
|
||||
// hv
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST, HIGHVOLTAGE_MIN, HIGHVOLTAGE_MAX);
|
||||
MAX1932_Disable();
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
// disable spi
|
||||
AD7689_Disable();
|
||||
AD9257_Disable();
|
||||
LTC2620_Disable();
|
||||
MAX1932_Disable();
|
||||
|
||||
#ifndef VIRTUAL
|
||||
// adcs
|
||||
AD9257_Configure();
|
||||
// slow adcs
|
||||
AD7689_Configure();
|
||||
// I2C
|
||||
INA226_ConfigureI2CCore();
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VIO_DEVICE_ID);
|
||||
// power regulators
|
||||
// I2C
|
||||
INA226_ConfigureI2CCore();
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VIO_DEVICE_ID);
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VA_DEVICE_ID);
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VB_DEVICE_ID);
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VC_DEVICE_ID);
|
||||
INA226_CalibrateCurrentRegister(I2C_POWER_VD_DEVICE_ID);
|
||||
// dacs
|
||||
LTC2620_Configure();
|
||||
#endif
|
||||
// switch off power regulators
|
||||
// switch off
|
||||
powerChip(0);
|
||||
setvchip(VCHIP_MIN_MV);
|
||||
|
||||
// adcs
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
AD9257_Disable();
|
||||
AD9257_Configure();
|
||||
|
||||
// slow adcs
|
||||
AD7689_SetDefines(ADC_SPI_REG, ADC_SPI_SLOW_VAL_REG, ADC_SPI_SLOW_SRL_CNV_MSK, ADC_SPI_SLOW_SRL_CLK_MSK, ADC_SPI_SLOW_SRL_DT_MSK, ADC_SPI_SLOW_SRL_DT_OFST);
|
||||
AD7689_Disable();
|
||||
AD7689_Configure();
|
||||
|
||||
// dacs
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MIN_MV, DAC_MAX_MV);
|
||||
LTC2620_Disable();
|
||||
LTC2620_Configure();
|
||||
//FIXME:
|
||||
// switch off dacs (power regulators most likely only sets to minimum (if power enable on))
|
||||
{
|
||||
@ -517,8 +519,6 @@ void setupDetector() {
|
||||
}
|
||||
|
||||
bus_w(ADC_PORT_INVERT_REG, ADC_PORT_INVERT_VAL);//FIXME: got from moench config file
|
||||
setvchip(VCHIP_MIN_MV);
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("Setting Default parameters\n"));
|
||||
cleanFifos(); // FIXME: why twice?
|
||||
@ -1031,9 +1031,6 @@ int validateTimer(enum timerIndex ind, int64_t val, int64_t retval) {
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
|
||||
int getMaxDacSteps() {
|
||||
|
||||
}
|
||||
|
||||
void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
if (val < 0)
|
||||
@ -1042,8 +1039,13 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
int dacval = val;
|
||||
#ifdef VIRTUAL
|
||||
if (mV && LTC2620_VoltageToDac(val, &dacval) == OK)
|
||||
if (!mV) {
|
||||
dacValues[ind] = val;
|
||||
}
|
||||
// convert to dac units
|
||||
else if (LTC2620_VoltageToDac(val, &dacval) == OK) {
|
||||
dacValues[ind] = dacval;
|
||||
}
|
||||
#else
|
||||
if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK)
|
||||
dacValues[ind] = dacval;
|
||||
@ -1104,7 +1106,9 @@ int getVchip() {
|
||||
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_PWR_DOWN_VAL)
|
||||
return dacValues[D_PWR_CHIP];
|
||||
int voltage = -1;
|
||||
Common_DacToVoltage(dacValues[D_PWR_CHIP], &voltage, VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MAX_STEPS);
|
||||
// dac to voltage
|
||||
ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, VCHIP_MIN_MV, VCHIP_MAX_MV,
|
||||
dacValues[D_PWR_CHIP], &voltage);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
@ -1117,8 +1121,9 @@ void setVchip(int val) {
|
||||
|
||||
// validate & convert it to dac
|
||||
if (val != LTC2620_PWR_DOWN_VAL) {
|
||||
// convert it to dac
|
||||
if (Common_VoltageToDac(val, &dacval, VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MAX_STEPS) == FAIL) {
|
||||
// convert voltage to dac
|
||||
if (ConvertToDifferentRange(VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
val, &dacval) == FAIL) {
|
||||
FILE_LOG(logERROR, ("\tVChip %d mV invalid. Is not between %d and %d mV\n", val, VCHIP_MIN_MV, VCHIP_MAX_MV));
|
||||
return;
|
||||
}
|
||||
@ -1246,8 +1251,9 @@ int getPower(enum DACINDEX ind) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// voltage value
|
||||
Common_DacToVoltage(dacValues[ind], &retval, POWER_RGLTR_MIN, (getVchip() - VCHIP_POWER_INCRMNT), LTC2620_MAX_STEPS);
|
||||
// convert dac to voltage
|
||||
ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, POWER_RGLTR_MIN, (getVchip() - VCHIP_POWER_INCRMNT),
|
||||
dacValues[ind], &retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -1290,9 +1296,11 @@ void setPower(enum DACINDEX ind, int val) {
|
||||
|
||||
// convert it to dac
|
||||
if (val != LTC2620_PWR_DOWN_VAL) {
|
||||
// convert it to dac
|
||||
if (Common_VoltageToDac(val, &dacval, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT, LTC2620_MAX_STEPS) == FAIL) {
|
||||
FILE_LOG(logERROR, ("\tPower index %d of value %d mV invalid. Is not between %d and %d mV\n", ind, val, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT));
|
||||
// convert voltage to dac
|
||||
if (ConvertToDifferentRange(POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT, LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
val, &dacval) == FAIL) {
|
||||
FILE_LOG(logERROR, ("\tPower index %d of value %d mV invalid. Is not between %d and %d mV\n",
|
||||
ind, val, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1352,30 +1360,16 @@ int setHighVoltage(int val){
|
||||
highvoltage = val;
|
||||
return highvoltage;
|
||||
#endif
|
||||
uint32_t dacvalue;
|
||||
float alpha = 0.55;
|
||||
|
||||
// setting hv
|
||||
if (val >= 0) {
|
||||
// limit values
|
||||
if (val < 60) {
|
||||
dacvalue = 0;
|
||||
val = 0;
|
||||
} else if (val >= 200) {
|
||||
dacvalue = 0x1;
|
||||
val = 200;
|
||||
} else {
|
||||
dacvalue = 1. + (200.-val) / alpha;
|
||||
val = 200.-(dacvalue-1)*alpha;
|
||||
}
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d (dacval %d)\n",val, dacvalue));
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
uint32_t addr = POWER_REG;
|
||||
|
||||
// switch off high voltage
|
||||
bus_w(addr, bus_r(addr) & (~POWER_HV_SLCT_MSK));
|
||||
|
||||
serializeToSPI(SPI_REG, dacvalue, HV_SERIAL_CS_OUT_MSK, MAX1932_HV_NUMBITS,
|
||||
HV_SERIAL_CLK_OUT_MSK, HV_SERIAL_DIGITAL_OUT_MSK, HV_SERIAL_DIGITAL_OUT_OFST);
|
||||
MAX1932_Set(val);
|
||||
|
||||
// switch on high voltage if val > 0
|
||||
if (val > 0)
|
||||
|
@ -39,10 +39,6 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
|
||||
#define NDAC (24)
|
||||
#define NPWR (6)
|
||||
#define NDAC_ONLY (NDAC - NPWR)
|
||||
//#define N_DAC (24)
|
||||
//#define N_PWR (5)
|
||||
//#define NADC (9)
|
||||
//#define DAC_CMD_OFF 20
|
||||
#define DYNAMIC_RANGE (16)
|
||||
#define NUM_BYTES_PER_PIXEL (DYNAMIC_RANGE / 8)
|
||||
#define CLK_FREQ (156.25) /* MHz */
|
||||
@ -65,29 +61,32 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
|
||||
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
|
||||
#define DEFAULT_TX_UDP_PORT (0x7e9a)
|
||||
|
||||
/* Defines in the Firmware */
|
||||
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
|
||||
#define WAIT_TIME_US_PLL (10 * 1000)
|
||||
#define WAIT_TIME_US_STP_ACQ (100)
|
||||
#define WAIT_TIME_CONFIGURE_MAC (500 * 1000)
|
||||
|
||||
#define DAC_MAX_VOLTAGE_MV (2500)
|
||||
#define HIGHVOLTAGE_MIN (60)
|
||||
#define HIGHVOLTAGE_MAX (200)
|
||||
#define DAC_MIN_MV (0)
|
||||
#define DAC_MAX_MV (2500)
|
||||
#define VCHIP_MAX_MV (2700)
|
||||
#define VCHIP_MIN_MV (1700)
|
||||
#define POWER_RGLTR_MAX (2500)
|
||||
#define POWER_RGLTR_MIN (600)
|
||||
#define VCHIP_POWER_INCRMNT (200)
|
||||
|
||||
#define IP_PACKETSIZE (0x2032)
|
||||
#define ADC_PORT_INVERT_VAL (0x453b2593)
|
||||
#define MAXIMUM_ADC_CLK (40)
|
||||
#define PLL_VCO_FREQ_MHZ (400)
|
||||
/* Defines in the Firmware */
|
||||
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
|
||||
#define WAIT_TIME_US_PLL (10 * 1000)
|
||||
#define WAIT_TIME_US_STP_ACQ (100)
|
||||
#define WAIT_TIME_CONFIGURE_MAC (500 * 1000)
|
||||
|
||||
/* MSB & LSB DEFINES */
|
||||
#define MSB_OF_64_BIT_REG_OFST (32)
|
||||
#define LSB_OF_64_BIT_REG_OFST (0)
|
||||
#define BIT_32_MSK (0xFFFFFFFF)
|
||||
|
||||
#define IP_PACKETSIZE (0x2032)
|
||||
#define ADC_PORT_INVERT_VAL (0x453b2593)
|
||||
#define MAXIMUM_ADC_CLK (40)
|
||||
#define PLL_VCO_FREQ_MHZ (400)
|
||||
|
||||
/** PLL Reconfiguration Registers */
|
||||
//https://www.altera.com/documentation/mcn1424769382940.html
|
||||
#define PLL_MODE_REG (0x00)
|
||||
|
@ -998,6 +998,7 @@ int setThresholdEnergy(int ev) {
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
|
||||
// uses LTC2620 with 2.048V (implementation different to others not bit banging)
|
||||
void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
if (val < 0)
|
||||
return;
|
||||
@ -1020,8 +1021,14 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
}
|
||||
|
||||
#ifdef VIRTUAL
|
||||
if (mV && Common_VoltageToDac(val, &dacval, 0, DAC_MAX_VOLTAGE_MV, MAX_DAC_UNIT_VALUE) == OK)
|
||||
if (!mV) {
|
||||
(detectorModules)->dacs[ind] = val;
|
||||
}
|
||||
// convert to dac units
|
||||
else if (ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
val, &dacval) == OK) {
|
||||
(detectorModules)->dacs[ind] = dacval;
|
||||
}
|
||||
#else
|
||||
char iname[10];
|
||||
strcpy(iname,dac_names[(int)ind]);
|
||||
@ -1059,7 +1066,9 @@ int getDAC(enum DACINDEX ind, int mV) {
|
||||
return (detectorModules)->dacs[ind];
|
||||
}
|
||||
int voltage = -1;
|
||||
Common_DacToVoltage((detectorModules)->dacs[ind], &voltage, 0, DAC_MAX_VOLTAGE_MV, MAX_DAC_UNIT_VALUE);
|
||||
// dac units to voltage
|
||||
ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
(detectorModules)->dacs[ind], &voltage);
|
||||
FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, (detectorModules)->dacs[ind], voltage));
|
||||
return voltage;
|
||||
}
|
||||
|
@ -374,40 +374,40 @@ void setupDetector() {
|
||||
// Initialization
|
||||
setPhaseShiftOnce();
|
||||
|
||||
// set defines
|
||||
if (getBoardRevision() == 1)
|
||||
AD9252_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
else
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MAX_VOLTAGE_MV);
|
||||
// hv
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
// disable spi
|
||||
if (getBoardRevision() == 1)
|
||||
// adc
|
||||
if (getBoardRevision() == 1) {
|
||||
AD9252_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
AD9252_Disable();
|
||||
else
|
||||
AD9252_Configure();
|
||||
} else {
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
AD9257_Disable();
|
||||
AD9257_Configure();
|
||||
}
|
||||
|
||||
// dac
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MIN_MV, DAC_MAX_MV);
|
||||
LTC2620_Disable();
|
||||
LTC2620_Configure();
|
||||
setDefaultDacs();
|
||||
|
||||
// temp
|
||||
bus_w(TEMP_SPI_IN_REG, TEMP_SPI_IN_IDLE_MSK);
|
||||
bus_w(TEMP_SPI_OUT_REG, 0x0);
|
||||
|
||||
|
||||
#ifndef VIRTUAL
|
||||
if (getBoardRevision() == 1)
|
||||
AD9252_Configure();
|
||||
else
|
||||
AD9257_Configure();
|
||||
#endif
|
||||
|
||||
// roi, gbit readout
|
||||
setROIADC(-1); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos,
|
||||
setGbitReadout();
|
||||
LTC2620_Configure();
|
||||
|
||||
// master, slave (25um)
|
||||
setMasterSlaveConfiguration();
|
||||
|
||||
// Default Parameters
|
||||
FILE_LOG(logINFOBLUE, ("Setting Default parameters\n"));
|
||||
setDefaultDacs();
|
||||
|
||||
setSettings(DEFAULT_SETTINGS);
|
||||
setExtSignal(DEFAULT_TRIGGER_MODE);
|
||||
setTiming(DEFAULT_TIMING_MODE);
|
||||
@ -416,7 +416,7 @@ void setupDetector() {
|
||||
setTimer(ACQUISITION_TIME, DEFAULT_EXPTIME);
|
||||
setTimer(FRAME_PERIOD, DEFAULT_PERIOD);
|
||||
setTimer(DELAY_AFTER_TRIGGER, DEFAULT_DELAY);
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
}
|
||||
|
||||
int setDefaultDacs() {
|
||||
@ -1090,8 +1090,13 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
int dacval = val;
|
||||
#ifdef VIRTUAL
|
||||
if (mV && LTC2620_VoltageToDac(val, &dacval) == OK)
|
||||
if (!mV) {
|
||||
dacValues[ind] = val;
|
||||
}
|
||||
// convert to dac units
|
||||
else if (LTC2620_VoltageToDac(val, &dacval) == OK) {
|
||||
dacValues[ind] = dacval;
|
||||
}
|
||||
#else
|
||||
if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK)
|
||||
dacValues[ind] = dacval;
|
||||
|
@ -51,7 +51,8 @@ enum DACINDEX {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN
|
||||
#define DEFAULT_PHASE_SHIFT (120)
|
||||
#define DEFAULT_TX_UDP_PORT (0xE185)
|
||||
|
||||
#define DAC_MAX_VOLTAGE_MV (2500)
|
||||
#define DAC_MIN_MV (0)
|
||||
#define DAC_MAX_MV (2500)
|
||||
|
||||
/** ENEt conf structs */
|
||||
typedef struct mac_header_struct{
|
||||
|
@ -397,23 +397,20 @@ void setupDetector() {
|
||||
resetPeripheral();
|
||||
cleanFifos();
|
||||
|
||||
// set spi defines
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MAX_VOLTAGE_MV);
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST);
|
||||
// hv
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST, HIGHVOLTAGE_MIN, HIGHVOLTAGE_MAX);
|
||||
MAX1932_Disable();
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
// disable spi
|
||||
AD9257_Disable();
|
||||
LTC2620_Disable();
|
||||
MAX1932_Disable();
|
||||
// adc
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
AD9257_Disable();
|
||||
AD9257_Configure();
|
||||
|
||||
#ifndef VIRTUAL
|
||||
AD9257_Configure();
|
||||
#endif
|
||||
// initialize dac series
|
||||
LTC2620_Configure();
|
||||
|
||||
//set dacs
|
||||
//dac
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MIN_MV, DAC_MAX_MV);
|
||||
LTC2620_Disable();
|
||||
LTC2620_Configure();
|
||||
setDefaultDacs();
|
||||
|
||||
bus_w(DAQ_REG, 0x0); /* Only once at server startup */
|
||||
@ -438,15 +435,11 @@ void setupDetector() {
|
||||
selectStoragecellStart(DEFAULT_STRG_CLL_STRT);
|
||||
/*setClockDivider(HALF_SPEED); depends if all the previous stuff works*/
|
||||
setTiming(DEFAULT_TIMING_MODE);
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
/* temporary set up until new firmware fixes bug */
|
||||
// set temperature threshold
|
||||
|
||||
// temp threshold and reset event
|
||||
setThresholdTemperature(DEFAULT_TMP_THRSHLD);
|
||||
// reset temp event
|
||||
setTemperatureEvent(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -844,8 +837,13 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
int dacval = val;
|
||||
#ifdef VIRTUAL
|
||||
if (mV && LTC2620_VoltageToDac(val, &dacval) == OK)
|
||||
if (!mV) {
|
||||
dacValues[ind] = val;
|
||||
}
|
||||
// convert to dac units
|
||||
else if (LTC2620_VoltageToDac(val, &dacval) == OK) {
|
||||
dacValues[ind] = dacval;
|
||||
}
|
||||
#else
|
||||
if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK) {
|
||||
dacValues[ind] = dacval;
|
||||
@ -906,26 +904,12 @@ int setHighVoltage(int val){
|
||||
highvoltage = val;
|
||||
return highvoltage;
|
||||
#endif
|
||||
u_int32_t dacvalue;
|
||||
float alpha = 0.55;
|
||||
|
||||
// setting hv
|
||||
if (val >= 0) {
|
||||
// limit values
|
||||
if (val < 60) {
|
||||
dacvalue = 0;
|
||||
val = 0;
|
||||
} else if (val >= 200) {
|
||||
dacvalue = 0x1;
|
||||
val = 200;
|
||||
} else {
|
||||
dacvalue = 1. + (200.-val) / alpha;
|
||||
val=200.-(dacvalue-1)*alpha;
|
||||
}
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d (dacval %d)\n",val, dacvalue));
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
serializeToSPI(SPI_REG, dacvalue, HV_SERIAL_CS_OUT_MSK, MAX1932_HV_NUMBITS,
|
||||
HV_SERIAL_CLK_OUT_MSK, HV_SERIAL_DIGITAL_OUT_MSK, HV_SERIAL_DIGITAL_OUT_OFST);
|
||||
highvoltage = val;
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
MAX1932_Set(val);
|
||||
highvoltage = val;
|
||||
}
|
||||
return highvoltage;
|
||||
}
|
||||
|
@ -66,7 +66,10 @@ enum NETWORKINDEX { TXN_FRAME };
|
||||
#define DEFAULT_NUM_STRG_CLLS (0)
|
||||
#define DEFAULT_STRG_CLL_STRT (0xf)
|
||||
|
||||
#define DAC_MAX_VOLTAGE_MV (2500)
|
||||
#define HIGHVOLTAGE_MIN (60)
|
||||
#define HIGHVOLTAGE_MAX (200)
|
||||
#define DAC_MIN_MV (0)
|
||||
#define DAC_MAX_MV (2500)
|
||||
|
||||
/* Defines in the Firmware */
|
||||
#define FIX_PATT_VAL (0xACDC2014)
|
||||
|
1
slsDetectorServers/moenchDetectorServer/common.h
Symbolic link
1
slsDetectorServers/moenchDetectorServer/common.h
Symbolic link
@ -0,0 +1 @@
|
||||
../slsDetectorServer/common.h
|
@ -476,25 +476,22 @@ void setupDetector() {
|
||||
resetPeripheral();
|
||||
cleanFifos();
|
||||
|
||||
// set spi defines
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MAX_VOLTAGE_MV);
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST);
|
||||
// hv
|
||||
MAX1932_SetDefines(SPI_REG, SPI_HV_SRL_CS_OTPT_MSK, SPI_HV_SRL_CLK_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_MSK, SPI_HV_SRL_DGTL_OTPT_OFST, HIGHVOLTAGE_MIN, HIGHVOLTAGE_MAX);
|
||||
MAX1932_Disable();
|
||||
//FIXME: power regulators??
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
// disable spi
|
||||
AD9257_Disable();
|
||||
LTC2620_Disable();
|
||||
MAX1932_Disable();
|
||||
// adc
|
||||
AD9257_SetDefines(ADC_SPI_REG, ADC_SPI_SRL_CS_OTPT_MSK, ADC_SPI_SRL_CLK_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_MSK, ADC_SPI_SRL_DT_OTPT_OFST);
|
||||
AD9257_Disable();
|
||||
AD9257_Configure();
|
||||
|
||||
#ifndef VIRTUAL
|
||||
// adcs
|
||||
AD9257_Configure();
|
||||
// dacs
|
||||
//dac
|
||||
LTC2620_SetDefines(SPI_REG, SPI_DAC_SRL_CS_OTPT_MSK, SPI_DAC_SRL_CLK_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_MSK, SPI_DAC_SRL_DGTL_OTPT_OFST, NDAC, DAC_MIN_MV, DAC_MAX_MV);
|
||||
LTC2620_Disable();
|
||||
LTC2620_Configure();
|
||||
#endif
|
||||
// switch off power regulators
|
||||
powerChip(0);
|
||||
//FIXME:
|
||||
//FIXME:
|
||||
// switch off dacs (power regulators most likely only sets to minimum (if power enable on))
|
||||
{
|
||||
int idac = 0;
|
||||
@ -503,9 +500,8 @@ void setupDetector() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bus_w(ADC_PORT_INVERT_REG, ADC_PORT_INVERT_VAL);//FIXME: got from moench config file
|
||||
setvchip(VCHIP_MIN_MV);
|
||||
setHighVoltage(DEFAULT_HIGH_VOLTAGE);
|
||||
|
||||
FILE_LOG(logINFOBLUE, ("Setting Default parameters\n"));
|
||||
cleanFifos(); // FIXME: why twice?
|
||||
@ -1025,8 +1021,13 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
FILE_LOG(logDEBUG1, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
int dacval = val;
|
||||
#ifdef VIRTUAL
|
||||
if (mV && LTC2620_VoltageToDac(val, &dacval) == OK)
|
||||
if (!mV) {
|
||||
dacValues[ind] = val;
|
||||
}
|
||||
// convert to dac units
|
||||
else if (LTC2620_VoltageToDac(val, &dacval) == OK) {
|
||||
dacValues[ind] = dacval;
|
||||
}
|
||||
#else
|
||||
if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK)
|
||||
dacValues[ind] = dacval;
|
||||
@ -1075,219 +1076,6 @@ void setVLimit(int l) {
|
||||
vLimit = l;
|
||||
}
|
||||
|
||||
int isVchipValid(int val) {
|
||||
if (val < VCHIP_MIN_MV || val > VCHIP_MAX_MV) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int getVchip() {
|
||||
// not set yet
|
||||
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_PWR_DOWN_VAL)
|
||||
return dacValues[D_PWR_CHIP];
|
||||
int voltage = -1;
|
||||
Common_DacToVoltage(dacValues[D_PWR_CHIP], &voltage, VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MAX_STEPS);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
void setVchip(int val) {
|
||||
// set vchip
|
||||
if (val != -1) {
|
||||
FILE_LOG(logINFO, ("Setting Vchip to %d mV\n", val));
|
||||
|
||||
int dacval = LTC2620_PWR_DOWN_VAL;
|
||||
|
||||
// validate & convert it to dac
|
||||
if (val != LTC2620_PWR_DOWN_VAL) {
|
||||
// convert it to dac
|
||||
if (Common_VoltageToDac(val, &dacval, VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_MAX_STEPS) == FAIL) {
|
||||
FILE_LOG(logERROR, ("\tVChip %d mV invalid. Is not between %d and %d mV\n", val, VCHIP_MIN_MV, VCHIP_MAX_MV));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set
|
||||
setDAC(D_PWR_CHIP, dacval, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int getVChipToSet(enum DACINDEX ind, int val) {
|
||||
// validate index & get adc index
|
||||
int adcIndex = getADCIndexFromDACIndex(ind);
|
||||
if (adcIndex == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// get maximum value of the adc values (minimum is 0)
|
||||
int max = 0;
|
||||
|
||||
int ipwr = 0;
|
||||
// loop through the adcs
|
||||
for (ipwr = 0; ipwr < PWR -1; ++ipwr) {
|
||||
|
||||
// get the dac values for each adc
|
||||
int dacVal = dacValues[getDACIndexFromADCIndex(i)];
|
||||
|
||||
// if current index, replace with value to be set
|
||||
if (ipwr == adcIndex)
|
||||
dacVal = val;
|
||||
|
||||
// if power enable off for that adc, dont take the value
|
||||
if (!(bus_r(POWER_REG) & (1 << (POWER_ENBL_VLTG_RGLTR_OFST + ipwr))))
|
||||
dacVal = 0;
|
||||
|
||||
// update max
|
||||
max = (dacVal > max) ? dacVal : max;
|
||||
}
|
||||
|
||||
// increment to get vchip value
|
||||
max += VCHIP_POWER_INCRMNT;
|
||||
|
||||
// validate with vchip minimum value
|
||||
if (max < VCHIP_MIN_MV)
|
||||
max = VCHIP_MIN_MV;
|
||||
return max;
|
||||
}
|
||||
|
||||
int getDACIndexFromADCIndex(enum ADCINDEX ind) {
|
||||
switch (ind) {
|
||||
case V_PWR_IO:
|
||||
return D_PWR_IO;
|
||||
case V_PWR_A:
|
||||
return D_PWR_A;
|
||||
case V_PWR_B:
|
||||
return D_PWR_B;
|
||||
case V_PWR_C:
|
||||
return D_PWR_C;
|
||||
case V_PWR_D:
|
||||
return D_PWR_D;
|
||||
default:
|
||||
FILE_LOG(logERROR, ("ADC index %d is not defined to get DAC index\n", ind));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int getADCIndexFromDACIndex(enum DACINDEX ind) {
|
||||
switch (ind) {
|
||||
case D_PWR_IO:
|
||||
return V_PWR_IO;
|
||||
case D_PWR_A:
|
||||
return V_PWR_A;
|
||||
case D_PWR_B:
|
||||
return V_PWR_B;
|
||||
case D_PWR_C:
|
||||
return V_PWR_C;
|
||||
case D_PWR_D:
|
||||
return V_PWR_D;
|
||||
default:
|
||||
FILE_LOG(logERROR, ("DAC index %d is not defined to get ADC index\n", ind));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int isPowerValid(int val) {
|
||||
if (val < POWER_RGLTR_MIN || val > POWER_RGLTR_MAX) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int getPower(enum DACINDEX ind) {
|
||||
// validate index & get adc index
|
||||
int adcIndex = getADCIndexFromDACIndex(ind);
|
||||
if (adcIndex == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// powered enable off
|
||||
{
|
||||
uint32_t addr = POWER_REG;
|
||||
uint32_t offset = POWER_ENBL_VLTG_RGLTR_OFST + adcIndex;
|
||||
uint32_t mask = (1 << offset);
|
||||
if (!(bus_r(addr) & mask))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// not set yet
|
||||
if (dacValues[ind] == -1) {
|
||||
FILE_LOG(logERROR, ("Power enabled, but unknown dac value for power index %d!", ind));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// dac powered off
|
||||
if (dacValues[ind] == LTC2620_PWR_DOWN_VAL) {
|
||||
FILE_LOG(logWARNING, ("Power %d enabled, dac value %d, voltage at minimum or 0\n", ind, LTC2620_PWR_DOWN_VAL));
|
||||
return LTC2620_PWR_DOWN_VAL;
|
||||
}
|
||||
|
||||
// vchip not set, weird error, should not happen (as vchip set to max in the beginning)
|
||||
// unless user set vchip to LTC2620_PWR_DOWN_VAL and then tried to get a power regulator value
|
||||
if (dacValues[D_PWR_CHIP] == -1 || dacValues[D_PWR_CHIP] == LTC2620_PWR_DOWN_VAL) {
|
||||
FILE_LOG(logERROR, ("Cannot read power regulator %d (vchip not set)."
|
||||
"Set a power regulator, which will also set vchip.\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// voltage value
|
||||
Common_DacToVoltage(dacValues[ind], &retval, POWER_RGLTR_MIN, (getVchip() - VCHIP_POWER_INCRMNT), LTC2620_MAX_STEPS);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void setPower(enum DACINDEX ind, int val) {
|
||||
// validate index & get adc index
|
||||
int adcIndex = getADCIndexFromDACIndex(ind);
|
||||
if (adcIndex == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t addr = POWER_REG;
|
||||
uint32_t offset = POWER_ENBL_VLTG_RGLTR_OFST + adcIndex;
|
||||
uint32_t mask = (1 << offset);
|
||||
|
||||
// set power
|
||||
if (val != -1) {
|
||||
FILE_LOG(logINFO, ("Setting Power to %d mV\n", val));
|
||||
|
||||
// validate value (already checked at tcp)
|
||||
if (!isPowerValid(val)) {
|
||||
FILE_LOG(logERROR, ("\Invalid value of %d mV for Power %d. Is not between %d and %d mV\n", val, ind, POWER_RGLTR_MIN, POWER_RGLTR_MAX));
|
||||
return;
|
||||
}
|
||||
|
||||
// get vchip to set vchip (calculated now before switching off power enable)
|
||||
int vchip = getVChipToSet(ind, val);
|
||||
|
||||
// Switch off power enable
|
||||
bus_w(addr, bus_r(addr) & ~(mask));
|
||||
|
||||
// power down dac
|
||||
setDac(ind, LTC2620_PWR_DOWN_VAL, 0);
|
||||
|
||||
// set vchip
|
||||
setVchip(vchip);
|
||||
if (getvchip() != vchip) {
|
||||
FILE_LOG(logERROR, ("Weird, Could not set vchip. Set %d, read %d\n.", vchip, getvchip()));
|
||||
return;
|
||||
}
|
||||
|
||||
// convert it to dac
|
||||
if (val != LTC2620_PWR_DOWN_VAL) {
|
||||
// convert it to dac
|
||||
if (Common_VoltageToDac(val, &dacval, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT, LTC2620_MAX_STEPS) == FAIL) {
|
||||
FILE_LOG(logERROR, ("\tPower index %d of value %d mV invalid. Is not between %d and %d mV\n", ind, val, POWER_RGLTR_MIN, vchip - VCHIP_POWER_INCRMNT));
|
||||
return;
|
||||
}
|
||||
|
||||
// set and power on/ update dac
|
||||
setDAC(ind, dacval, 0);
|
||||
|
||||
// to be sure of valid conversion
|
||||
if (dacval >= 0)
|
||||
bus_w(addr, bus_r(addr) | mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getADC(enum ADCINDEX ind){
|
||||
#ifdef VIRTUAL
|
||||
@ -1308,37 +1096,14 @@ int setHighVoltage(int val){
|
||||
highvoltage = val;
|
||||
return highvoltage;
|
||||
#endif
|
||||
uint32_t dacvalue;
|
||||
float alpha = 0.55;
|
||||
// setting hv
|
||||
if (val >= 0) {
|
||||
// limit values
|
||||
if (val < 60) {
|
||||
dacvalue = 0;
|
||||
val = 0;
|
||||
} else if (val >= 200) {
|
||||
dacvalue = 0x1;
|
||||
val = 200;
|
||||
} else {
|
||||
dacvalue = 1. + (200.-val) / alpha;
|
||||
val = 200.-(dacvalue-1)*alpha;
|
||||
}
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d (dacval %d)\n",val, dacvalue));
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
uint32_t addr = POWER_REG;
|
||||
// setting hv
|
||||
if (val >= 0) {
|
||||
FILE_LOG(logINFO, ("Setting High voltage: %d V", val));
|
||||
MAX1932_Set(val);
|
||||
highvoltage = val;
|
||||
//FIXME: might have to set the power_reg to set it?
|
||||
}
|
||||
|
||||
// switch off high voltage
|
||||
bus_w(addr, bus_r(addr) & (~POWER_HV_SLCT_MSK));
|
||||
|
||||
serializeToSPI(SPI_REG, dacvalue, HV_SERIAL_CS_OUT_MSK, MAX1932_HV_NUMBITS,
|
||||
HV_SERIAL_CLK_OUT_MSK, HV_SERIAL_DIGITAL_OUT_MSK, HV_SERIAL_DIGITAL_OUT_OFST);
|
||||
|
||||
// switch on high voltage if val > 0
|
||||
if (val > 0)
|
||||
bus_w(addr, bus_r(addr) | POWER_HV_SLCT_MSK);
|
||||
|
||||
highvoltage = val;
|
||||
}
|
||||
return highvoltage;
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
|
||||
#define NCHAN_ANALOG (32)
|
||||
#define NCHAN_DIGITAL (4)
|
||||
#define NCHIP (1)
|
||||
#define NDAC (24)
|
||||
#define NPWR (6)
|
||||
#define NDAC_ONLY (NDAC - NPWR)
|
||||
//#define N_DAC (24)
|
||||
//#define N_PWR (5)
|
||||
//#define NADC (9)
|
||||
//#define DAC_CMD_OFF 20
|
||||
#define NDAC (8)
|
||||
#define DYNAMIC_RANGE (16)
|
||||
#define NUM_BYTES_PER_PIXEL (DYNAMIC_RANGE / 8)
|
||||
#define CLK_FREQ (156.25) /* MHz */
|
||||
@ -65,29 +59,27 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
|
||||
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
|
||||
#define DEFAULT_TX_UDP_PORT (0x7e9a)
|
||||
|
||||
#define HIGHVOLTAGE_MIN (60)
|
||||
#define HIGHVOLTAGE_MAX (200)
|
||||
#define DAC_MIN_MV (0)
|
||||
#define DAC_MAX_MV (2500)
|
||||
|
||||
/* Defines in the Firmware */
|
||||
#define WAIT_TME_US_FR_LK_AT_ME_REG (100) // wait time in us after acquisition done to ensure there is no data in fifo
|
||||
#define WAIT_TIME_US_PLL (10 * 1000)
|
||||
#define WAIT_TIME_US_STP_ACQ (100)
|
||||
#define WAIT_TIME_CONFIGURE_MAC (500 * 1000)
|
||||
|
||||
#define DAC_MAX_VOLTAGE_MV (2500)
|
||||
#define VCHIP_MAX_MV (2700)
|
||||
#define VCHIP_MIN_MV (1700)
|
||||
#define POWER_RGLTR_MAX (2500)
|
||||
#define POWER_RGLTR_MIN (600)
|
||||
#define VCHIP_POWER_INCRMNT (200)
|
||||
/* MSB & LSB DEFINES */
|
||||
#define MSB_OF_64_BIT_REG_OFST (32)
|
||||
#define LSB_OF_64_BIT_REG_OFST (0)
|
||||
#define BIT_32_MSK (0xFFFFFFFF)
|
||||
|
||||
#define IP_PACKETSIZE (0x2032)
|
||||
#define ADC_PORT_INVERT_VAL (0x453b2593) //FIXME: a default value?
|
||||
#define MAXIMUM_ADC_CLK (40)
|
||||
#define PLL_VCO_FREQ_MHZ (400)
|
||||
|
||||
/* MSB & LSB DEFINES */
|
||||
#define MSB_OF_64_BIT_REG_OFST (32)
|
||||
#define LSB_OF_64_BIT_REG_OFST (0)
|
||||
#define BIT_32_MSK (0xFFFFFFFF)
|
||||
|
||||
/** PLL Reconfiguration Registers */
|
||||
//https://www.altera.com/documentation/mcn1424769382940.html
|
||||
#define PLL_MODE_REG (0x00)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
#include "common.h"
|
||||
|
||||
#include "math.h"
|
||||
#include <string.h>
|
||||
|
||||
/* LTC2620 DAC DEFINES */
|
||||
@ -25,9 +24,9 @@
|
||||
#define LTC2620_NUMBITS (24)
|
||||
#define LTC2620_DAISY_CHAIN_NUMBITS (32) // due to shift register FIXME: was 33 earlier
|
||||
#define LTC2620_NUMCHANNELS (8)
|
||||
#define LTC2620_MIN_MV (0)
|
||||
#define LTC2620_MAX_STEPS (pow(2,12)) // 4096
|
||||
#define LTC2620_PWR_DOWN_VAL (-100)
|
||||
#define LTC2620_MIN_VAL (0)
|
||||
#define LTC2620_MAX_VAL (4095) // 12 bits
|
||||
|
||||
uint32_t LTC2620_Reg = 0x0;
|
||||
uint32_t LTC2620_CsMask = 0x0;
|
||||
@ -35,7 +34,8 @@ uint32_t LTC2620_ClkMask = 0x0;
|
||||
uint32_t LTC2620_DigMask = 0x0;
|
||||
int LTC2620_DigOffset = 0x0;
|
||||
int LTC2620_Ndac = 0;
|
||||
int LTC2620_MaxMV = 0;
|
||||
int LTC2620_MinVoltage = 0;
|
||||
int LTC2620_MaxVoltage = 0;
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
@ -45,16 +45,18 @@ int LTC2620_MaxMV = 0;
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param nd total number of dacs for this board (for dac channel and daisy chain chip id)
|
||||
* @param mv maximum voltage in mV
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int mv) {
|
||||
void LTC2620_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst, int nd, int minMV, int maxMV) {
|
||||
LTC2620_Reg = reg;
|
||||
LTC2620_CsMask = cmsk;
|
||||
LTC2620_ClkMask = clkmsk;
|
||||
LTC2620_DigMask = dmsk;
|
||||
LTC2620_DigOffset = dofst;
|
||||
LTC2620_Ndac = nd;
|
||||
LTC2620_MaxMV = mv;
|
||||
LTC2620_MinVoltage = minMV;
|
||||
LTC2620_MaxVoltage = maxMV;
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +78,9 @@ void LTC2620_Disable() {
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_VoltageToDac(int voltage, int* dacval) {
|
||||
return Common_VoltageToDac(voltage, dacval, LTC2620_MIN_MV, LTC2620_MaxMV, LTC2620_MAX_STEPS);
|
||||
return ConvertToDifferentRange(LTC2620_MinVoltage, LTC2620_MaxVoltage,
|
||||
LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
voltage, dacval);
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +91,9 @@ int LTC2620_VoltageToDac(int voltage, int* dacval) {
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int LTC2620_DacToVoltage(int dacval, int* voltage) {
|
||||
return Common_DacToVoltage(dacval, voltage, LTC2620_MIN_MV, LTC2620_MaxMV, LTC2620_MAX_STEPS);
|
||||
return ConvertToDifferentRange( LTC2620_MIN_VAL, LTC2620_MAX_VAL,
|
||||
LTC2620_MinVoltage, LTC2620_MaxVoltage,
|
||||
dacval, voltage);
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,14 +7,19 @@
|
||||
#define MAX1932_HV_NUMBITS (8)
|
||||
#define MAX1932_HV_DATA_OFST (0)
|
||||
#define MAX1932_HV_DATA_MSK (0x000000FF << MAX1932_HV_DATA_OFST)
|
||||
|
||||
// on power up, dac = 0xff (1.25)
|
||||
// higher voltage requires lower dac value, 0 is off
|
||||
#define MAX1932_MIN_DAC_VAL (0xFF)
|
||||
#define MAX1932_MAX_DAC_VAL (0x1)
|
||||
#define MAX1932_POWER_OFF_DAC_VAL (0x0)
|
||||
|
||||
uint32_t MAX1932_Reg = 0x0;
|
||||
uint32_t MAX1932_CsMask = 0x0;
|
||||
uint32_t MAX1932_ClkMask = 0x0;
|
||||
uint32_t MAX1932_DigMask = 0x0;
|
||||
int MAX1932_DigOffset = 0x0;
|
||||
int MAX1932_MinVoltage = 0;
|
||||
int MAX1932_MaxVoltage = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Set Defines
|
||||
@ -23,15 +28,21 @@ int MAX1932_DigOffset = 0x0;
|
||||
* @param clkmsk clock output mask
|
||||
* @param dmsk digital output mask
|
||||
* @param dofst digital output offset
|
||||
* @param minMV minimum voltage determined by hardware
|
||||
* @param maxMV maximum voltage determined by hardware
|
||||
*/
|
||||
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
|
||||
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst,
|
||||
int minMV, int maxMV) {
|
||||
MAX1932_Reg = reg;
|
||||
MAX1932_CsMask = cmsk;
|
||||
MAX1932_ClkMask = clkmsk;
|
||||
MAX1932_DigMask = dmsk;
|
||||
MAX1932_DigOffset = dofst;
|
||||
MAX1932_MinVoltage = minMV;
|
||||
MAX1932_MaxVoltage = maxMV;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable SPI
|
||||
*/
|
||||
@ -42,14 +53,6 @@ void MAX1932_Disable() {
|
||||
& ~(MAX1932_DigMask));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void MAX1932_Configure(){
|
||||
FILE_LOG(logINFOBLUE, ("Configuring MAX1932\n"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set value
|
||||
@ -57,8 +60,35 @@ void MAX1932_Configure(){
|
||||
*/
|
||||
void MAX1932_Set (int val) {
|
||||
FILE_LOG(logDEBUG1, ("\tSetting high voltage to %d\n", val));
|
||||
if (val < 0)
|
||||
return FAIL;
|
||||
|
||||
uint32_t dacvalue = 0;
|
||||
|
||||
// limit values (normally < 60 => 0 (off))
|
||||
if (val < MAX1932_MinVoltage) {
|
||||
dacvalue = MAX1932_POWER_OFF_DAC_VAL;
|
||||
val = 0;
|
||||
}
|
||||
// limit values (normally > 200 => 0x1 (max))
|
||||
else if (val > MAX1932_MaxVoltage) {
|
||||
dacvalue = MAX1932_MAX_DAC_VAL;
|
||||
val = MAX1932_MaxVoltage;
|
||||
}
|
||||
// convert value
|
||||
else {
|
||||
// no failure in conversion as limits handled (range from 0x1 to 0xFF)
|
||||
ConvertToDifferentRange(MAX1932_MinVoltage, MAX1932_MaxVoltage,
|
||||
MAX1932_MIN_DAC_VAL, MAX1932_MAX_DAC_VAL,
|
||||
val, &dacvalue);
|
||||
dacvalue &= MAX1932_HV_DATA_MSK;
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
|
||||
serializeToSPI(MAX1932_Reg, dacvalue, MAX1932_CsMask, MAX1932_HV_NUMBITS,
|
||||
MAX1932_ClkMask, MAX1932_DigMask, MAX1932_DigOffset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,44 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Convert voltage to dac units
|
||||
* @param voltage value in mv
|
||||
* @param dacval pointer to value converted to dac units
|
||||
* @param vmin minimum voltage in mV
|
||||
* @param vmax maximum voltage in mV
|
||||
* @param maximum number of steps
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
* Convert a value from a range to a different range (eg voltage to dac or vice versa)
|
||||
* @param inputMin input minimum
|
||||
* @param inputMax input maximum
|
||||
* @param outputMin output minimum
|
||||
* @param outputMax output maximum
|
||||
* @param inputValue input value
|
||||
* @param outputValue pointer to output value
|
||||
* @returns FAIL if input value is out of bounds, else OK
|
||||
*/
|
||||
int Common_VoltageToDac(int voltage, int* dacval, int vmin, int vmax, int nsteps) {
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax,
|
||||
int inputValue, int* outputValue) {
|
||||
FILE_LOG(logDEBUG1, ("\tInput Value: %d\n", inputValue));
|
||||
|
||||
// validate
|
||||
if ((voltage < vmin) || (voltage > vmax)) {
|
||||
FILE_LOG(logERROR, ("Voltage value (to convert to dac value) is outside bounds (%d to %d mV): %d\n", vmin, vmax, voltage));
|
||||
// validate within bounds
|
||||
// eg. MAX1932 range is v(60 - 200) to dac(255 - 1), here inputMin > inputMax (when dac to voltage)
|
||||
int smaller = inputMin;
|
||||
int bigger = inputMax;
|
||||
if (smaller > bigger) {
|
||||
smaller = inputMax;
|
||||
bigger = inputMin;
|
||||
}
|
||||
if ((inputValue < smaller) || (inputValue > bigger)) {
|
||||
FILE_LOG(logERROR, ("Input Value is outside bounds (%d to %d): %d\n", inputValue, smaller, bigger));
|
||||
*outputValue = -1;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// convert
|
||||
*dacval = (int)(((voltage - vmin) / (vmax - vmin)) * (nsteps - 1) + 0.5);
|
||||
return OK;
|
||||
}
|
||||
/**
|
||||
* Convert dac units to voltage
|
||||
* @param dacval dac units
|
||||
* @param voltage pointer to value converted to mV
|
||||
* @param vmin minimum voltage in mV
|
||||
* @param vmax maximum voltage in mV
|
||||
* @param maximum number of steps
|
||||
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||
*/
|
||||
int Common_DacToVoltage(int dacval, int* voltage, int vmin, int vmax, int nsteps) {
|
||||
double value = double((inputValue - inputMin) * (outputMax - outputMin))
|
||||
/ double(inputMax - inputMin) + outputMin;
|
||||
|
||||
// validate
|
||||
if ((dacval < 0) || (dacval >= nsteps)) {
|
||||
FILE_LOG(logERROR, ("Dac units (to convert to voltage) is outside bounds (0 to %d): %d\n", nsteps - 1, dacval));
|
||||
return FAIL;
|
||||
// double to integer conversion (if decimal places, round to integer)
|
||||
if ((value - (int)value) > 0.0001) {
|
||||
value += 0.5;
|
||||
}
|
||||
*outputValue = value;
|
||||
|
||||
// convert
|
||||
*voltage = vmin + (vmax - vmin) * dacval / (nsteps - 1);
|
||||
FILE_LOG(logDEBUG1, ("\tConverted Ouput Value: %d\n", *outputValue));
|
||||
return OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user