also save TRG-OUT setting, change PHA default channel setting

This commit is contained in:
carina@hades 2022-08-12 18:13:54 -04:00
parent 972c249076
commit 0a6f866f7a
3 changed files with 86 additions and 46 deletions

View File

@ -234,6 +234,7 @@ void Digitizer::ErrorMsg(string header){
int Digitizer::ProgramBoard(){
printf("----- program Board\n");
ret = CAEN_DGTZ_Reset(handle);
if (ret) {
printf("ERROR: can't reset the digitizer.\n");
@ -291,7 +292,7 @@ void Digitizer::StartACQ(){
ErrorMsg("Start ACQ");
return;
}
printf("Acquisition Started for Board %d\n", boardID);
printf("\e[1m\e[33m======= Acquisition Started for Board %d\e[0m\n", boardID);
AcqRun = true;
}
@ -339,17 +340,27 @@ void Digitizer::ReadData(){
printf(" extracted %d events in ch-%02d\n", NumEvents[i], i);
}
ErrorMsg("GetDPPEvents");
FILE * haha = fopen("output.bin", "w+");
fwrite(buffer, BufferSize, 1, haha);
fclose(haha);
}
//===========================================================
void Digitizer::WriteRegister(uint32_t address, uint32_t value, int ch ){
/// only for channel setting.
if( ch < 0 ) {
ret = CAEN_DGTZ_WriteRegister(handle, address + 0x7000, value);
for( int i = 0; i < NChannel; i++) EditByte(value, address + (i << 8));
if( address < 0x8000){
///printf("0x%x, 0x%x=%u, ch:%d\n", address, value, value, ch);
if( ch < 0 ) {
ret = CAEN_DGTZ_WriteRegister(handle, address + 0x7000, value);
for( int i = 0; i < NChannel; i++) EditByte(value, address + (i << 8));
}else{
ret = CAEN_DGTZ_WriteRegister(handle, address + (ch<<8), value);
EditByte( value, address + (ch<<8) );
}
}else{
ret = CAEN_DGTZ_WriteRegister(handle, address + (ch<<8), value);
EditByte( value, address + (ch<<8) );
ret = CAEN_DGTZ_WriteRegister(handle, address, value);
}
ErrorMsg("WriteRegister");
}
@ -378,16 +389,14 @@ void Digitizer::SetChannelMask(uint32_t mask){
}
void Digitizer::SetRecordLength(unsigned int ns, int ch){
int ch_coupled = ch + int(pow(-1, ch));
WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch);
WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch_coupled);
if( ch >= 0 ) WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch + int(pow(-1, ch)));
ErrorMsg("SetRecordLength");
}
void Digitizer::SetEventAggregation(unsigned int numEvent, int ch){
int ch_coupled = ch + int(pow(-1, ch));
WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch);
WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch_coupled);
if( ch >= 0 ) WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch + int(pow(-1, ch)));
ErrorMsg("SetEventAggregation");
}
void Digitizer::SetInputDynamicRange(unsigned int TwoVol_0_or_halfVol_1, int ch){ WriteRegister( Register::DPP::InputDynamicRange, TwoVol_0_or_halfVol_1, ch); ErrorMsg("SetInputDynamicRange");}
@ -454,11 +463,15 @@ void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){
}
void Digitizer::SetBits(uint32_t address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){
///printf("address : 0x%x, value : 0x%x, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch);
uint32_t bit ;
uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos);
if (ch < 0 ) ch = 0; /// take ch-0
bit = ReadRegister(address, ch);
uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos);
int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
bit = ReadRegister(address, tempCh);
///printf("bit : 0x%x, bitmask : 0x%x \n", bit, bitmask);
bit = (bit & ~bitmask) | (bitValue << bitSmallestPos);
///printf("bit : 0x%x, ch : %d \n", bit, ch);
WriteRegister(address, bit, ch);
if( ret != 0 ) ErrorMsg("SetBits");
}
@ -584,17 +597,21 @@ void Digitizer::CreateAndSaveSettingBinary(string fileName){
settingFileExist = true;
///Save board setting
EditByteByRegister(Register::DPP::BoardConfiguration);
EditByteByRegister(Register::DPP::GlobalTriggerMask);
EditByteByRegister(Register::DPP::ChannelEnableMask);
EditByteByRegister(Register::DPP::ROM_BoardVersion);
EditByteByRegister(Register::DPP::ROM_BoardFromFactor);
EditByteByRegister(Register::DPP::ROM_BoardIDByte1);
EditByteByRegister(Register::DPP::ROM_BoardIDByte0);
EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte1);
EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte0);
EditByteByRegister(Register::DPP::ROCFPGAFirmwareRevision);
EditByteByRegister(Register::DPP::BoardInfo);
EditByteByRegister(Register::DPP::BoardConfiguration); /// 0x8000
EditByteByRegister(Register::DPP::GlobalTriggerMask); /// 0x810C
EditByteByRegister(Register::DPP::ChannelEnableMask); /// 0x8120
EditByteByRegister(Register::DPP::FrontPanelTRGOUTEnableMask); /// 0x8110
EditByteByRegister(Register::DPP::FrontPanelIOControl); /// 0x811C
EditByteByRegister(Register::DPP::DisableExternalTrigger); /// 0x817C
EditByteByRegister(Register::DPP::TriggerValidationMask); /// 0x8180
EditByteByRegister(Register::DPP::ROM_BoardVersion); /// 0xF030
EditByteByRegister(Register::DPP::ROM_BoardFromFactor); /// 0xF034
EditByteByRegister(Register::DPP::ROM_BoardIDByte1); /// 0xF038
EditByteByRegister(Register::DPP::ROM_BoardIDByte0); /// 0xF03C
EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte1); /// 0xF080
EditByteByRegister(Register::DPP::ROM_BoardSerialNumByte0); /// 0xF084
EditByteByRegister(Register::DPP::ROCFPGAFirmwareRevision); /// 0x8124
EditByteByRegister(Register::DPP::BoardInfo); /// 0x8140
///================ channel settings
for( int ch = 0; ch < NChannel ; ch++){

View File

@ -13,8 +13,8 @@ DigitizerPHA::~DigitizerPHA(){
}
int DigitizerPHA::ProgramBoard(){
printf("program board and channels\n");
Digitizer::ProgramBoard();
Digitizer::ProgramBoard();
printf("----- program PHA\n");
/// Set trigger propagation
/// Set analog probe 1 to input
/// Set analog probe 2 to Tranpedoiz - Baseline
@ -30,31 +30,33 @@ int DigitizerPHA::ProgramBoard(){
SetRecordLength(2000);
SetPreTriggerDuration(500);
SetBaselineSampling(0x11);
SetBaselineSampling(5);
SetDCOffset(0.2);
SetInputDynamicRange(1);
SetInputDynamicRange(0);
SetPulsePolarity(0);
SetTriggerThreshold(200);
SetTriggerThreshold(100);
SetTriggerHoldOff(480);
SetTriggerSmoothingFactor(2);
SetTriggerOutputWidth(50);
SetTriggerOutputWidth(0);
SetInputRiseTime(96);
SetTrapezoidRescaling(31);
SetTrapezoidRescaling(19);
SetTrapezoidRiseTime(200);
SetTrapezoidFlatTop(50);
SetDecayTime(10000);
SetPeakingTime(50);
SetPeakingHoldOff(1000);
SetDecayTime(3125);
SetPeakingTime(5);
SetPeakingHoldOff(62);
SetPeakSampling(2);
SetEnergyFineGain(1);
SetRiseTimeValidWindow(10);
SetRiseTimeValidWindow(0);
SetEventAggregation(0);
SetRollOverFlag(1);
SetPileUpFlag(1);
SetExtra2WordOption(2);
//WriteRegister(Register::DPP::DPPAlgorithmControl, 0xc300013);
ErrorMsg("PHA-ProgramBoard");
printf("End of program board and channels\n");
@ -69,14 +71,14 @@ void DigitizerPHA::SetTimeStampRecording(bool OnOff) { SetBits(Register::DPP::Bo
void DigitizerPHA::SetEnergyRecording(bool OnOff) { SetBits(Register::DPP::BoardConfiguration, OnOff, 1, 19); ErrorMsg("PHA-SetEnergyRecording");}
void DigitizerPHA::SetVirtualProbe1(unsigned int bit){ SetBits(Register::DPP::BoardConfiguration, bit, 4, 20); ErrorMsg("PHA-SetVirtualProbe1"); }
void DigitizerPHA::SetTrapezoidRescaling(unsigned int rightShiftBits, int ch ){ SetBits(Register::DPP::DPPAlgorithmControl, rightShiftBits, 5, 0, ch); ErrorMsg("SetTrapezoidRescaling"); }
void DigitizerPHA::SetPeakSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 2, 12, ch); ErrorMsg("SetPeakSampling");}
void DigitizerPHA::SetPulsePolarity(bool PositiveIsZero, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, PositiveIsZero, 1, 16, ch); ErrorMsg("SetPulsePolarity");}
void DigitizerPHA::SetBaselineSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 3, 20, ch); ErrorMsg("SetBaselineSampling"); }
void DigitizerPHA::SetRollOverFlag(bool isRollOver, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isRollOver, 1, 26, ch); ErrorMsg("SetRollOverFlag");}
void DigitizerPHA::SetPileUpFlag(bool isPileUpFlag, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isPileUpFlag, 1, 27, ch); ErrorMsg("SetPileUpFlag");}
void DigitizerPHA::SetTrapezoidRescaling(unsigned int rightShiftBits, int ch){ SetBits(Register::DPP::DPPAlgorithmControl, rightShiftBits, 5, 0, ch); ErrorMsg("SetTrapezoidRescaling"); }
void DigitizerPHA::SetPeakSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 2, 12, ch); ErrorMsg("SetPeakSampling");}
void DigitizerPHA::SetPulsePolarity(bool PositiveIsZero, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, PositiveIsZero, 1, 16, ch); ErrorMsg("SetPulsePolarity");}
void DigitizerPHA::SetBaselineSampling(unsigned int bit, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, bit, 3, 20, ch); ErrorMsg("SetBaselineSampling"); }
void DigitizerPHA::SetRollOverFlag(bool isRollOver, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isRollOver, 1, 26, ch); ErrorMsg("SetRollOverFlag");}
void DigitizerPHA::SetPileUpFlag(bool isPileUpFlag, int ch) { SetBits(Register::DPP::DPPAlgorithmControl, isPileUpFlag, 1, 27, ch); ErrorMsg("SetPileUpFlag");}
void DigitizerPHA::SetExtra2WordOption(unsigned int bit, int ch) { SetBits(Register::DPP::PHA::DPPAlgorithmControl2_G, bit, 3, 8, ch); ErrorMsg("PHA-SetExtra2WordOption");}
void DigitizerPHA::SetExtra2WordOption(unsigned int bit, int ch) { SetBits(Register::DPP::PHA::DPPAlgorithmControl2_G, bit, 3, 8, ch); ErrorMsg("PHA-SetExtra2WordOption");}
void DigitizerPHA::SetTriggerThreshold(unsigned int threshold, int ch ) { WriteRegister(Register::DPP::PHA::TriggerThreshold, threshold & 0x03FF, ch); ErrorMsg("PHA-SetTriggerThreshold");}
void DigitizerPHA::SetTriggerHoldOff(unsigned int nSample, int ch ) { WriteRegister(Register::DPP::PHA::TriggerHoldOffWidth, nSample & 0x03FF, ch); ErrorMsg("PHA-SetTriggerHoldOff"); }
@ -102,6 +104,7 @@ void DigitizerPHA::PrintBoardConfiguration(){
printf(" 32 28 24 20 16 12 8 4 0\n");
printf(" | | | | | | | | |\n");
cout <<" Board Configuration : 0b" << bitset<32>(value[0]) << endl;
printf(" : 0x%x\n", value[0]);
printf(" Bit[ 0] = Auto Data Flush \n");
printf(" Bit[ 1] = Save decimated waveform \n");
printf(" Bit[ 2] = Trigger propagation \n");

View File

@ -13,19 +13,39 @@ int main(int argc, char* argv[]){
dig[i].OpenDigitizer(board, port, true);
dig[i].OpenSettingBinary("setting_" + to_string(dig[i].GetSerialNumber()) + ".bin");
dig[i].SetAcqMode("list");
//dig[i].PrintACQStatue();
dig[i].PrintACQStatue();
}
//dig[0].PrintBoardConfiguration();
//dig[0].WriteRegister(Register::DPP::FrontPanelTRGOUTEnableMask, 0xFF, -1);
//dig[0].WriteRegister(Register::DPP::FrontPanelIOControl, 0x100, -1);
//dig[0].WriteRegister(Register::DPP::TriggerValidationMask, 0, -1);
//dig[0].SetTriggerThreshold(100);
//dig[0].SetBits(Register::DPP::BoardConfiguration, 0x0101, 4, 20); // TRG validation window
dig[0].PrintBoardConfiguration(); //[20:23] vitural probe
dig[0].PrintChannelSettingFromDigitizer(15);
//dig[0].ReadRegister(Register::DPP::PHA::DPPAlgorithmControl2_G, 13, "DPP Control 2");
//dig[0].ReadRegister(Register::DPP::AcquisitionControl, -1, "Acq control"); // [0:1]
//dig[0].ReadRegister(Register::DPP::GlobalTriggerMask, -1, "GlobalTrigger mask");
//dig[0].ReadRegister(Register::DPP::FrontPanelTRGOUTEnableMask, -1, "Front Planel Trig-OUT mask"); /// should be 0xFF
//dig[0].ReadRegister(Register::DPP::FrontPanelIOControl, -1, "Front Planel I/O control");
//dig[0].ReadRegister(Register::DPP::DisableExternalTrigger, -1, "Disable External Trigger");
//dig[0].ReadRegister(Register::DPP::TriggerValidationMask, -1, "Trigger validation Mask");
//dig[0].PrintChannelSettingFromDigitizer(15);
//Data * data = dig[0].data;
//data->AllocateMemory(dig[0].GetHandle());
dig[0].StartACQ();
sleep(2);
sleep(5);
dig[0].ReadData();