Commit 71d78094 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Init run adapted

parent 4263d70d
...@@ -987,105 +987,111 @@ int driver_obs_obsdaq::init() { ...@@ -987,105 +987,111 @@ int driver_obs_obsdaq::init() {
***************************************************************************/ ***************************************************************************/
int driver_obs_obsdaq::init_run(double freq){ int driver_obs_obsdaq::init_run(double freq){
// The receive buffer // The receive buffer
char buf[200]; char buf[200];
// A command to send // A command to send
char cmd[20]; char cmd[20];
// Index of the selected frequency // Index of the selected frequency
int freq_sel; int freq_sel;
// ADC calibration
int adc_scale, adc_offset;
/////////////////////////////////////////////////////////////////////
//
// Set frequency.
//
/////////////////////////////////////////////////////////////////////
// Set triggering off
send("#PP00000000");
usleep(1e6);
// Find the closest possible valid frequency lower or equal to the one // ADC calibration
// requested. int adc_scale, adc_offset;
for (int i=0; i<valid_filter_rates_num; i++){
if (valid_filter_rates[i]>freq){
freq_sel=i;
break;
}
}
// Set range to +10V and set frequency of digital filter /////////////////////////////////////////////////////////////////////
for (int i=0; i<3; i++){ //
sprintf(cmd,"$%1dWS020102%s",i,filter_cmds[freq_sel]); // Set frequency.
send(cmd); waitanswer(5); //
} /////////////////////////////////////////////////////////////////////
// Print used and requested frequency // Set triggering off
fprintf(stderr,"Frequency set to: %6.2f Hz. " //TODO Check if necessary here
"Requested frequency: %6.2f Hz.\n", send("#PP00000000");
valid_filter_rates[freq_sel],freq); usleep(1e6);
///////////////////////////////////////////////////////////////////////// // Find the closest possible valid frequency larger or equal to
// // the one requested.
// Calibrate. for (int i=0; i<valid_filter_rates_num; i++){
// if (valid_filter_rates[i]>=freq){
///////////////////////////////////////////////////////////////////////// freq_sel = i;
break;
}
}
// Iterate over all three channels // Set range to +10V and set frequency of digital filter
for (int i=0; i<3; i++){ for (int i=0; i<3; i++){
sprintf(cmd,"$%1dWS020102%s",i,filter_cmds[freq_sel]);
send(cmd); waitanswer(5);
}
int config=0; // Print used and requested frequency
fprintf(stderr,"Frequency set to: %6.2f Hz. "
"Requested frequency: %6.2f Hz.\n",
valid_filter_rates[freq_sel],freq);
// Get current 24-bit configuration (Manual 12.4.9) /////////////////////////////////////////////////////////////////////////
sprintf(cmd,"$%1dRS",i); //
send(cmd); // Calibrate.
receive(buf,sizeof(buf),1); //
fprintf(stderr,"REC_CONFIG: %s\n",buf); /////////////////////////////////////////////////////////////////////////
// Get the last four bytes ("ccdd") and add channel number // Iterate over all three channels
config= (i<<16) + strtoul(&buf[7],NULL,16); for (int i=0; i<3; i++){
// Check if calibration for the given config int config=0;
// was pre-determined
if (driver_obs::cal->get_adc_calibrate // Get current 24-bit configuration (Manual 12.4.9)
(&adc_offset, &adc_scale, config)<0){ usleep(0.5*1e6);
flush();
sprintf(cmd,"$%1dRS",i);
send(cmd);
receive(buf,sizeof(buf),1);
fprintf(stderr,"REC_CONFIG: %s\n",buf);
// Automatic Calibration // Get the last four bytes ("ccdd") and add channel number
//auto_calibrate(i,1); config= (i<<16) + strtoul(&buf[7],NULL,16);
} else { // Check if calibration for the given config
// was pre-determined
if (driver_obs::cal->get_adc_calibrate
(&adc_offset, &adc_scale, config)<0){
// Set the pre-determined calibration constant // Automatic Calibration
sprintf(cmd,"$%1dWO%06X",i,adc_offset); // auto_calibrate(i,1);
send(cmd); waitanswer(5);
sprintf(cmd,"$%1dWF%06X",i,adc_scale);
send(cmd); waitanswer(5);
} } else {
//printf("============ GOT: %06X %06X\n",adc_offset,adc_scale); // Set the pre-determined calibration constant
sprintf(cmd,"$%1dWO%06X",i,adc_offset);
send(cmd); waitanswer(5);
sprintf(cmd,"$%1dWF%06X",i,adc_scale);
send(cmd); waitanswer(5);
} }
//printf("============ GOT: %06X %06X\n",adc_offset,adc_scale);
}
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Set the scaling parameter (Manual 12.5.1). // Set the scaling parameter (Manual 12.5.1).
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
//TODO Automatically set the calibration parameters //TODO Automatically set the calibration parameters
// Set the conversion parameters // Set the conversion parameters
//FULLSCALE=42.5; // Self-Gain calibration //FULLSCALE=42.5; // Self-Gain calibration
//FULLSCALE=40.0; // System-Gain calibration //FULLSCALE=40.0; // System-Gain calibration
//GAIN=4.0; // +/- 10V range //GAIN=4.0; // +/- 10V range
//GAIN=8.0; // +/- 5V range //GAIN=8.0; // +/- 5V range
M = 40.0 / 4.0 / (double) 0x800000;
//printf("M: %f\n",M); M = 40.0 / 4.0 / (double) 0x800000;
//printf("M: %f\n",M);
return(0);
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment