ps7106.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         ps7106.c
00004   Created by:   Stefan Ritt
00005 
00006   Cotents:      Routines for accessing Phillips Scientific
00007                 7106 discriminators
00008 
00009 
00010   Revision history
00011   ------------------------------------------------------------------
00012   date        by    modification
00013   ---------   ---   ------------------------------------------------
00014   13-NOV-96   SR    created
00015 
00016 *********************************************************************/
00017 
00018 #include <stdio.h>
00019 #include <dos.h>
00020 #include <math.h>
00021 
00022 #include "midas.h"
00023 #include "mcstd.h"
00024 #include "ps7106.h"
00025 
00026 /*------------------------------------------------------------------*/
00027 
00028 #define READ_MASK_7106          0
00029 #define READ_LATCH_7106         0
00030 #define READ_THRESH_7106        1
00031 #define READ_STATUS_7106        1
00032 #define WRITE_MASK_7106         16
00033 #define WRITE_THRESH_7106       17
00034 #define START_ADC_7106          17
00035 #define SET_LOCAL_7106          24
00036 #define TEST_DISC_7106          25
00037 #define SET_REMOTE_7106         26
00038 #define TEST_REMOTE_7106        27
00039 
00040 /*------------------------------------------------------------------*/
00041 
00042 int ps7106_set(int crate, int slot, double thresh_value)
00043 /********************************************************************\
00044   Sets the threshold of a Phillips 7106 discriminator to the given
00045   <thresh_value> in millivolts.
00046 \********************************************************************/
00047 {
00048    INT q;
00049    WORD data, threshold;
00050 
00051    // Convert threshold value to register value
00052    if (thresh_value > 1033)
00053       thresh_value = 1033;
00054    if (thresh_value < 10)
00055       thresh_value = 10;
00056    threshold = (unsigned int) (thresh_value - 10);
00057 
00058    /* Set remote mode */
00059    camo(crate, slot, 0, SET_REMOTE_7106, 0);
00060 
00061    /* Verify Remote mode */
00062    camc_q(crate, slot, 0, TEST_REMOTE_7106, &q);
00063    if (!q) {
00064       cm_msg(MERROR, "ps7106_set", "Error setting remote mode on crate %d, slot %d.\n",
00065              crate, slot);
00066 //    printf("Error setting remote mode on crate %d, slot %d.\n", crate, slot);
00067       return -1;
00068    }
00069 
00070    /* unmask all channels */
00071    camo(crate, slot, 0, 16, 0xFFFF);
00072 
00073    /* Write threshold */
00074    camo(crate, slot, 0, WRITE_THRESH_7106, threshold);
00075    ss_sleep(10);
00076 
00077    /* Verify threshold */
00078    cami(crate, slot, 0, READ_THRESH_7106, &data);
00079    data = data & 0x3FF;
00080    if (data != threshold) {
00081       cm_msg(MERROR, "ps7106_set", "Error setting threshold:\
00082  requested %d (%4.0f mV), read %d", threshold, thresh_value, data);
00083 //    printf("Error setting threshold:\
00084 // requested %d (%4.0f mV), read %d", threshold, thresh_value, data);
00085       return -1;
00086    }
00087 
00088    /* Measure threshold */
00089    camo(crate, slot, 1, START_ADC_7106, threshold);
00090    ss_sleep(10);
00091 
00092    cami(crate, slot, 1, READ_THRESH_7106, &data);
00093    data = data & 0x3FF;
00094 
00095    if (fabs((double) data - thresh_value) > 2.0) {
00096       cm_msg(MERROR, "ps7106_set", "Error setting threshold on crate %d, slot %d:\
00097  requested %1.0lfmV, measured %dmV", crate, slot, thresh_value, data);
00098 //    printf("Error setting threshold on crate %d, slot %d:\
00099 // requested %1.0lfmV, measured %dmV", crate, slot, thresh_value, data);
00100    }
00101 
00102    return 0;
00103 }

Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk