doubleTriggerBurstRandomSequence.cxx

00001 {
00002 printf("starting double trigger burst random sequence\n");
00003 
00004 const int length=150;
00005 const unsigned long ntrigs=100000;
00006 
00007 int* ttrigs = new int[length];
00008 printf ("allocated ttrigs[%d]\n",length);
00009 
00010 for (int i=0; i<length; ++i){
00011   ttrigs[i]=0;
00012 }
00013 
00014 // add a couple of L1As:
00015 ttrigs[0]=0x01;
00016 ttrigs[130]=0x01;
00017 // sequence end
00018 
00019 
00020 // reset sequence control - need to do this before loading the sequence
00021 tapi.timRegLoad(0x1a,0x0200);
00022 tapi.timRegLoad(0x1a,0x0);
00023 
00024 // load the sequence
00025 tapi.timRegLoad(0x1C,length-1);
00026 for (int i=0; i<length; ++i){
00027   tapi.timRegLoad(0x8000 + i*2, ttrigs[i]);
00028   int in = tapi.timReadRegister(0x8000 + i*2);
00029   //printf("in[%d]=0x%x (%x)\n",i,in,trigs[i]);
00030 }
00031 
00032 // L1 counters
00033 tapi.timRegLoad(0x12,0x0); 
00034 tapi.timRegLoad(0x10,0x0);
00035 
00036 // set the burst counter
00037 tapi.timRegLoad(0x04, (ntrigs & 0xffff ) );
00038 tapi.timRegLoad(0x8e, (ntrigs >> 16) );
00039 
00040 // set burst mode
00041 tapi.timRegLoad(0x02,0x200);
00042 
00043 // trigger, go, non-cyclic
00044 tapi.timRegLoad(0x1a,0x0401);
00045 // set triggers to act as SeqGo
00046 tapi.timRegLoad(0x42,0x100);
00047   
00048 // Set up internal random trigger source
00049 tapi.timRegLoad(0x00, 0x12); 
00050 
00051 // set frequency to 50kHz
00052 tapi.timRegLoad(0x02,0x600);
00053 
00054 unsigned long l1id=0;
00055 unsigned long poll=0;
00056 unsigned long unchanged_polls=0;
00057 bool stalled=false;
00058 unsigned long lastl1id=-1;
00059 do{
00060   poll++;
00061   l1id = ((tapi.timReadRegister(0x12)<<16) + (tapi.timReadRegister(0x10)));
00062 
00063   //intermittent diagnostics
00064   if (poll%(ntrigs/10)==0){
00065     printf("%d of %d sent \n",l1id,ntrigs,lastl1id);
00066 
00067     // check if l1id has stopped increasing
00068     if (l1id==lastl1id) {
00069       unchanged_polls++;
00070       if (unchanged_polls>10) stalled=true;
00071     }else{
00072       unchanged_polls=0;
00073     }
00074   }
00075   lastl1id=l1id;
00076 } while (l1id<ntrigs && !stalled);
00077 
00078 if (stalled) printf("stalled\n");
00079 const bool incomplete=(l1id!=ntrigs);
00080 if (incomplete){
00081   printf("Incorrect number of triggers sent - %d rather than %d\n",l1id,ntrigs);
00082 }
00083 
00084 if (incomplete || stalled || true) {
00085   for (unsigned reg=0; reg<0x1F; ++reg){
00086      printf ("reg 0x%x=0x%x\t",reg,tapi.timReadRegister(reg));
00087      if (reg%4==0) printf("\n");
00088   }
00089   printf("\n\n");
00090 }
00091 
00092 // stop the sequence, reset other registers
00093 tapi.timRegLoad(0x1a,0x0);
00094 tapi.timRegLoad(0x02,0x0);
00095 tapi.timRegLoad(0x04,0x0);
00096 tapi.timRegLoad(0x8e,0x0);
00097 tapi.timRegLoad(0x00,0x0);
00098 tapi.timRegLoad(0x02,0x0);
00099 
00100 unsigned outl1id = tapi.timReadRegister(0x10) + (tapi.timReadRegister(0x12)<<16);
00101 printf("number of l1ids sent was %d \n\n",outl1id);
00102 
00103 
00104 for (int i=0; i<length; ++i){
00105   int out = tapi.timReadRegister(0x8000 + i*2);
00106   if (out==0){
00107     printf(".");
00108   }else if (out==0xffff){
00109     printf("x");
00110   }else{
00111     printf("\nOutput[%d]=0x%x\n",i,out);
00112   }
00113 }
00114 printf("\n");
00115 
00116 delete[] ttrigs;
00117 
00118 } // end of macro
00119 
00120 

Generated on Mon Feb 6 14:01:19 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6