M3: fixed gain bits with negative polarity

This commit is contained in:
Erik Frojdh
2021-04-12 16:44:47 +02:00
parent d9cd780386
commit be5fee8126
14 changed files with 97 additions and 9 deletions

View File

@ -35,6 +35,44 @@ int getChipStatusRegister(){
return chipStatusRegister;
}
int gainCapsToCsr(int caps){
//Translates bit representation
int csr = 0;
if (!(caps & M3_C10pre))
csr |= 1 << _CSR_C10pre;
if (caps & M3_C15sh)
csr |= 1 << CSR_C15sh;
if (caps & M3_C30sh)
csr |= 1 << CSR_C30sh;
if (caps & M3_C50sh)
csr |= 1 << CSR_C50sh;
if (caps & M3_C225ACsh)
csr |= 1 << CSR_C225ACsh;
if (!(caps & M3_C15pre))
csr |= 1 << _CSR_C15pre;
return csr;
}
int csrToGainCaps(int csr){
//Translates bit representation
int caps = 0;
if (!(csr & (1 << _CSR_C10pre)))
caps |= M3_C10pre;
if (csr & (1 << CSR_C15sh))
caps |= M3_C15sh;
if (csr & (1 << CSR_C30sh))
caps |= M3_C30sh;
if (csr & (1 << CSR_C50sh))
caps |= M3_C50sh;
if (csr & (1 << CSR_C225ACsh))
caps |= M3_C225ACsh;
if (!(csr & (1 << _CSR_C15pre)))
caps |= M3_C15pre;
return caps;
}
patternParameters *setChipStatusRegisterPattern(int csr) {
int iaddr=0;
int nbits=18;

View File

@ -37,23 +37,25 @@
#define CSR_invpol 4
#define CSR_dpulse 5
#define CSR_interp 6
#define CSR_C10pre 7 //#default
#define _CSR_C10pre 7 //#default, negative polarity
#define CSR_pumprobe 8
#define CSR_apulse 9
#define CSR_C15sh 10
#define CSR_C30sh 11 //#default
#define CSR_C50sh 12
#define CSR_C225ACsh 13 // Connects 225fF SHAPER AC cap (1: 225 to shaper, 225 to GND. 0: 450 to shaper)
#define CSR_C15pre 14
#define _CSR_C15pre 14 // negative polarity
#define CSR_default (1<<CSR_C10pre )|(1<< CSR_C30sh)
#define CSR_default (1<<_CSR_C10pre )|(1<< CSR_C30sh)
#define GAIN_MASK ((1 << CSR_C10pre) | ( 1 << CSR_C15sh) | (1 << CSR_C30sh) | (1 << CSR_C50sh) | (1 << CSR_C225ACsh) | ( 1 << CSR_C15pre))
#define GAIN_MASK ((1 << _CSR_C10pre) | ( 1 << CSR_C15sh) | (1 << CSR_C30sh) | (1 << CSR_C50sh) | (1 << CSR_C225ACsh) | ( 1 << _CSR_C15pre))
int setBit(int ibit, int patword);
int clearBit(int ibit, int patword);
int getChipStatusRegister();
int gainCapsToCsr(int caps);
int csrToGainCaps(int csr);
patternParameters *setChipStatusRegisterPattern(int csr);
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits);

View File

@ -1078,8 +1078,8 @@ int setDACS(int* dacs){
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module\n"));
if (setGainCaps(myMod.reg)){
sprintf(mess, "Could not set module gain caps\n");
if (setChipStatusRegister(myMod.reg)){
sprintf(mess, "Could not CSR from module\n");
LOG(logERROR, (mess));
return FAIL;
}
@ -2667,7 +2667,15 @@ int setGainCaps(int caps){
// Update only gain caps, leave the rest of the CSR unchanged
int csr = getChipStatusRegister();
csr &= ~GAIN_MASK;
caps &= GAIN_MASK;
caps = gainCapsToCsr(caps);
// caps &= GAIN_MASK;
csr |= caps;
return setChipStatusRegister(csr);
}
int getGainCaps(){
int csr = getChipStatusRegister();
int caps = csrToGainCaps(csr);
return caps;
}