mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 17:10:03 +02:00
in between
This commit is contained in:
parent
79693a38f5
commit
1c59c5c4f4
1
slsDetectorServers/ctbDetectorServer/MAX1932.h
Symbolic link
1
slsDetectorServers/ctbDetectorServer/MAX1932.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../slsDetectorServer/MAX1932.h
|
1
slsDetectorServers/jungfrauDetectorServer/MAX1932.h
Symbolic link
1
slsDetectorServers/jungfrauDetectorServer/MAX1932.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../slsDetectorServer/MAX1932.h
|
64
slsDetectorServers/slsDetectorServer/MAX1932.h
Executable file
64
slsDetectorServers/slsDetectorServer/MAX1932.h
Executable file
@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||||
|
|
||||||
|
/* MAX1932 HV DEFINES */
|
||||||
|
|
||||||
|
#define MAX1932_HV_NUMBITS (8)
|
||||||
|
#define MAX1932_HV_DATA_OFST (0)
|
||||||
|
#define MAX1932_HV_DATA_MSK (0x000000FF << MAX1932_HV_DATA_OFST)
|
||||||
|
|
||||||
|
// on power up, dac = 0xff (1.25)
|
||||||
|
|
||||||
|
uint32_t MAX1932_Reg = 0x0;
|
||||||
|
uint32_t MAX1932_CsMask = 0x0;
|
||||||
|
uint32_t MAX1932_ClkMask = 0x0;
|
||||||
|
uint32_t MAX1932_DigMask = 0x0;
|
||||||
|
int MAX1932_DigOffset = 0x0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Defines
|
||||||
|
* @param reg spi register
|
||||||
|
* @param cmsk chip select mask
|
||||||
|
* @param clkmsk clock output mask
|
||||||
|
* @param dmsk digital output mask
|
||||||
|
* @param dofst digital output offset
|
||||||
|
*/
|
||||||
|
void MAX1932_SetDefines(uint32_t reg, uint32_t cmsk, uint32_t clkmsk, uint32_t dmsk, int dofst) {
|
||||||
|
MAX1932_Reg = reg;
|
||||||
|
MAX1932_CsMask = cmsk;
|
||||||
|
MAX1932_ClkMask = clkmsk;
|
||||||
|
MAX1932_DigMask = dmsk;
|
||||||
|
MAX1932_DigOffset = dofst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable SPI
|
||||||
|
*/
|
||||||
|
void MAX1932_Disable() {
|
||||||
|
bus_w(MAX1932_Reg, bus_r(MAX1932_Reg)
|
||||||
|
| MAX1932_CsMask
|
||||||
|
| MAX1932_ClkMask
|
||||||
|
&~(MAX1932_DigMask));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure
|
||||||
|
*/
|
||||||
|
void MAX1932_Configure(){
|
||||||
|
FILE_LOG(logINFOBLUE, ("Configuring MAX1932\n"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set
|
||||||
|
* @param dacnum dac number
|
||||||
|
* @param data dac value to set
|
||||||
|
*/
|
||||||
|
void MAX1932_Set (int dacnum, int data) {
|
||||||
|
FILE_LOG(logDEBUG1, ("\tSetting dac %d to %d\n", dacnum, data));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
44
slsDetectorServers/slsDetectorServer/common.h
Executable file
44
slsDetectorServers/slsDetectorServer/common.h
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert voltage to dac units
|
||||||
|
* @param voltage value in mv
|
||||||
|
* @param dacval pointer to value converted to dac units
|
||||||
|
* @param vmin minimum voltage in mV
|
||||||
|
* @param vmax maximum voltage in mV
|
||||||
|
* @param maximum number of steps
|
||||||
|
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||||
|
*/
|
||||||
|
int Common_VoltageToDac(int voltage, int* dacval, int vmin, int vmax, int nsteps) {
|
||||||
|
|
||||||
|
// validate
|
||||||
|
if ((voltage < vmin) || (voltage > vmax)) {
|
||||||
|
FILE_LOG(logERROR, ("Voltage value (to convert to dac value) is outside bounds (%d to %d mV): %d\n", vmin, vmax, voltage));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert
|
||||||
|
*dacval = (int)(((voltage - vmin) / (vmax - vmin)) * (nsteps - 1) + 0.5);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Convert dac units to voltage
|
||||||
|
* @param dacval dac units
|
||||||
|
* @param voltage pointer to value converted to mV
|
||||||
|
* @param vmin minimum voltage in mV
|
||||||
|
* @param vmax maximum voltage in mV
|
||||||
|
* @param maximum number of steps
|
||||||
|
* @returns FAIL when voltage outside limits, OK if conversion successful
|
||||||
|
*/
|
||||||
|
int Common_DacToVoltage(int dacval, int* voltage, int vmin, int vmax, int nsteps) {
|
||||||
|
|
||||||
|
// validate
|
||||||
|
if ((dacval < 0) || (dacval >= nsteps)) {
|
||||||
|
FILE_LOG(logERROR, ("Dac units (to convert to voltage) is outside bounds (0 to %d): %d\n", nsteps - 1, dacval));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert
|
||||||
|
*voltage = vmin + (vmax - vmin) * dacval / (nsteps - 1);
|
||||||
|
return OK;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user