Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Achim Morschhauser
GeomagLogger
Commits
71d78094
Commit
71d78094
authored
Nov 06, 2018
by
Achim Morschhauser
Browse files
Init run adapted
parent
4263d70d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/driver_obs_obsdaq.cpp
View file @
71d78094
...
...
@@ -987,105 +987,111 @@ int driver_obs_obsdaq::init() {
***************************************************************************/
int
driver_obs_obsdaq
::
init_run
(
double
freq
){
// The receive buffer
char
buf
[
200
];
// A command to send
char
cmd
[
20
];
// Index of the selected frequency
int
freq_sel
;
// ADC calibration
int
adc_scale
,
adc_offset
;
/////////////////////////////////////////////////////////////////////
//
// Set frequency.
//
/////////////////////////////////////////////////////////////////////
// Set triggering off
send
(
"#PP00000000"
);
usleep
(
1e6
);
// The receive buffer
char
buf
[
200
];
// A command to send
char
cmd
[
20
];
// Index of the selected frequency
int
freq_sel
;
// Find the closest possible valid frequency lower or equal to the one
// requested.
for
(
int
i
=
0
;
i
<
valid_filter_rates_num
;
i
++
){
if
(
valid_filter_rates
[
i
]
>
freq
){
freq_sel
=
i
;
break
;
}
}
// ADC calibration
int
adc_scale
,
adc_offset
;
// 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
]);
send
(
cmd
);
waitanswer
(
5
);
}
/////////////////////////////////////////////////////////////////////
//
// Set frequency.
//
/////////////////////////////////////////////////////////////////////
//
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
);
//
Set triggering off
//TODO Check if necessary here
send
(
"#PP00000000"
);
usleep
(
1e6
);
/////////////////////////////////////////////////////////////////////////
//
// Calibrate.
//
/////////////////////////////////////////////////////////////////////////
// Find the closest possible valid frequency larger or equal to
// the one requested.
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
for
(
int
i
=
0
;
i
<
3
;
i
++
){
// 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
]);
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
);
receive
(
buf
,
sizeof
(
buf
),
1
);
fprintf
(
stderr
,
"REC_CONFIG: %s
\n
"
,
buf
);
/////////////////////////////////////////////////////////////////////////
//
// Calibrate.
//
/////////////////////////////////////////////////////////////////////////
// Get the last four bytes ("ccdd") and add
channel
number
config
=
(
i
<<
16
)
+
strtoul
(
&
buf
[
7
],
NULL
,
16
);
// Iterate over all three
channel
s
for
(
int
i
=
0
;
i
<
3
;
i
++
){
// Check if calibration for the given config
// was pre-determined
if
(
driver_obs
::
cal
->
get_adc_calibrate
(
&
adc_offset
,
&
adc_scale
,
config
)
<
0
){
int
config
=
0
;
// Get current 24-bit configuration (Manual 12.4.9)
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
//auto_calibrate(i
,1);
// Get the last four bytes ("ccdd") and add channel number
config
=
(
i
<<
16
)
+
strtoul
(
&
buf
[
7
],
NULL
,
1
6
);
}
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
sprintf
(
cmd
,
"$%1dWO%06X"
,
i
,
adc_offset
);
send
(
cmd
);
waitanswer
(
5
);
sprintf
(
cmd
,
"$%1dWF%06X"
,
i
,
adc_scale
);
send
(
cmd
);
waitanswer
(
5
);
// Automatic Calibration
// auto_calibrate(i,1);
}
}
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
// Set the conversion parameters
//FULLSCALE=42.5; // Self-Gain calibration
//FULLSCALE=40.0; // System-Gain calibration
//TODO Automatically set the calibration parameters
// Set the conversion parameters
//FULLSCALE=42.5; // Self-Gain calibration
//FULLSCALE=40.0; // System-Gain calibration
//GAIN=4.0; // +/- 10V range
//GAIN=8.0; // +/- 5V range
//GAIN=4.0; // +/- 10V 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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment