From c51bd7e66235ba19b62f18d987e594f480884a23 Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Wed, 11 Oct 2023 18:28:19 -0400 Subject: [PATCH] many bug fix, added QDC in Scope --- ClassData.h | 4 +- ClassDigitizer.cpp | 109 +++++++++++- DigiSettingsPanel.cpp | 139 ++++++++++++--- DigiSettingsPanel.h | 1 + FSUDAQ.cpp | 22 ++- README.md | 1 - RegisterAddress.h | 6 +- Scope.cpp | 389 ++++++++++++++++++++++++++++++++++-------- Scope.h | 19 ++- macro.h | 2 +- test.cpp | 65 +++++-- 11 files changed, 625 insertions(+), 132 deletions(-) diff --git a/ClassData.h b/ClassData.h index 4c3ee1c..fee85c1 100644 --- a/ClassData.h +++ b/ClassData.h @@ -412,7 +412,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ unsigned int bdAggTimeTag = ReadBuffer(nw, verbose); if( verbose >= 2 ) printf("Agg Time Tag : %u \n", bdAggTimeTag); - for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of RegChannel is 8 for PHA, PSD, QDC + for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; if( verbose >= 2 ) printf("==================== Dual/Group Channel Block, ch Mask : 0x%X, nw : %d\n", chMask *2, nw); @@ -526,7 +526,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe unsigned int digitalProbe = ( (word >> 16 ) & 0xF ); unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 ); unsigned int analogProbe1 = ( (word >> 22 ) & 0x3 ); - bool hasWaveForm = ( (word >> 27 ) & 0x1 ); + hasWaveForm = ( (word >> 27 ) & 0x1 ); bool hasTimeStamp = ( (word >> 29 ) & 0x1 ); bool hasEnergy = ( (word >> 30 ) & 0x1 ); hasDualTrace = ( (word >> 31 ) & 0x1 ); diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index f73ad23..8fddd60 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -295,8 +295,24 @@ int Digitizer::ProgramBoard_PHA(){ address = DPP::PHA::PeakHoldOff; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E ); address = DPP::PHA::TriggerHoldOffWidth; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E ); address = DPP::PHA::RiseTimeValidationWindow;ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x0 ); - - ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::ChannelDCOffset) + 0x7000 , 0x0CCC ); + + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x0, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x1, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x2, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x3, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x4, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x5, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x6, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x7, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x8, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x9, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xA, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xB, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xC, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xD, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xE, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xF, 0xAAAA); + ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PreTrigger) + 0x7000 , 32 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::InputDynamicRange) + 0x7000 , 0x0 ); @@ -305,9 +321,12 @@ int Digitizer::ProgramBoard_PHA(){ ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::MaxAggregatePerBlockTransfer), 4); ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(DPP::DPPAlgorithmControl) + 0x7000, 0xC30200f); - if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} + if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");} isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); + + usleep(1000*300); + ReadAllSettingsFromBoard(); return ret; @@ -328,7 +347,22 @@ int Digitizer::ProgramBoard_PSD(){ ret |= CAEN_DGTZ_SetChannelEnableMask(handle, 0xFFFF); - ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::ChannelDCOffset) + 0x7000 , 0xEEEE ); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x0, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x1, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x2, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x3, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x4, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x5, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x6, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x7, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x8, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x9, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xA, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xB, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xC, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xD, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xE, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xF, 0xAAAA); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PreTrigger) + 0x7000 , 20 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::RecordLength_G) + 0x7000 , 80 ); @@ -337,9 +371,12 @@ int Digitizer::ProgramBoard_PSD(){ ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::LongGateWidth) + 0x7000 , 64 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::GateOffset) + 0x7000 , 19 ); - if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} + if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");} isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); + + usleep(1000*300); + ReadAllSettingsFromBoard(); return ret; } @@ -349,9 +386,63 @@ int Digitizer::ProgramBoard_QDC(){ printf("===== Digitizer::%s\n", __func__); Reset(); - ret = CAEN_DGTZ_SetChannelEnableMask(handle, 0xFFFF); + int ret = 0; + + WriteRegister(DPP::QDC::RecordLength, 6000/16, -1); + WriteRegister(DPP::QDC::GateWidth, 100/16, -1); + WriteRegister(DPP::QDC::GateOffset, 0, -1); + WriteRegister(DPP::QDC::FixedBaseline, 0, -1); + WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1); + //WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse + WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse + WriteRegister(DPP::QDC::TriggerHoldOffWidth, 100/16, -1); + WriteRegister(DPP::QDC::TRGOUTWidth, 100/16, -1); + //WriteRegister(DPP::QDC::OverThresholdWidth, 100/16, -1); + //WriteRegister(DPP::QDC::DCOffset, 100/16, -1); + WriteRegister(DPP::QDC::SubChannelMask, 0xFF, -1); + + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x0, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x1, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x2, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x3, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x4, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x5, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x6, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x7, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x8, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x9, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xA, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xB, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xC, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xD, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xE, 0xAAAA); + ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xF, 0xAAAA); + + + WriteRegister(DPP::QDC::TriggerThreshold_sub0, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub1, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub2, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub3, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub4, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub5, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub6, 100, -1); + WriteRegister(DPP::QDC::TriggerThreshold_sub7, 100, -1); + + WriteRegister(DPP::BoardConfiguration, 0xC0110); + WriteRegister(DPP::AggregateOrganization, 0x0); + WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x100); + WriteRegister(DPP::AcquisitionControl, 0x0); + WriteRegister(DPP::GlobalTriggerMask, 0x0); + WriteRegister(DPP::FrontPanelTRGOUTEnableMask, 0x0); + WriteRegister(DPP::FrontPanelIOControl, 0x0); + WriteRegister(DPP::QDC::GroupEnableMask, 0xFF); + WriteRegister(DPP::MaxAggregatePerBlockTransfer, 0x4); + + if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");} isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); + + usleep(1000*300); ReadAllSettingsFromBoard(); return ret; @@ -370,8 +461,8 @@ void Digitizer::StartACQ(){ } } - if( DPPType == V1730_DPP_PSD_CODE) bufferSize = 160 * 1024 * 1024; //TODO allocate 160 MB for PSD - if( DPPType == V1740_DPP_QDC_CODE) bufferSize = 160 * 1024 * 1024; //TODO allocate 160 MB for QDC + if( DPPType == V1730_DPP_PSD_CODE) bufferSize = 100 * 1024 * 1024; //TODO allocate 160 MB for PSD + if( DPPType == V1740_DPP_QDC_CODE) bufferSize = 100 * 1024 * 1024; //TODO allocate 160 MB for QDC data->AllocateMemory(bufferSize); @@ -511,7 +602,7 @@ void Digitizer::PrintACQStatue(){ //=========================================================== void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){ - printf("%30s[0x%04X](ch-%02d) [0x%04X]: 0x%08X \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, registerAddress.ActualAddress(ch), value); + printf("%30s[0x%04X](digi-%d,ch-%02d) [0x%04X]: 0x%08X \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),GetSerialNumber(), ch, registerAddress.ActualAddress(ch), value); if( !isConnected ) { //SetSettingToMemory(registerAddress, value, ch); //TODO should the binary setting be edited offline? diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index 665e325..2e5a880 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -186,10 +186,11 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr connect(bnProgramPreDefined, &QPushButton::clicked, this, [=](){ if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) digi[ID]->ProgramBoard_PHA(); if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) digi[ID]->ProgramBoard_PSD(); + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) digi[ID]->ProgramBoard_QDC(); usleep(1000*500); // wait for 0.2 sec - ReadSettingsFromBoard(); + UpdatePanelFromMemory(); emit UpdateOtherPanels(); }); @@ -2463,22 +2464,48 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ sbFixedBaseline[ID][numGroup]->setEnabled( cbBaseLineAvg[ID][numGroup]->currentData().toInt() == 0); }); - /// DC offset - QGroupBox * dcWidget = new QGroupBox("Fine DC offset [LSB]",inputBox); + /// DC offset + SubChannel On/Off + QGroupBox * dcWidget = new QGroupBox("SubCh On/Off + Fine DC offset [LSB]",inputBox); inputLayout->addWidget(dcWidget, 5, 0, 1, 4); QGridLayout * dcLayout = new QGridLayout(dcWidget); dcLayout->setSpacing(2); - int grpID = chSelection[ID]->currentIndex(); + int grpID = chSelection[ID]->currentIndex() - 1; for( int i = 0; i < 8; i ++){ lbSubCh[ID][i] = new QLabel("Sub-Ch:" + QString::number(grpID < 0 ? i : grpID*8 + i), dcWidget); lbSubCh[ID][i]->setAlignment(Qt::AlignRight | Qt::AlignCenter); - dcLayout->addWidget(lbSubCh[ID][i], 1 + i/4, 2*(i%4) ); + dcLayout->addWidget(lbSubCh[ID][i], 1 + i/4, 3*(i%4) ); + + pbSubChMask[ID][8][i] = new QPushButton(inputBox); + pbSubChMask[ID][8][i]->setFixedSize(QSize(20,20)); + dcLayout->addWidget(pbSubChMask[ID][8][i], 1 + i/4, 3*(i%4) + 1 ); + + connect(pbSubChMask[ID][8][i], &QPushButton::clicked, this, [=](){ + if( !enableSignalSlot) return; + + int grpID = chSelection[ID]->currentIndex() - 1; + + if( pbSubChMask[ID][8][i]->styleSheet() == "" ){ + pbSubChMask[ID][8][i]->setStyleSheet("background-color : green;"); + + digi[ID]->SetBits(DPP::QDC::SubChannelMask, {1, i}, 1, grpID); + + }else{ + pbSubChMask[ID][8][i]->setStyleSheet(""); + digi[ID]->SetBits(DPP::QDC::SubChannelMask, {1, i}, 0, grpID); + } + + UpdateSettings_QDC(); + SyncAllChannelsTab_QDC(); + + emit UpdateOtherPanels(); + }); + sbSubChOffset[ID][8][i] = new RSpinBox(inputBox); - dcLayout->addWidget(sbSubChOffset[ID][8][i], 1 + i/4, 2*(i%4) + 1 ); + dcLayout->addWidget(sbSubChOffset[ID][8][i], 1 + i/4, 3*(i%4) + 2 ); sbSubChOffset[ID][8][i]->setMinimum(-1); sbSubChOffset[ID][8][i]->setMaximum(0xFF); @@ -2652,7 +2679,7 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ QTabWidget * inputTab = new QTabWidget(this); inputLayout->addWidget(inputTab); - QStringList tabName = {"Common Settings", "Baseline", "Fine DC offset"}; + QStringList tabName = {"Common Settings", "Baseline", "Fine DC offset", "Ch. On/Off"}; const int nTab = tabName.count(); @@ -2684,6 +2711,7 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ QLabel * lb6 = new QLabel("Polarity", this); lb6->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb6, 0, 8); QLabel * lb7 = new QLabel("Input Smoothing", this); lb7->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb7, 0, 10); } + SetUpSpinBox(sbDCOffset[ID][ch], "", tabLayout, ch + 1, 1, DPP::QDC::DCOffset, ch); SetUpSpinBox(sbRecordLength[ID][ch], "", tabLayout, ch + 1, 3, DPP::QDC::RecordLength, ch); SetUpSpinBox(sbPreTrigger[ID][ch], "", tabLayout, ch + 1, 5, DPP::QDC::PreTrigger, ch); @@ -2747,6 +2775,39 @@ void DigiSettingsPanel::SetUpChannel_QDC(){ };/// end of subCh } + if( i == 3 ){ + for(int subCh = 0; subCh < 8; subCh ++ ){ + + if( ch == 0 ){ + QLabel * lb0 = new QLabel("SubCh-" + QString::number(subCh), this); lb0->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb0, 0, subCh+1); + } + + pbSubChMask[ID][ch][subCh] = new QPushButton(this); + pbSubChMask[ID][ch][subCh]->setFixedSize(QSize(20,20)); + tabLayout->addWidget(pbSubChMask[ID][ch][subCh], ch + 1, subCh + 1 ); + + connect(pbSubChMask[ID][ch][subCh], &QPushButton::clicked, this, [=](){ + if( !enableSignalSlot) return; + + if( pbSubChMask[ID][ch][subCh]->styleSheet() == "" ){ + pbSubChMask[ID][ch][subCh]->setStyleSheet("background-color : green;"); + + digi[ID]->SetBits(DPP::QDC::SubChannelMask, {1, subCh}, 1, ch); + + }else{ + pbSubChMask[ID][ch][subCh]->setStyleSheet(""); + digi[ID]->SetBits(DPP::QDC::SubChannelMask, {1, subCh}, 0, ch); + } + + UpdatePanelFromMemory(); + emit UpdateOtherPanels(); + return; + }); + + + } + } + } } @@ -3048,6 +3109,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ chkTrigPropagation[ID]->setChecked( Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::TrigPropagation) ); } + ///========================================== if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) { chkDecimateTrace[ID]->setChecked( Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::DecimateTrace) ); chkDualTrace[ID]->setChecked( Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::DualTrace) ); @@ -3083,6 +3145,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ } } + ///========================================== if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) { chkDecimateTrace[ID]->setChecked( Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::DisableDigiTrace_PSD) ); int temp = Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::AnalogProbe1); @@ -3109,6 +3172,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ } } + ///========================================== if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) { int temp = Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::AnalogProbe1); for( int i = 0; i < cbAnaProbe1[ID]->count(); i++){ @@ -3126,6 +3190,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ } } } + //*======================================== uint32_t chMask = digi[ID]->GetSettingFromMemory(DPP::RegChannelEnableMask); for( int i = 0; i < digi[ID]->GetNumRegChannels(); i++){ @@ -3196,7 +3261,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ uint32_t glbTrgMask = digi[ID]->GetSettingFromMemory(DPP::GlobalTriggerMask); if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE || digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ){ - for( int i = 0; i < digi[ID]->GetNumRegChannels(); i++){ + for( int i = 0; i < digi[ID]->GetCoupledChannels(); i++){ if( (glbTrgMask >> i ) & 0x1 ){ bnGlobalTriggerMask[ID][i]->setStyleSheet("background-color: green;"); }else{ @@ -3211,7 +3276,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ //*======================================== uint32_t TRGOUTMask = digi[ID]->GetSettingFromMemory(DPP::FrontPanelTRGOUTEnableMask); - for( int i = 0; i < digi[ID]->GetNumRegChannels(); i++){ + for( int i = 0; i < digi[ID]->GetCoupledChannels(); i++){ if( (TRGOUTMask >> i ) & 0x1 ){ bnTRGOUTMask[ID][i]->setStyleSheet("background-color: green;"); }else{ @@ -3337,9 +3402,9 @@ void DigiSettingsPanel::SyncSpinBox(RSpinBox *(&spb)[][MaxRegChannel+1]){ spb[ID][nCh]->setValue( spb[ID][ch]->value()); }else{ //check is all SpinBox has same value; - int count = 1; + int count = 0; const int value = spb[ID][0]->value(); - for( int i = 1; i < nCh; i ++){ + for( int i = 0; i < nCh; i ++){ if( spb[ID][i]->value() == value ) count++; spb[ID][i]->setEnabled(bnChEnableMask[ID][i]->styleSheet() == "" ? false : true ); @@ -3370,9 +3435,9 @@ void DigiSettingsPanel::SyncComboBox(RComboBox *(&cb)[][MaxRegChannel+1]){ enableSignalSlot = true; }else{ //check is all SpinBox has same value; - int count = 1; + int count = 0; const QString text = cb[ID][0]->currentText(); - for( int i = 1; i < nCh; i ++){ + for( int i = 0; i < nCh; i ++){ if( cb[ID][i]->currentText() == text ) count++; cb[ID][i]->setEnabled(bnChEnableMask[ID][i]->styleSheet() == "" ? false : true ); } @@ -3399,9 +3464,9 @@ void DigiSettingsPanel::SyncCheckBox(QCheckBox *(&chk)[][MaxRegChannel+1]){ enableSignalSlot = true; }else{ //check is all SpinBox has same value; - int count = 1; + int count = 0; const Qt::CheckState state = chk[ID][0]->checkState(); - for( int i = 1; i < nCh; i ++){ + for( int i = 0; i < nCh; i ++){ if( chk[ID][i]->checkState() == state ) count++; chk[ID][i]->setEnabled(bnChEnableMask[ID][i]->styleSheet() == "" ? false : true ); } @@ -3710,33 +3775,55 @@ void DigiSettingsPanel::SyncAllChannelsTab_QDC(){ enableSignalSlot = false; sbSubChOffset[ID][nGrp][subCh]->setValue(sbSubChOffset[ID][grp][subCh]->value()); sbSubChThreshold[ID][nGrp][subCh]->setValue(sbSubChThreshold[ID][grp][subCh]->value()); + pbSubChMask[ID][nGrp][subCh]->setStyleSheet(pbSubChMask[ID][grp][subCh]->styleSheet()); }else{ - int count0 = 1; - int count1 = 1; + int count0 = 0; + int count1 = 0; + int count2 = 0; const int value0 = sbSubChOffset[ID][0][subCh]->value(); const int value1 = sbSubChThreshold[ID][0][subCh]->value(); - for( int i = 1; i < nGrp; i ++){ + const QString value2 = pbSubChMask[ID][0][subCh]->styleSheet(); + for( int i = 0; i < nGrp; i ++){ if( sbSubChOffset[ID][i][subCh]->value() == value0 ) count0++; if( sbSubChThreshold[ID][i][subCh]->value() == value1 ) count1++; - sbSubChOffset[ID][i][subCh]->setEnabled(bnChEnableMask[ID][i]->styleSheet() == "" ? false : true ); - sbSubChThreshold[ID][i][subCh]->setEnabled(bnChEnableMask[ID][i]->styleSheet() == "" ? false : true ); + if( pbSubChMask[ID][i][subCh]->styleSheet() == value2 ) count2++; + + if( bnChEnableMask[ID][i]->styleSheet() == "" ){ + + sbSubChOffset[ID][i][subCh]->setEnabled(false); + sbSubChThreshold[ID][i][subCh]->setEnabled(false); + + }else{ + + sbSubChOffset[ID][i][subCh]->setEnabled(pbSubChMask[ID][i][subCh]->styleSheet() == "" ? false : true ); + sbSubChThreshold[ID][i][subCh]->setEnabled(pbSubChMask[ID][i][subCh]->styleSheet() == "" ? false : true ); + + } + } - //printf("%d =? %d , %d, %f\n", count, nCh, value, spb[ID][0]->value()); + // printf("%d =? %d , %d, %f\n", count1, subCh, value1, sbSubChThreshold[ID][nGrp][subCh]->value()); enableSignalSlot = false; if( count0 != nGrp ){ sbSubChOffset[ID][nGrp][subCh]->setValue(-1); }else{ sbSubChOffset[ID][nGrp][subCh]->setValue(value0); } + if( count1 != nGrp ){ sbSubChThreshold[ID][nGrp][subCh]->setValue(-1); }else{ sbSubChThreshold[ID][nGrp][subCh]->setValue(value1); } + if( count2 != nGrp ){ + pbSubChMask[ID][nGrp][subCh]->setStyleSheet("background-color : brown;"); + }else{ + pbSubChMask[ID][nGrp][subCh]->setStyleSheet(value2); + } + } } @@ -3759,6 +3846,16 @@ void DigiSettingsPanel::UpdateSettings_QDC(){ UpdateSpinBox(sbGateOffset[ID][grp], DPP::QDC::GateOffset, grp); //UpdateSpinBox(sbOverThresholdWidth[ID][grp], DPP::QDC::OverThresholdWidth, grp); + uint32_t subChMask = digi[ID]->GetSettingFromMemory(DPP::QDC::SubChannelMask, grp); + + for( int i = 0; i < 8; i++) { + if( (subChMask >> i) & 0x1 ) { + pbSubChMask[ID][grp][i]->setStyleSheet("background-color : green;"); + }else{ + pbSubChMask[ID][grp][i]->setStyleSheet(""); + } + } + uint32_t dpp = digi[ID]->GetSettingFromMemory(DPP::QDC::DPPAlgorithmControl, grp); UpdateComboBoxBit(cbPolarity[ID][grp], dpp, DPP::QDC::Bit_DPPAlgorithmControl::Polarity); diff --git a/DigiSettingsPanel.h b/DigiSettingsPanel.h index c49031b..768c429 100644 --- a/DigiSettingsPanel.h +++ b/DigiSettingsPanel.h @@ -281,6 +281,7 @@ private: //QCheckBox * chkOverthreshold[MaxNDigitizer][MaxRegChannel+1]; //TODO need firmware version 4.25 & 135.17 //RSpinBox * sbOverThresholdWidth[MaxNDigitizer][MaxRegChannel + 1]; + QPushButton * pbSubChMask[MaxNDigitizer][MaxRegChannel+1][8]; RSpinBox * sbSubChOffset[MaxNDigitizer][MaxRegChannel + 1][8]; RSpinBox * sbSubChThreshold[MaxNDigitizer][MaxRegChannel + 1][8]; QLabel * lbSubCh[MaxNDigitizer][8]; diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 299f6be..838fb2c 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -1216,6 +1216,7 @@ void MainWindow::SetSyncMode(){ digi[i]->WriteRegister(DPP::AcquisitionControl, 0); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0); } + if( digiSettings && digiSettings->isVisible() ) digiSettings->UpdatePanelFromMemory(); dialog.accept(); }); @@ -1223,9 +1224,10 @@ void MainWindow::SetSyncMode(){ digi[0]->WriteRegister(DPP::AcquisitionControl, 0); digi[0]->WriteRegister(DPP::FrontPanelIOControl, 0x10000); //RUN for(unsigned int i = 1; i < nDigi; i++){ - digi[i]->WriteRegister(DPP::AcquisitionControl, 2); + digi[i]->WriteRegister(DPP::AcquisitionControl, 0x42); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0x10000); // S-IN } + if( digiSettings && digiSettings->isVisible() ) digiSettings->UpdatePanelFromMemory(); dialog.accept(); }); @@ -1233,17 +1235,19 @@ void MainWindow::SetSyncMode(){ digi[0]->WriteRegister(DPP::AcquisitionControl, 0); digi[0]->WriteRegister(DPP::FrontPanelIOControl, 0x10000); //RUN for(unsigned int i = 1; i < nDigi; i++){ - digi[i]->WriteRegister(DPP::AcquisitionControl, 1); + digi[i]->WriteRegister(DPP::AcquisitionControl, 0x41); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0x30000); // S-IN } + if( digiSettings && digiSettings->isVisible() ) digiSettings->UpdatePanelFromMemory(); dialog.accept(); }); connect(bnMethod3, &QPushButton::clicked, [&](){ for(unsigned int i = 0; i < nDigi; i++){ - digi[i]->WriteRegister(DPP::AcquisitionControl, 1); + digi[i]->WriteRegister(DPP::AcquisitionControl, 0x41); digi[i]->WriteRegister(DPP::FrontPanelIOControl, 0x30000); // S-IN } + if( digiSettings && digiSettings->isVisible() ) digiSettings->UpdatePanelFromMemory(); dialog.accept(); }); @@ -1507,6 +1511,7 @@ void MainWindow::UpdateAllPanels(int panelID){ if(scalar) { for( unsigned int iDigi = 0; iDigi < nDigi; iDigi++){ uint32_t chMask = digi[iDigi]->GetRegChannelMask(); + uint32_t subChMask = 0; for( int ch = 0; ch < digi[iDigi]->GetNumInputCh(); ch++){ // leTrigger[iDigi][i]->setEnabled( (chMask >> i) & 0x1 ); // leAccept[iDigi][i]->setEnabled( (chMask >> i) & 0x1 ); @@ -1518,7 +1523,18 @@ void MainWindow::UpdateAllPanels(int panelID){ int grpID = ch/digi[iDigi]->GetNumRegChannels(); leTrigger[iDigi][ch]->setEnabled( (chMask >> grpID) & 0x1 ); leAccept[iDigi][ch]->setEnabled( (chMask >> grpID) & 0x1 ); + + if( (chMask >> grpID ) & 0x1 ){ + + int subCh = ch%digi[iDigi]->GetNumRegChannels(); + if( subCh == 0 ) subChMask = digi[iDigi]->GetSettingFromMemory(DPP::QDC::SubChannelMask, grpID); + + leTrigger[iDigi][ch]->setEnabled( (subChMask >> subCh) & 0x1 ); + leAccept[iDigi][ch]->setEnabled( (subChMask >> subCh) & 0x1 ); + + } } + } } } diff --git a/README.md b/README.md index ee2fe07..76d5b86 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,6 @@ Those file can be compiled using * DC offset issue. When porgram default settings, the DC offset is not the same for all channels. * for PHA firmware, when the trigger average changed, the Events per Agg need to be changed. * Sometimes, the buffer is not in time order, and make the trigger/Accept rate to be nagative. This is nothing to do with the program but the digitizer settings. Recommand reporgram the digitizer. -* in 1740D, QDC, Record Length and Over Threshold WIdth cannot read from digitizer, although the register is correct. # Known Bugs diff --git a/RegisterAddress.h b/RegisterAddress.h index 43ad50d..ba8f223 100644 --- a/RegisterAddress.h +++ b/RegisterAddress.h @@ -798,7 +798,7 @@ namespace DPP { const Reg GroupStatus_R ("Group Status" , 0x1088, RW::ReadONLY, false, {}); /// R/ const Reg AMCFirmwareRevision_R ("AMC firmware version" , 0x108C, RW::ReadONLY, false, {}); /// R/ const Reg DCOffset ("DC offset" , 0x1098, RW::ReadWrite, false, 0xFFFF, -1); /// R/W - const Reg SubChannelMask ("SubChannel Mask" , 0x10A8, RW::ReadWrite, false, 0xFF, 1); /// R/W + const Reg SubChannelMask ("SubChannel Mask" , 0x10A8, RW::ReadWrite, false, 0xFF, -1); /// R/W const Reg DCOffset_LowCh ("DC offset for low ch." , 0x10C0, RW::ReadWrite, false, 0xFFFFFFFF, -1); /// R/W const Reg DCOffset_HighCh ("DC offset for high ch." , 0x10C4, RW::ReadWrite, false, 0xFFFFFFFF, -1); /// R/W const Reg TriggerThreshold_sub0 ("Trigger Threshold sub0" , 0x10D0, RW::ReadWrite, false, 0xFFF, -1); /// R/W @@ -811,8 +811,8 @@ namespace DPP { const Reg TriggerThreshold_sub7 ("Trigger Threshold sub7" , 0x10EC, RW::ReadWrite, false, 0xFFF, -1); /// R/W - const Reg NumberEventsPerAggregate ("Number of Events per Aggregate", 0x8020, RW::ReadWrite, false, 0x3FF, 1); /// R/W - const Reg GroupEnableMask ("Group Enable Mask" , 0x8120, RW::ReadWrite, false, 0xFF, 1); /// R/W + const Reg NumberEventsPerAggregate ("Number of Events per Aggregate", 0x8020, RW::ReadWrite, false, 0x3FF, -1); /// R/W + const Reg GroupEnableMask ("Group Enable Mask" , 0x8120, RW::ReadWrite, false, 0xFF, -1); /// R/W namespace Bit_DPPAlgorithmControl { const std::pair ChargeSensitivity = {3, 0} ; /// length, smallest pos diff --git a/Scope.cpp b/Scope.cpp index 9d1209e..9ccea4b 100644 --- a/Scope.cpp +++ b/Scope.cpp @@ -33,6 +33,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh dataTrace[1]->setPen(QPen(Qt::blue, 2)); dataTrace[2]->setPen(QPen(Qt::darkYellow, 1)); dataTrace[3]->setPen(QPen(Qt::darkGreen, 1)); + dataTrace[4]->setPen(QPen(Qt::darkMagenta, 1)); plot->setAnimationDuration(1); // msec plot->setAnimationOptions(QChart::NoAnimation); @@ -54,32 +55,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh updateTraceThread->SetWaitTimeinSec(ScopeUpdateMiliSec / 1000.); connect(updateTraceThread, &TimingThread::timeUp, this, &Scope::UpdateScope); - - sbReordLength = nullptr; - sbPreTrigger = nullptr; - sbDCOffset = nullptr; - cbDynamicRange = nullptr; - cbPolarity = nullptr; - - ///---- PHA - sbInputRiseTime = nullptr; - sbTriggerHoldOff = nullptr; - sbThreshold = nullptr; - cbSmoothingFactor = nullptr; - - sbTrapRiseTime = nullptr; - sbTrapFlatTop = nullptr; - sbDecayTime = nullptr; - sbPeakingTime = nullptr; - sbPeakHoldOff = nullptr; - - cbPeakAvg = nullptr; - cbBaselineAvg = nullptr; - - cbAnaProbe1 = nullptr; - cbAnaProbe2 = nullptr; - cbDigiProbe1 = nullptr; - cbDigiProbe2 = nullptr; + NullThePointers(); //*================================== UI int rowID = -1; @@ -123,8 +99,9 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh //---Setup SettingGroup CleanUpSettingsGroupBox(); - if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPHAPanel(); - if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPSDPanel(); + if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPanel_PHA(); + if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPanel_PSD(); + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) SetUpPanel_QDC(); ReadSettingsFromBoard(); @@ -171,8 +148,9 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh settingLayout = new QGridLayout(settingGroup); settingLayout->setSpacing(0); - if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPHAPanel(); - if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPSDPanel(); + if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPanel_PHA(); + if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPanel_PSD(); + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) SetUpPanel_QDC(); } //================ Plot view @@ -240,6 +218,10 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh QValueAxis * yaxis = qobject_cast (plot->axes(Qt::Vertical).first()); yaxis->setRange(0, 0x3FFF); } + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) { + QValueAxis * yaxis = qobject_cast (plot->axes(Qt::Vertical).first()); + yaxis->setRange(0, 0xFFF); + } enableSignalSlot = true; @@ -256,6 +238,40 @@ Scope::~Scope(){ delete plot; } +void Scope::NullThePointers(){ + + sbReordLength = nullptr; + sbPreTrigger = nullptr; + sbDCOffset = nullptr; + cbDynamicRange = nullptr; + cbPolarity = nullptr; + + /// PHA + sbInputRiseTime = nullptr; + sbTriggerHoldOff = nullptr; + sbThreshold = nullptr; + cbSmoothingFactor = nullptr; + + sbTrapRiseTime = nullptr; + sbTrapFlatTop = nullptr; + sbDecayTime = nullptr; + sbPeakingTime = nullptr; + sbPeakHoldOff = nullptr; + cbPeakAvg = nullptr; + cbBaselineAvg = nullptr; + + cbAnaProbe1 = nullptr; + cbAnaProbe2 = nullptr; + cbDigiProbe1 = nullptr; + cbDigiProbe2 = nullptr; + + /// PSD + sbShortGate = nullptr; + sbLongGate = nullptr; + sbGateOffset = nullptr; + +} + //*======================================================= //*======================================================= void Scope::StartScope(){ @@ -345,7 +361,7 @@ void Scope::UpdateScope(){ if( digi[ID]->GetInputChannelOnOff(ch) == false) return; - // printf("### %d %d \n", ch, digi[ID]->GetData()->DataIndex[ch]); + //printf("### %d %d \n", ch, digi[ID]->GetData()->DataIndex[ch]); digiMTX[ID].lock(); Data * data = digi[ID]->GetData(); @@ -362,7 +378,7 @@ void Scope::UpdateScope(){ // printf("--- %s| %d, %d, %d | %d | %d, %d\n", __func__, ch, data->LoopIndex[ch], index, traceLength, factor, tick2ns ); if( data->TriggerRate[ch] > 0 ){ - QVector points[4]; + QVector points[5]; if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) { for( int i = 0; i < traceLength ; i++ ) { points[0].append(QPointF(tick2ns * i * factor, (data->Waveform1[ch][index])[i])); @@ -370,6 +386,10 @@ void Scope::UpdateScope(){ if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(tick2ns * i * factor, (data->DigiWaveform1[ch][index])[i] * 1000)); if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(tick2ns * i * factor, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); } + dataTrace[0]->replace(points[0]); + dataTrace[1]->replace(points[1]); + dataTrace[2]->replace(points[2]); + dataTrace[3]->replace(points[3]); } if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) { @@ -379,11 +399,26 @@ void Scope::UpdateScope(){ if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(tick2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000)); if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(tick2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); } + dataTrace[0]->replace(points[0]); + dataTrace[1]->replace(points[1]); + dataTrace[2]->replace(points[2]); + dataTrace[3]->replace(points[3]); + } + + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) { + for( int i = 0; i < traceLength ; i++ ) { + points[0].append(QPointF(tick2ns * i * factor, (data->Waveform1[ch][index])[i])); + if( i < (int) data->DigiWaveform1[ch][index].size() ) points[1].append(QPointF(tick2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000)); + if( i < (int) data->DigiWaveform2[ch][index].size() ) points[2].append(QPointF(tick2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500)); + if( i < (int) data->DigiWaveform3[ch][index].size() ) points[3].append(QPointF(tick2ns * i, (data->DigiWaveform3[ch][index])[i] * 1000 + 1000)); + if( i < (int) data->DigiWaveform4[ch][index].size() ) points[4].append(QPointF(tick2ns * i, (data->DigiWaveform4[ch][index])[i] * 1000 + 1500)); + } + dataTrace[0]->replace(points[0]); + dataTrace[1]->replace(points[1]); + dataTrace[2]->replace(points[2]); + dataTrace[3]->replace(points[3]); + dataTrace[4]->replace(points[4]); } - dataTrace[0]->replace(points[0]); - dataTrace[1]->replace(points[1]); - dataTrace[2]->replace(points[2]); - dataTrace[3]->replace(points[3]); } digiMTX[ID].unlock(); @@ -392,6 +427,7 @@ void Scope::UpdateScope(){ dataTrace[1]->clear(); dataTrace[2]->clear(); dataTrace[3]->clear(); + dataTrace[4]->clear(); } plot->axes(Qt::Horizontal).first()->setRange(0, tick2ns * traceLength * factor); @@ -425,9 +461,21 @@ void Scope::SetUpComboBox(RComboBox * &cb, QString str, int row, int col, const int ch = cbScopeCh->currentIndex(); int value = cb->currentData().toInt(); - digiMTX[ID].lock(); - digi[ID]->WriteRegister(para, value, ch); - digiMTX[ID].unlock(); + + if( digi[ID]->GetDPPType() == DPPType::DPP_QDC_CODE ) { + int grp = ch/8; // convert ch to grp + + digiMTX[ID].lock(); + digi[ID]->WriteRegister(para, value, grp); + digiMTX[ID].unlock(); + + }else{ + + digiMTX[ID].lock(); + digi[ID]->WriteRegister(para, value, ch); + digiMTX[ID].unlock(); + + } QString msg; msg = QString::fromStdString(para.GetName()) ; @@ -488,7 +536,7 @@ void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Re value = value * factor; } - if( para == DPP::ChannelDCOffset ){ + if( para == DPP::ChannelDCOffset || para == DPP::QDC::DCOffset){ value = uint16_t((1.0 - sb->value()/100.) * 0xFFFF); } @@ -498,10 +546,17 @@ void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Re msg += " | 0x" + QString::number(value, 16); - digiMTX[ID].lock(); - digi[ID]->WriteRegister(para, value, ch); + if( digi[ID]->GetDPPType() == DPPType::DPP_QDC_CODE ){ + int grp = ch/8; // convert ch to grp + digiMTX[ID].lock(); + digi[ID]->WriteRegister(para, value, grp); + digiMTX[ID].unlock(); + }else{ + digiMTX[ID].lock(); + digi[ID]->WriteRegister(para, value, ch); + digiMTX[ID].unlock(); + } - digiMTX[ID].unlock(); if( digi[ID]->GetErrorCode() == CAEN_DGTZ_Success ){ SendLogMsg(msg + " | OK."); sb->setStyleSheet(""); @@ -524,9 +579,11 @@ void Scope::CleanUpSettingsGroupBox(){ QList labelChildren3 = settingGroup->findChildren(); for( int i = 0; i < labelChildren3.size(); i++) delete labelChildren3[i]; + NullThePointers(); + } -void Scope::SetUpPHAPanel(){ +void Scope::SetUpPanel_PHA(){ printf("--- %s \n", __func__); enableSignalSlot = false; @@ -627,7 +684,7 @@ void Scope::SetUpPHAPanel(){ } -void Scope::SetUpPSDPanel(){ +void Scope::SetUpPanel_PSD(){ enableSignalSlot = false; printf("==== %s \n", __func__); @@ -646,7 +703,7 @@ void Scope::SetUpPSDPanel(){ cbPolarity->addItem("Negative", 1); connect(cbPolarity, &RComboBox::currentIndexChanged, this, [=](){ if( !enableSignalSlot ) return; - digi[ID]->SetBits(DPP::DPPAlgorithmControl, DPP::Bit_DPPAlgorithmControl_PHA::Polarity, cbPolarity->currentData().toInt(), cbScopeCh->currentIndex()); + digi[ID]->SetBits(DPP::DPPAlgorithmControl, DPP::Bit_DPPAlgorithmControl_PSD::Polarity, cbPolarity->currentData().toInt(), cbScopeCh->currentIndex()); }); SetUpSpinBox(sbShortGate, "Short Gate [ns] ", rowID, 2, DPP::PSD::ShortGateWidth); @@ -697,6 +754,106 @@ void Scope::SetUpPSDPanel(){ enableSignalSlot = true; } +void Scope::SetUpPanel_QDC() { + + enableSignalSlot = false; + printf("==== %s \n", __func__); + + int rowID = 0; + SetUpSpinBox(sbReordLength, "Record Length [ns] ", rowID, 0, DPP::QDC::RecordLength); + SetUpSpinBox(sbPreTrigger, "Pre Trigger [ns] ", rowID, 2, DPP::QDC::PreTrigger); + SetUpSpinBox(sbDCOffset, "DC offset [%] ", rowID, 4, DPP::QDC::DCOffset); + sbDCOffset->setDecimals(2); + + SetUpComboBoxSimple(cbPolarity, "Polarity ", rowID, 6); + cbPolarity->addItem("Positive", 0); + cbPolarity->addItem("Negative", 1); + connect(cbPolarity, &RComboBox::currentIndexChanged, this, [=](){ + if( !enableSignalSlot ) return; + digi[ID]->SetBits(DPP::QDC::DPPAlgorithmControl, DPP::QDC::Bit_DPPAlgorithmControl::Polarity, cbPolarity->currentData().toInt(), cbScopeCh->currentIndex()); + }); + + rowID ++; //============================================================= + SetUpSpinBox(sbShortGate, "Gate Width [ns] ", rowID, 0, DPP::QDC::GateWidth); + SetUpSpinBox(sbGateOffset, "Gate Offset [ns] ", rowID, 2, DPP::QDC::GateOffset); + + + QLabel * lb = new QLabel("Threshold [LSB]", settingGroup); + lb->setAlignment(Qt::AlignRight | Qt::AlignCenter); + settingLayout->addWidget(lb, rowID, 4); + + sbThreshold = new RSpinBox(settingGroup); + settingLayout->addWidget(sbThreshold, rowID, 5); + + sbThreshold->setMinimum(0); + sbThreshold->setMaximum(0xFFF); + sbThreshold->setSingleStep(1); + + connect(sbThreshold, &RSpinBox::valueChanged, this, [=](){ + if( !enableSignalSlot ) return; + sbThreshold->setStyleSheet("color : blue;"); + }); + + connect(sbThreshold, &RSpinBox::returnPressed, this, [=](){ + if( !enableSignalSlot ) return; + + uint32_t value = sbThreshold->value(); + sbThreshold->setStyleSheet(""); + + int ch = cbScopeCh->currentIndex(); + + int grp = ch/8; + int subCh = ch%8; + + Reg para = DPP::QDC::TriggerThreshold_sub0; + + digiMTX[ID].lock(); + switch(subCh){ + case 0: para = DPP::QDC::TriggerThreshold_sub0; break; + case 1: para = DPP::QDC::TriggerThreshold_sub1; break; + case 2: para = DPP::QDC::TriggerThreshold_sub2; break; + case 3: para = DPP::QDC::TriggerThreshold_sub3; break; + case 4: para = DPP::QDC::TriggerThreshold_sub4; break; + case 5: para = DPP::QDC::TriggerThreshold_sub5; break; + case 6: para = DPP::QDC::TriggerThreshold_sub6; break; + case 7: para = DPP::QDC::TriggerThreshold_sub7; break; + } + digiMTX[ID].unlock(); + + QString msg; + msg = QString::fromStdString(para.GetName()) + "|DIG:"+ QString::number(digi[ID]->GetSerialNumber()) + ",CH:" + (ch == -1 ? "All" : QString::number(ch)); + msg += " = " + QString::number(sbThreshold->value()); + msg += " | 0x" + QString::number(value, 16); + + digi[ID]->WriteRegister(para, value, grp); + + if( digi[ID]->GetErrorCode() == CAEN_DGTZ_Success ){ + SendLogMsg(msg + " | OK."); + sbThreshold->setStyleSheet(""); + emit UpdateOtherPanels(); + }else{ + SendLogMsg(msg + " | Fail."); + sbThreshold->setStyleSheet("color:red;"); + } + + }); + + rowID ++; //============================================================= + SetUpComboBoxSimple(cbAnaProbe1, "Ana. Probe ", rowID, 0); + for( int i = 0; i < (int) DPP::Bit_BoardConfig::ListAnaProbe_QDC.size(); i++){ + cbAnaProbe1->addItem(QString::fromStdString(DPP::Bit_BoardConfig::ListAnaProbe_QDC[i].first), DPP::Bit_BoardConfig::ListAnaProbe_QDC[i].second); + } + connect(cbAnaProbe1, &RComboBox::currentIndexChanged, this, [=](){ + if( !enableSignalSlot ) return; + digi[ID]->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::AnalogProbe1, cbAnaProbe1->currentData().toInt(), cbScopeCh->currentIndex()); + //dataTrace[0]->setName(cbAnaProbe1->currentText()); + + }); + + enableSignalSlot = true; + +} + void Scope::EnableControl(bool enable){ if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ){ @@ -732,7 +889,13 @@ void Scope::UpdateComobox(RComboBox * &cb, const Reg para){ int ch = cbScopeCh->currentIndex(); enableSignalSlot = false; - int haha = digi[ID]->GetSettingFromMemory(para, ch); + int haha = -99; + + if( digi[ID]->GetDPPType() == DPPType::DPP_QDC_CODE ){ + haha = digi[ID]->GetSettingFromMemory(para, ch/8); + }else{ + haha = digi[ID]->GetSettingFromMemory(para, ch); + } for( int i = 0; i < cb->count(); i++){ int kaka = cb->itemData(i).toInt(); @@ -748,6 +911,8 @@ void Scope::UpdateComobox(RComboBox * &cb, const Reg para){ void Scope::UpdateSpinBox(RSpinBox * &sb, const Reg para){ int ch = cbScopeCh->currentIndex(); + if( digi[ID]->GetDPPType() == DPPType::DPP_QDC_CODE ) ch = ch /8; + enableSignalSlot = false; unsigned int haha = digi[ID]->GetSettingFromMemory(para, ch); @@ -764,29 +929,15 @@ void Scope::UpdatePanelFromMomeory(){ int ch = cbScopeCh->currentIndex(); - unsigned int haha = digi[ID]->GetSettingFromMemory(DPP::RecordLength_G, ch); - sbReordLength->setValue(haha * DPP::RecordLength_G.GetPartialStep() * tick2ns); - - // if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ){ - // int factor = digi[ID]->IsDualTrace() ? 2 : 1; // if dual trace, - // sbReordLength->setValue(haha * DPP::RecordLength_G.GetPartialStep() * tick2ns / factor); - // }else{ - // } - - haha = digi[ID]->GetSettingFromMemory(DPP::ChannelDCOffset, ch); - sbDCOffset->setValue((1.0 - haha * 1.0 / 0xFFFF) * 100 ); - - UpdateComobox(cbDynamicRange, DPP::InputDynamicRange); - UpdateSpinBox(sbPreTrigger, DPP::PreTrigger); - - if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) UpdatePHAPanel(); - if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) UpdatePSDPanel(); + if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) UpdatePanel_PHA(); + if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) UpdatePanel_PSD(); + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) UpdatePanel_QDC(); settingGroup->setEnabled(digi[ID]->GetInputChannelOnOff(ch)); } -void Scope::UpdatePHAPanel(){ +void Scope::UpdatePanel_PHA(){ enableSignalSlot = false; int ch = cbScopeCh->currentIndex(); @@ -798,6 +949,15 @@ void Scope::UpdatePHAPanel(){ cbPolarity->setCurrentIndex(0); } + unsigned int haha = digi[ID]->GetSettingFromMemory(DPP::RecordLength_G, ch); + sbReordLength->setValue(haha * DPP::RecordLength_G.GetPartialStep() * tick2ns); + + haha = digi[ID]->GetSettingFromMemory(DPP::ChannelDCOffset, ch); + sbDCOffset->setValue((1.0 - haha * 1.0 / 0xFFFF) * 100 ); + + UpdateComobox(cbDynamicRange, DPP::InputDynamicRange); + UpdateSpinBox(sbPreTrigger, DPP::PreTrigger); + UpdateSpinBox(sbInputRiseTime, DPP::PHA::InputRiseTime); UpdateSpinBox(sbThreshold, DPP::PHA::TriggerThreshold); UpdateSpinBox(sbTriggerHoldOff, DPP::PHA::TriggerHoldOffWidth); @@ -855,7 +1015,7 @@ void Scope::UpdatePHAPanel(){ enableSignalSlot = true; } -void Scope::UpdatePSDPanel(){ +void Scope::UpdatePanel_PSD(){ enableSignalSlot = false; printf("==== %s \n", __func__); @@ -869,6 +1029,15 @@ void Scope::UpdatePSDPanel(){ cbPolarity->setCurrentIndex(0); } + unsigned int haha = digi[ID]->GetSettingFromMemory(DPP::RecordLength_G, ch); + sbReordLength->setValue(haha * DPP::RecordLength_G.GetPartialStep() * tick2ns); + + haha = digi[ID]->GetSettingFromMemory(DPP::ChannelDCOffset, ch); + sbDCOffset->setValue((1.0 - haha * 1.0 / 0xFFFF) * 100 ); + + UpdateComobox(cbDynamicRange, DPP::InputDynamicRange); + UpdateSpinBox(sbPreTrigger, DPP::PreTrigger); + UpdateSpinBox(sbShortGate, DPP::PSD::ShortGateWidth); UpdateSpinBox(sbLongGate, DPP::PSD::LongGateWidth); UpdateSpinBox(sbGateOffset, DPP::PSD::GateOffset); @@ -903,18 +1072,61 @@ void Scope::UpdatePSDPanel(){ enableSignalSlot = true; } -void Scope::ReadSettingsFromBoard(){ +void Scope::UpdatePanel_QDC(){ + enableSignalSlot = false; + + printf("==== %s \n", __func__); int ch = cbScopeCh->currentIndex(); - digi[ID]->ReadRegister(DPP::RecordLength_G, ch); - digi[ID]->ReadRegister(DPP::PreTrigger, ch); - digi[ID]->ReadRegister(DPP::ChannelDCOffset, ch); - digi[ID]->ReadRegister(DPP::InputDynamicRange, ch); - digi[ID]->ReadRegister(DPP::BoardConfiguration, ch); - digi[ID]->ReadRegister(DPP::DPPAlgorithmControl, ch); + int grp = ch/8; + + uint32_t DPPAlg = digi[ID]->GetSettingFromMemory(DPP::QDC::DPPAlgorithmControl, grp); + if( Digitizer::ExtractBits(DPPAlg, DPP::QDC::Bit_DPPAlgorithmControl::Polarity) ){ + cbPolarity->setCurrentIndex(1); + }else{ + cbPolarity->setCurrentIndex(0); + } + + uint32_t haha = digi[ID]->GetSettingFromMemory(DPP::QDC::DCOffset, grp); + sbDCOffset->setValue((1.0 - haha * 1.0 / 0xFFFF) * 100 ); + + UpdateSpinBox(sbReordLength, DPP::QDC::RecordLength); + UpdateSpinBox(sbPreTrigger, DPP::QDC::PreTrigger); + + + UpdateSpinBox(sbShortGate, DPP::QDC::GateWidth); + UpdateSpinBox(sbGateOffset, DPP::QDC::GateOffset); + + + + uint32_t BdCfg = digi[ID]->GetSettingFromMemory(DPP::BoardConfiguration, 0); + + int temp = Digitizer::ExtractBits(BdCfg, DPP::Bit_BoardConfig::AnalogProbe1); + for( int i = 0; i < cbAnaProbe1->count(); i++){ + if( cbAnaProbe1->itemData(i).toInt() == temp ) { + cbAnaProbe1->setCurrentIndex(i); + dataTrace[0]->setName(cbAnaProbe1->currentText()); + break; + } + } + + enableSignalSlot = true; +} + +void Scope::ReadSettingsFromBoard(){ + + digi[ID]->ReadRegister(DPP::BoardConfiguration); if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ){ + int ch = cbScopeCh->currentIndex(); + + digi[ID]->ReadRegister(DPP::RecordLength_G, ch); + digi[ID]->ReadRegister(DPP::PreTrigger, ch); + digi[ID]->ReadRegister(DPP::ChannelDCOffset, ch); + digi[ID]->ReadRegister(DPP::InputDynamicRange, ch); + digi[ID]->ReadRegister(DPP::BoardConfiguration, ch); + digi[ID]->ReadRegister(DPP::DPPAlgorithmControl, ch); digi[ID]->ReadRegister(DPP::PHA::InputRiseTime, ch); digi[ID]->ReadRegister(DPP::PHA::TriggerThreshold, ch); @@ -923,14 +1135,43 @@ void Scope::ReadSettingsFromBoard(){ digi[ID]->ReadRegister(DPP::PHA::TrapezoidFlatTop, ch); digi[ID]->ReadRegister(DPP::PHA::DecayTime, ch); digi[ID]->ReadRegister(DPP::PHA::PeakingTime, ch); - } if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE){ + int ch = cbScopeCh->currentIndex(); + + digi[ID]->ReadRegister(DPP::RecordLength_G, ch); + digi[ID]->ReadRegister(DPP::PreTrigger, ch); + digi[ID]->ReadRegister(DPP::ChannelDCOffset, ch); + digi[ID]->ReadRegister(DPP::InputDynamicRange, ch); + digi[ID]->ReadRegister(DPP::BoardConfiguration, ch); + digi[ID]->ReadRegister(DPP::DPPAlgorithmControl, ch); digi[ID]->ReadRegister(DPP::PSD::ShortGateWidth); digi[ID]->ReadRegister(DPP::PSD::LongGateWidth); digi[ID]->ReadRegister(DPP::PSD::GateOffset); + } + + if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE){ + int ch = cbScopeCh->currentIndex(); + int grp = ch/8; + + digi[ID]->ReadRegister(DPP::QDC::RecordLength, grp); + digi[ID]->ReadRegister(DPP::QDC::PreTrigger, grp); + digi[ID]->ReadRegister(DPP::QDC::DCOffset, grp); + digi[ID]->ReadRegister(DPP::QDC::DPPAlgorithmControl, grp); + + digi[ID]->ReadRegister(DPP::QDC::GateOffset, grp); + digi[ID]->ReadRegister(DPP::QDC::GateWidth, grp); + + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub0, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub1, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub2, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub3, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub4, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub5, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub6, grp); + digi[ID]->ReadRegister(DPP::QDC::TriggerThreshold_sub7, grp); } diff --git a/Scope.h b/Scope.h index bd0cdd4..36a4324 100644 --- a/Scope.h +++ b/Scope.h @@ -59,14 +59,18 @@ private: void SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Reg para); void CleanUpSettingsGroupBox(); - void SetUpPHAPanel(); - void SetUpPSDPanel(); + void SetUpPanel_PHA(); + void SetUpPanel_PSD(); + void SetUpPanel_QDC(); void EnableControl(bool enable); void UpdateComobox(RComboBox * &cb, const Reg para); void UpdateSpinBox(RSpinBox * &sb, const Reg para); - void UpdatePHAPanel(); - void UpdatePSDPanel(); + void UpdatePanel_PHA(); + void UpdatePanel_PSD(); + void UpdatePanel_QDC(); + + void NullThePointers(); Digitizer ** digi; unsigned short nDigi; @@ -83,7 +87,7 @@ private: RChart * plot; RChartView * plotView; - QLineSeries * dataTrace[MaxNumberOfTrace]; // 2 analog, 2 digi + QLineSeries * dataTrace[MaxNumberOfTrace]; // 2 analog, 2 digi for PHA, PSD, 1 analog, 4 digi for QDC RComboBox * cbScopeDigi; RComboBox * cbScopeCh; @@ -128,6 +132,11 @@ private: RSpinBox * sbLongGate; RSpinBox * sbGateOffset; + /// QDC + //sbShortGate -> GateWidth + //sbGateOffset -> GateOffset + //sbTriggerHoldOff ->Trigger Hold Off + }; diff --git a/macro.h b/macro.h index 1558311..8a270ca 100644 --- a/macro.h +++ b/macro.h @@ -13,7 +13,7 @@ #define MaxDisplayTraceDataLength 1250 //data point, #define ScopeUpdateMiliSec 200 // msec -#define MaxNumberOfTrace 4 // in an event +#define MaxNumberOfTrace 5 // in an event #define SETTINGSIZE 2048 diff --git a/test.cpp b/test.cpp index 6ab460a..a756757 100644 --- a/test.cpp +++ b/test.cpp @@ -26,16 +26,55 @@ int getch(void); //^====================================== int main(int argc, char* argv[]){ + Digitizer * digi = new Digitizer(0, 0, false, true); + digi->Reset(); + digi->ProgramBoard_PHA(); + + for( int ch = 0; ch < 16; ch++){ + printf("%2d | 0x%X \n", ch, digi->GetSettingFromMemory(DPP::ChannelDCOffset, ch)); + } + + //digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); + + // Data * data = digi->GetData(); + + // digi->StartACQ(); + + // for( int i = 0; i < 4; i ++ ){ + // usleep(1000*1000); + // digi->ReadData(); + // data->DecodeBuffer(false, 100); + // data->PrintStat(); + + // //data->SaveData(); + + // // int index = data->NumEventsDecoded[0]; + // // printf("-------------- %ld \n", data->Waveform1[0][index].size()); + + // //data->PrintAllData(); + + // } + + // digi->StopACQ(); + + + + digi->CloseDigitizer(); + delete digi; + + + + /********************** DPP-PHA Digitizer * digi = new Digitizer(0, 2, false, true); digi->Reset(); digi->WriteRegister(DPP::SoftwareClear_W, 1); digi->WriteRegister(DPP::QDC::RecordLength, 6000/16, -1); - digi->WriteRegister(DPP::QDC::GateWidth, 100/16, -1); + digi->WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1); + digi->WriteRegister(DPP::QDC::GateWidth, 200/16, -1); digi->WriteRegister(DPP::QDC::GateOffset, 0, -1); digi->WriteRegister(DPP::QDC::FixedBaseline, 0, -1); - digi->WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1); //digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse digi->WriteRegister(DPP::QDC::TriggerHoldOffWidth, 100/16, -1); @@ -44,19 +83,19 @@ int main(int argc, char* argv[]){ //digi->WriteRegister(DPP::QDC::DCOffset, 100/16, -1); digi->WriteRegister(DPP::QDC::SubChannelMask, 0xFF, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub0, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub1, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub3, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub4, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub5, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub6, 100, -1); - digi->WriteRegister(DPP::QDC::TriggerThreshold_sub7, 100, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub0, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub1, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub2, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub3, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub4, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub5, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub6, 10, -1); + digi->WriteRegister(DPP::QDC::TriggerThreshold_sub7, 10, -1); digi->WriteRegister(DPP::BoardConfiguration, 0xC0110); - digi->WriteRegister(DPP::AggregateOrganization, 0x0); - digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x7FF); + digi->WriteRegister(DPP::AggregateOrganization, 0x1); + digi->WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x4); digi->WriteRegister(DPP::AcquisitionControl, 0x0); digi->WriteRegister(DPP::GlobalTriggerMask, 0x0); digi->WriteRegister(DPP::FrontPanelTRGOUTEnableMask, 0x0); @@ -65,7 +104,7 @@ int main(int argc, char* argv[]){ digi->WriteRegister(DPP::MaxAggregatePerBlockTransfer, 0x3FF); - digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112, 0); // with pulse for grp 0 + //digi->WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112, 0); // with pulse for grp 0 digi->WriteRegister(DPP::BoardID, 0x7);