![]() | ![]() | ![]() | Initialize | ![]() |
The initialization function must prepare the hardware to be accessed and perform any one-time initialization. In our case, the Philips ADC/TDC will be set up:
/*!
Initialize the modules.
The crate must be held inhibited while the modules are initialized
or else gates can make them busy at which point they'll ignore programming
requests.
*/
void MyEventSegment::Initialize()
{
branchinit(m_nB); // Ensure the branch is initialized.
inhibit(m_nB, m_nC); // Hold the crate inhibited.
InitTdc(1, 100, 50, 50);
InitAdc(2, 50, 25, 25);
uninhibit(m_nB, m_nC);
}
Using helper functions (InitTdc and InitAdc) keeps the code uncluttered and easy to understand. In addition, breaking the code down into these small functions helps keep the complexity of a real experiment under control. For a larger experiment, you may even want to make a class out of the digitizers themselves. This has been done for many of the standard electroncis modules.
The implementation of InitTdc and InitAdc are shown below.
/*!
Initialize a TDC.
Clear the module, set the command register and set the
parameters from the common levels passed in.
\param vsn - The virtual slot number to program in the tdc.
\param pedestal - Common pedestal value for all channels.
\param lld - Common low level discriminator value for all channels.
\param uld - Common upper level discriminator value for all channels.
*/
void
MyEventSegment::InitTdc(int vsn, int pedestal, int lld, int uld)
{
camctl(m_nB, m_nC, m_nTdc, 0, 9); // Clear
camwrite16(m_nB, m_nC, m_nTdc, 0, 23, 0xffff); // clear ctl reg bits.
camwrite16(m_nB, m_nC, m_nTdc, 0, 19, 7); // Enable pedestals & thresholds
// Pedestals
camwrite16(m_nB, m_nC, m_nTdc, 0, 17, 0); // Select pedestal memory
for(int i =0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nTdc, i, 20, pedestal);
}
// ULD:
camwrite16(m_nB, m_nC, m_nTdc, 1, 17, 0); // Select lower level disc.
for(int i = 0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nTdc, i, 20, lld);
}
// LLD
camwrite16(m_nB, m_nC, m_nTdc, 2, 17, 0); // Select upper level disc.
for(int i = 0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nTdc, i, 20, uld);
}
}
/*!
Initialize the adc:
*/
void
MyEventSegment::InitAdc(int vsn, int pedestal, int lld, int uld)
{
camctl(m_nB, m_nC, m_nAdc, 0, 9); // Clear
camwrite16(m_nB, m_nC, m_nAdc, 0, 23, 0xffff); // clear ctl reg bits.
camwrite16(m_nB, m_nC, m_nAdc, 0, 19, 7); // Enable pedestals & thresholds
// Pedestals
camwrite16(m_nB, m_nC, m_nAdc, 0, 17, 0); // Select pedestal memory
for(int i =0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nAdc, i, 20, pedestal);
}
// ULD:
camwrite16(m_nB, m_nC, m_nAdc, 1, 17, 0); // Select lower level disc.
for(int i = 0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nAdc, i, 20, lld);
}
// LLD
camwrite16(m_nB, m_nC, m_nAdc, 2, 17, 0); // Select upper level disc.
for(int i = 0; i < 15; i++) {
camwrite16(m_nB, m_nC, m_nAdc, i, 20, uld);
}
}
![]() | ![]() | ![]() | Initialize | ![]() |