Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Production Test Suite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Production Test Suite
Commits
85ec062a
Commit
85ec062a
authored
Dec 12, 2011
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gain and offset correction functions.
parent
97bc7288
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
1 deletion
+58
-1
fmc_adc.py
test/fmcadc100m14b4cha/python/fmc_adc.py
+58
-1
No files found.
test/fmcadc100m14b4cha/python/fmc_adc.py
View file @
85ec062a
...
...
@@ -82,7 +82,7 @@ class CFmcAdc100Ms:
R_CH3_SSR
=
0x4C
R_CH3_VALUE
=
0x50
R_CH3_GAIN
=
0x54
R_CH
1
_OFFSET
=
0x58
R_CH
3
_OFFSET
=
0x58
R_CH4_SSR
=
0x5C
R_CH4_VALUE
=
0x60
R_CH4_GAIN
=
0x64
...
...
@@ -122,6 +122,9 @@ class CFmcAdc100Ms:
IN_TERM_MASK
=
0x08
IN_RANGES
=
{
'100mV'
:
0x23
,
'1V'
:
0x11
,
'10V'
:
0x45
,
'CAL'
:
0x40
,
'OPEN'
:
0x00
,
'CAL_100mV'
:
0x42
,
'CAL_1V'
:
0x40
,
'CAL_10V'
:
0x44
}
dac_offset_corr
=
[
0.0
]
*
4
dac_gain_corr
=
[
1.0
]
*
4
def
channel_addr
(
self
,
channel
,
reg
):
if
(
channel
<
1
or
channel
>
4
):
...
...
@@ -282,6 +285,43 @@ class CFmcAdc100Ms:
else
:
raise
Exception
(
'Unsupported parameter, channel number from 1 to 4'
)
def
set_dac_corr
(
self
,
gain
,
offset
):
self
.
dac_offset_corr
=
offset
self
.
dac_gain_corr
=
gain
def
dac_apply_corr
(
self
,
value
,
gain_corr
,
offset_corr
):
return
int
((
float
(
value
)
+
offset_corr
)
*
gain_corr
)
# Set DC offset with gain and offset correction
# value = DAC unsigned integer value
def
set_dc_offset_corrected
(
self
,
channel
,
value
):
if
(
1
==
channel
):
#print('CH%d DAC uncorrected value: 0x%.4X')%(channel, value)
value
=
self
.
dac_apply_corr
(
value
,
self
.
dac_gain_corr
[
channel
-
1
],
self
.
dac_offset_corr
[
channel
-
1
])
#print('gain corr: %1.9f offset corr: %1.9f')%(self.dac_gain_corr[channel-1], self.dac_offset_corr[channel-1])
#print('CH%d DAC corrected value : 0x%.4X')%(channel, value)
self
.
dac_ch1
.
set_offset
(
value
)
elif
(
2
==
channel
):
#print('CH%d DAC uncorrected value: 0x%.4X')%(channel, value)
value
=
self
.
dac_apply_corr
(
value
,
self
.
dac_gain_corr
[
channel
-
1
],
self
.
dac_offset_corr
[
channel
-
1
])
#print('gain corr: %1.9f offset corr: %1.9f')%(self.dac_gain_corr[channel-1], self.dac_offset_corr[channel-1])
#print('CH%d DAC corrected value : 0x%.4X')%(channel, value)
self
.
dac_ch2
.
set_offset
(
value
)
elif
(
3
==
channel
):
#print('CH%d DAC uncorrected value: 0x%.4X')%(channel, value)
value
=
self
.
dac_apply_corr
(
value
,
self
.
dac_gain_corr
[
channel
-
1
],
self
.
dac_offset_corr
[
channel
-
1
])
#print('gain corr: %1.9f offset corr: %1.9f')%(self.dac_gain_corr[channel-1], self.dac_offset_corr[channel-1])
#print('CH%d DAC corrected value : 0x%.4X')%(channel, value)
self
.
dac_ch3
.
set_offset
(
value
)
elif
(
4
==
channel
):
#print('CH%d DAC uncorrected value: 0x%.4X')%(channel, value)
value
=
self
.
dac_apply_corr
(
value
,
self
.
dac_gain_corr
[
channel
-
1
],
self
.
dac_offset_corr
[
channel
-
1
])
#print('gain corr: %1.9f offset corr: %1.9f')%(self.dac_gain_corr[channel-1], self.dac_offset_corr[channel-1])
#print('CH%d DAC corrected value : 0x%.4X')%(channel, value)
self
.
dac_ch4
.
set_offset
(
value
)
else
:
raise
Exception
(
'Unsupported parameter, channel number from 1 to 4'
)
# Reset DC offset DACs
def
dc_offset_reset
(
self
):
reg
=
self
.
fmc_adc_csr
.
rd_reg
(
self
.
R_CTL
)
...
...
@@ -523,6 +563,23 @@ class CFmcAdc100Ms:
addr
=
self
.
channel_addr
(
channel
,
self
.
R_CH1_VALUE
)
return
self
.
fmc_adc_csr
.
rd_reg
(
addr
)
# Set channel gain and offset correction
def
set_adc_gain_offset_corr
(
self
,
channel
,
gain
,
offset
):
addr
=
self
.
channel_addr
(
channel
,
self
.
R_CH1_GAIN
)
self
.
fmc_adc_csr
.
wr_reg
(
addr
,
gain
)
addr
=
self
.
channel_addr
(
channel
,
self
.
R_CH1_OFFSET
)
self
.
fmc_adc_csr
.
wr_reg
(
addr
,
offset
)
# Get channel gain correction
def
get_adc_gain_corr
(
self
,
channel
):
addr
=
self
.
channel_addr
(
channel
,
self
.
R_CH1_GAIN
)
return
self
.
fmc_adc_csr
.
rd_reg
(
addr
)
# Get channel offset correction
def
get_adc_offset_corr
(
self
,
channel
):
addr
=
self
.
channel_addr
(
channel
,
self
.
R_CH1_OFFSET
)
return
self
.
fmc_adc_csr
.
rd_reg
(
addr
)
# Print ADC core config/status
def
print_adc_core_config
(
self
):
print
(
"
\n
ADC core configuration/status"
)
...
...
Write
Preview
Markdown
is supported
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