Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python_test_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
python_test_scripts
Commits
1676306e
You need to sign in or sign up before continuing.
Commit
1676306e
authored
2 years ago
by
Gijs Schoonderbeek
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup (my way)
parent
a523b08a
No related branches found
No related tags found
1 merge request
!3
Apsct production
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apsct_lib.py
+314
-300
314 additions, 300 deletions
apsct_lib.py
production_apsct.py
+59
-0
59 additions, 0 deletions
production_apsct.py
with
373 additions
and
300 deletions
apsct_lib.py
+
314
−
300
View file @
1676306e
'''
"""
Copyright 2021 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
ASTRON Netherlands Institute for Radio Astronomy
Licensed under the Apache License, Version 2.0 (the
"
License
"
);
...
...
@@ -13,7 +13,7 @@ limitations under the License.
Set APSCT_CLK
'''
"""
import
sys
import
time
sys
.
path
.
insert
(
0
,
'
.
'
)
...
...
@@ -23,244 +23,324 @@ if os.name =="posix":
else
:
from
I2C_serial
import
*
DEBUG
=
False
I2CBUSNR
=
5
sleep_time
=
0.15
SET_PLL
=
True
READ_LOCK
=
True
READ_ALL
=
False
CHECK_EEPROM
=
False
PWR_RST
=
False
#True #False
READ_SENSOR
=
False
#True
READ_REGS
=
False
#True
CLK_FREQ
=
'
200MHz
'
dev_i2c_eeprom
=
I2C
(
0x50
)
dev_i2c_eeprom
.
bus_nr
=
I2CBUSNR
EEPROM
=
0x50
PLL_200M
=
0x20
PLL_160M
=
0x21
CS
=
6
SCLK
=
4
SDO
=
5
SDI
=
7
PLL_200M
=
0x20
PLL_160M
=
0x21
class
ApsctClass
()
class
ApsctClass
:
#
# Toplevel class that contrains all parts of the APSCT
#
def
__init__
(
self
):
self
.
reg_address
def
Write_byte_PLL
(
reg_address
,
wr_data
,
ADDRESS
=
0x20
):
self
.
status
=
False
self
.
eeprom
=
EepromClass
()
self
.
pll_200
=
PllClass
(
PLL_200M
)
self
.
pll_160
=
PllClass
(
PLL_160M
)
self
.
sensors
=
ApsctSensors
()
def
read_IO_expanderis
(
self
):
#
#
Write Byte to the ADC
#
Read both IO-Expander lines and pints on the screen
#
I2C_device
=
I2C
(
ADDRESS
,
BUSNR
=
I2CBUSNR
)
PLL_rw
=
0x00
# 0 for write, 1 for read
i2c_addr
=
[
0x20
,
0x21
]
for
addr
in
i2c_addr
:
i2c_device
=
I2C
(
addr
,
BUSNR
=
I2CBUSNR
)
# clock selection
for
reg_cnt
in
range
(
8
):
ack
,
ret_value
=
i2c_device
.
read_bytes
(
reg_cnt
,
2
)
stri
=
"
Expander : 0x{:0>2x}, Reg 0x{:0>2x}, value 0x{}{}
"
.
format
(
addr
,
reg_cnt
,
ret_value
[
0
],
ret_value
[
1
])
# [start+2:start])
print
(
stri
)
def
power
(
self
,
state
):
#
# Set power supply APSCTs in the give state
#
# state is True: Power on
# state is False: Power off
#
stri
=
"
Power to {}
"
.
format
(
state
)
print
(
stri
)
I2C_IO_device_A
=
I2C
(
0x20
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_A
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
I2C_IO_device_A
.
write_bytes
(
0x07
,
0x00
)
# '0' is output
I2C_IO_device_B
=
I2C
(
0x21
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_B
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
if
state
:
bits_to_set_A1
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
bits_to_set_A2
=
0x04
bits_to_set_B1
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
else
:
bits_to_set_A1
=
0x00
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
bits_to_set_A2
=
0x00
bits_to_set_B1
=
0x00
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
if
DEBUG
:
stri
=
"
Bits to reg 0 0x{0:x}
"
.
format
(
bits_to_set_A1
)
print
(
stri
)
I2C_IO_device_A
.
write_bytes
(
0x02
,
bits_to_set_A1
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
bits_to_set_A2
)
I2C_IO_device_B
.
write_bytes
(
0x02
,
bits_to_set_B1
)
def
set_apsct
(
self
,
state
):
#
# set APSCT to 200MHz, 160MHz or off
#
if
state
==
"
200MHz
"
:
self
.
power
(
True
)
self
.
pll_200
.
setup_pll
()
elif
state
==
"
160MHz
"
:
self
.
power
(
True
)
self
.
pll_160
.
setup_pll
()
else
:
self
.
power
(
False
)
class
PllClass
:
#
# Toplevel class that contrains all parts of the PLL
#
def
__init__
(
self
,
address
=
0x20
):
self
.
status
=
False
self
.
i2c_address
=
address
self
.
dev_i2c_pll
=
I2C
(
self
.
i2c_address
,
BUSNR
=
I2CBUSNR
)
if
address
==
0x20
:
self
.
frequency
=
'
200MHz
'
else
:
self
.
frequency
=
'
160MHz
'
def
Write_byte_PLL
(
self
,
reg_address
,
wr_data
):
#
# Write Byte to the PLL
#
pll_rw
=
0x00
# 0 for write, 1 for read
stri
=
"
Write to address : 0x{1:{fill}2x} value 0x{0:{fill}2x}
"
.
format
(
wr_data
,
reg_address
,
fill
=
'
0
'
)
print
(
stri
)
I2C_device
.
write_bytes
(
0x06
,
0x2C
)
self
.
dev_i2c_pll
.
write_bytes
(
0x06
,
0x2C
)
if
DEBUG
:
rd_bytes
=
I2C_device
.
read_bytes
(
0x06
,
1
)
rd_bytes
=
self
.
dev_i2c_pll
.
read_bytes
(
0x06
,
1
)
stri
=
"
IO expander wrote 0x{0:x}, read 0x{1}
"
.
format
(
0x2C
,
rd_bytes
[
1
])
print
(
stri
)
data
=
(
reg_address
<<
9
)
+
(
PLL
_rw
<<
8
)
+
wr_data
data
=
(
reg_address
<<
9
)
+
(
pll
_rw
<<
8
)
+
wr_data
bit_array
=
"
{0:{fill}16b}
"
.
format
(
data
,
fill
=
'
0
'
)
I2C_device
.
write_bytes
(
0x02
,
0x02
|
(
0x1
<<
CS
))
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
0x02
|
(
0x1
<<
CS
))
for
bit
in
bit_array
:
for
clk
in
range
(
2
):
Write_data
=
0x02
|
(
0
<<
CS
)
|
(
clk
<<
SCLK
)
|
(
int
(
bit
)
<<
SDI
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
for
clk
in
range
(
2
):
Write_data
=
0x02
|
(
0
<<
CS
)
|
(
clk
<<
SCLK
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
for
clk
in
range
(
2
):
Write_data
=
0x02
|
(
1
<<
CS
)
|
(
clk
<<
SCLK
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
Write_data
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
if
DEBUG
:
read_bits
=
Read_byte_PLL
(
reg_address
,
nof_bytes
=
1
,
ADDRESS
=
ADDRESS
)
# stri = "Bits written 0x{0:x} to register 0x{1:x} read from PLL are {2}".format(wr_data, reg_address, read_bits)
# print(stri)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
def
Read_byte_PLL
(
reg_address
,
nof_bytes
=
1
,
ADDRESS
=
0x20
):
def
Read_byte_PLL
(
self
,
reg_address
,
nof_bytes
=
1
):
#
# Read Byte from the
ADC
# Read Byte from the
PLL
#
I2C_device
=
I2C
(
ADDRESS
,
BUSNR
=
I2CBUSNR
)
PLL_rw
=
0x01
# 0 for write, 1 for read
I2C_device
.
write_bytes
(
0x06
,
0x2C
)
data
=
(
reg_address
<<
7
)
+
PLL_rw
pll_rw
=
0x01
# 0 for write, 1 for read
self
.
dev_i2c_pll
.
write_bytes
(
0x06
,
0x2C
)
data
=
(
reg_address
<<
7
)
+
pll_rw
bit_array
=
"
{0:{fill}8b}
"
.
format
(
data
,
fill
=
'
0
'
)
for
bit
in
bit_array
:
for
clk
in
range
(
2
):
Write_data
=
0x02
|
(
0
<<
CS
)
|
(
clk
<<
SCLK
)
|
(
int
(
bit
)
<<
SDI
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
sleep
(
sleep_time
)
# print("read byte")
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
time
.
sleep
(
sleep_time
)
read_bit
=
''
for
cnt
in
range
(
8
*
nof_bytes
):
for
clk
in
[
0
,
1
]:
# Read after rizing edge
Write_data
=
0x02
|
(
clk
<<
SCLK
)
|
(
int
(
bit
)
<<
SDI
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
ret_ack
,
ret_value
=
I2C_device
.
read_bytes
(
0x00
,
1
)
# stri= "ret_value = {}".format(int(ret_value,16))
# print(stri)
Write_data
=
0x02
|
(
clk
<<
SCLK
)
|
(
int
(
bit_array
[
-
1
])
<<
SDI
)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
ret_ack
,
ret_value
=
self
.
dev_i2c_pll
.
read_bytes
(
0x00
,
1
)
if
ret_ack
:
read_bit
+=
str
((
int
(
ret_value
,
16
)
>>
SDO
)
&
0x01
)
else
:
print
(
"
ACK nok
"
)
Write_data
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
stri
=
"
Read back at address 0x{0:{fill}2x} result : 0x{1:{fill}2x}
"
.
format
(
reg_address
,
int
(
read_bit
,
2
),
fill
=
'
0
'
)
self
.
dev_i2c_pll
.
write_bytes
(
0x02
,
Write_data
)
stri
=
"
Read back at address 0x{0:{fill}2x} result : 0x{1:{fill}2x}
"
.
format
(
reg_address
,
int
(
read_bit
,
2
),
fill
=
'
0
'
)
print
(
stri
)
return
read_bit
;
return
read_bit
def
read_all_regs_pll
(
pll_frequency
=
'
200MHz
'
)
:
I2C_device
=
I2C
(
0x20
,
BUSNR
=
I2CBUSNR
)
#clock selection
I2C_device
.
write_bytes
(
0x07
,
0x00
)
if
pll_frequency
==
'
160MHz
'
:
print
(
"
Read PLL 160 MHz
"
)
pll_address
=
PLL_160M
# I2C_device.write_bytes(0x03, 0x0F)
def
setup_pll
(
self
):
#
# Set registers on the PLL
#
self
.
dev_i2c_pll
.
write_bytes
(
0x07
,
0x00
)
if
self
.
frequency
==
'
160MHz
'
:
self
.
dev_i2c_pll
.
write_bytes
(
0x03
,
0x08
)
else
:
self
.
dev_i2c_pll
.
write_bytes
(
0x03
,
0x28
)
self
.
Write_byte_PLL
(
0x03
,
0x0C
)
sleep
(
0.5
)
self
.
Write_byte_PLL
(
0x03
,
0x08
)
self
.
Write_byte_PLL
(
0x03
,
0x08
)
self
.
Write_byte_PLL
(
0x04
,
0xCF
)
# CF disable not used outputs, 00 enable all
self
.
Write_byte_PLL
(
0x05
,
0x97
)
self
.
Write_byte_PLL
(
0x06
,
0x10
)
# cp inv = 0xF4 other 0xE4
self
.
Write_byte_PLL
(
0x07
,
0x04
)
# Divider R = 1 dec
self
.
Write_byte_PLL
(
0x08
,
0x01
)
self
.
Write_byte_PLL
(
0x07
,
0x00
)
self
.
Write_byte_PLL
(
0x09
,
0x10
)
# reset
if
self
.
frequency
==
'
160MHz
'
:
self
.
Write_byte_PLL
(
0x0A
,
0x10
)
else
:
print
(
"
Read PLL 200 MHz
"
)
pll_address
=
PLL_200M
# I2C_device.write_bytes(0x03, 0xF8)
# for reg_cnt in range(0x15):
self
.
Write_byte_PLL
(
0x0A
,
0x14
)
self
.
Write_byte_PLL
(
0x09
,
0x00
)
self
.
Write_byte_PLL
(
0x0C
,
0x8F
)
self
.
Write_byte_PLL
(
0x0D
,
0x88
)
# Dig CLK = 200/1 = 200 MHz
self
.
Write_byte_PLL
(
0x0F
,
0x08
)
# RCU CLK = 200/1 = 200 MHz
self
.
Write_byte_PLL
(
0x11
,
0x08
)
# PPS ref CLK = 200/1 = 200 MHz
self
.
Write_byte_PLL
(
0x13
,
0x88
)
# T.P. CLK = 200/1 = 200 MHz
def
read_all_regs_pll
(
self
):
#
# Read all registers on the PLL and print on screen
#
self
.
dev_i2c_pll
.
write_bytes
(
0x07
,
0x00
)
bytes_to_read
=
24
ret_value
=
Read_byte_PLL
(
0
,
nof_bytes
=
bytes_to_read
,
ADDRESS
=
pll_address
)
ret_value
=
self
.
Read_byte_PLL
(
0
,
nof_bytes
=
bytes_to_read
)
for
cnt
in
range
(
bytes_to_read
):
start
=
cnt
*
8
stri
=
"
Reg nr 0x{:0>2x} value: 0x{:0>2x}
"
.
format
(
cnt
,
int
(
ret_value
[
start
:
start
+
8
],
2
))
print
(
stri
)
def
read_IO_expanderis
():
i2c_addr
=
[
0x20
,
0x21
]
for
addr
in
i2c_addr
:
I2C_device
=
I2C
(
addr
,
BUSNR
=
I2CBUSNR
)
#clock selection
for
reg_cnt
in
range
(
8
):
ack
,
ret_value
=
I2C_device
.
read_bytes
(
reg_cnt
,
2
)
stri
=
"
Expander : 0x{:0>2x}, Reg 0x{:0>2x}, value 0x{}{}
"
.
format
(
addr
,
reg_cnt
,
ret_value
[
0
],
ret_value
[
1
])
#[start+2:start])
print
(
stri
)
def
setup_pll
(
pll_frequency
=
'
200MHz
'
)
:
I2C_device
=
I2C
(
0x20
,
BUSNR
=
I2CBUSNR
)
#clock selection
I2C_device
.
write_bytes
(
0x07
,
0x00
)
if
pll_frequency
==
'
160MHz
'
:
print
(
"
Set PLL to 160 MHz mode
"
)
pll_address
=
PLL_160M
I2C_device
.
write_bytes
(
0x03
,
0x08
)
else
:
print
(
"
Set PLL to 200 MHz mode
"
)
pll_address
=
PLL_200M
I2C_device
.
write_bytes
(
0x03
,
0x28
)
Write_byte_PLL
(
0x03
,
0x0C
,
pll_address
)
sleep
(
0.5
)
Write_byte_PLL
(
0x03
,
0x08
,
pll_address
)
Write_byte_PLL
(
0x03
,
0x08
,
pll_address
)
Write_byte_PLL
(
0x04
,
0xCF
,
pll_address
)
# CF disable not used outputs, 00 enable all
Write_byte_PLL
(
0x05
,
0x97
,
pll_address
)
Write_byte_PLL
(
0x06
,
0x10
,
pll_address
)
# cp inv = 0xF4 other 0xE4
Write_byte_PLL
(
0x07
,
0x04
,
pll_address
)
# Divider R = 1 dec
Write_byte_PLL
(
0x08
,
0x01
,
pll_address
)
Write_byte_PLL
(
0x07
,
0x00
,
pll_address
)
Write_byte_PLL
(
0x09
,
0x10
,
pll_address
)
# reset
if
pll_frequency
==
'
160MHz
'
:
Write_byte_PLL
(
0x0A
,
0x10
,
pll_address
)
else
:
Write_byte_PLL
(
0x0A
,
0x14
,
pll_address
)
Write_byte_PLL
(
0x09
,
0x00
,
pll_address
)
Write_byte_PLL
(
0x0C
,
0x8F
,
pll_address
)
Write_byte_PLL
(
0x0D
,
0x88
,
pll_address
)
# Dig CLK = 200/1 = 200 MHz
Write_byte_PLL
(
0x0F
,
0x08
,
pll_address
)
# RCU CLK = 200/1 = 200 MHz
Write_byte_PLL
(
0x11
,
0x08
,
pll_address
)
# PPS ref CLK = 200/1 = 200 MHz
Write_byte_PLL
(
0x13
,
0x88
,
pll_address
)
# T.P. CLK = 200/1 = 200 MHz
def
power
(
state
):
stri
=
"
Power to {}
"
.
format
(
state
)
print
(
stri
)
def
read_lol
(
self
,
pll_frequency
=
'
200MHz
'
):
#
# Read loss of lock status
#
I2C_IO_device_A
=
I2C
(
0x20
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_A
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
I2C_IO_device_A
.
write_bytes
(
0x07
,
0x00
)
# '0' is output
I2C_IO_device_B
=
I2C
(
0x21
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_B
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
if
state
:
bits_to_set_A1
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
bits_to_set_A2
=
0x04
bits_to_set_B1
=
0x02
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
else
:
bits_to_set_A1
=
0x00
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
bits_to_set_A2
=
0x00
bits_to_set_B1
=
0x00
|
(
1
<<
CS
)
|
(
0
<<
SCLK
)
|
(
0
<<
SDI
)
if
DEBUG
:
stri
=
"
Bits to reg 0 0x{0:x}
"
.
format
(
bits_to_set_A1
)
print
(
stri
)
I2C_IO_device_A
.
write_bytes
(
0x02
,
bits_to_set_A
1
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
bits_to_set_A2
)
I2C_IO_device_B
.
write_bytes
(
0x02
,
bits_to_set_B1
)
I2C_IO_device_B
.
write_bytes
(
0x07
,
0xFF
)
# '0' is output
ack
,
ret_value
=
I2C_IO_device_B
.
read_bytes
(
0x01
,
1
)
status_reg
=
int
(
ret_value
,
16
)
if
(
pll_frequency
==
'
200MHz
'
)
&
((
status_reg
&
0x10
)
>
0
)
:
print
(
"
lost lock 200MHz
"
)
if
((
status_reg
&
0x20
)
>
0
)
&
(
pll_frequency
==
'
160MHz
'
):
print
(
"
lost lock 160MHz
"
)
ack
,
ret_value
=
I2C_IO_device_A
.
read_bytes
(
0x01
,
1
)
old_reg
=
int
(
ret_value
,
16
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
(
old_reg
|
0x10
))
# '0' is output
sleep
(
1
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
(
old_reg
&
0xEF
))
# '0' is output
def
write_eeprom
(
data
=
0x01
):
class
EepromClass
:
#
# Class to handle EEPROM communication
#
def
__init__
(
self
):
#
# All monitor. read and write functions for the EEPROM
#
self
.
dev_i2c_eeprom
=
I2C
(
EEPROM
)
self
.
dev_i2c_eeprom
.
bus_nr
=
I2CBUSNR
def
write_eeprom
(
self
,
data
=
"
APSPU
"
,
address
=
0
):
#
# Write the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
dev_i2c_eeprom
.
read_bytes
(
0
)
# Data = data to write in string formal
# Address = address to write the data to
# Return True if successfully
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
0
)
if
ret_ack
<
1
:
print
(
"
EEPROM not found during write
"
)
return
False
else
:
dev_i2c_eeprom
.
write_bytes
(
0x00
,
data
)
wr_data
=
bytearray
(
data
.
encode
(
"
utf-8
"
,
errors
=
"
ignore
"
))
for
loc
,
data_byte
in
enumerate
(
wr_data
):
self
.
dev_i2c_eeprom
.
write_bytes
(
address
+
loc
,
data_byte
)
sleep
(
0.1
)
return
True
def
read_eeprom
():
def
read_eeprom
(
self
,
address
=
0
,
nof_bytes
=
5
):
#
# Read the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
dev_i2c_eeprom
.
read_last_reg
(
1
)
# Address = address to read from
# nof_bytes = number of bytes to read
# return string with the data from the flash
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_last_reg
(
1
)
if
ret_ack
<
1
:
print
(
"
no EEPROM found during read
"
)
return
False
else
:
ret_ack
,
ret_value
=
dev_i2c_eeprom
.
read_bytes
(
0x00
,
1
)
return
ret_value
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
address
,
nof_bytes
)
str_return
=
bytes
.
fromhex
(
ret_value
[:
nof_bytes
*
2
]).
decode
(
'
UTF-8
'
)
return
str_return
def
wr_rd_eeprom
(
value
=
0x34
):
def
wr_rd_eeprom
(
self
,
value
=
"
APSPU-1
"
,
address
=
0
):
#
# Write and Read the EEPROM to check functionality
#
if
write_eeprom
(
value
):
ret_value
=
read_eeprom
()
stri
=
"
Wrote to EEPROM: 0x{0:X}, Read from EEPROM: 0x{1}
"
.
format
(
value
,
ret_value
)
# value = string with data to write
# address = address to write the data to
# return True if read back is same as write value
#
if
self
.
write_eeprom
(
value
,
address
=
0
):
ret_value
=
self
.
read_eeprom
(
address
=
0
,
nof_bytes
=
len
(
value
))
stri
=
"
Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}
"
.
format
(
value
,
ret_value
,
address
)
print
(
stri
)
if
ret_value
==
value
:
return
True
else
:
return
False
class
ApsctSensors
:
#
# All monitor. read and write functions for the voltage sensors on APSCT
#
def
__init__
(
self
):
#
# All monitor. read and write functions for the EEPROM
#
self
.
dev_i2c_sensor
=
I2C
(
0x74
)
self
.
dev_i2c_sensor
.
bus_nr
=
I2CBUSNR
def
apsct_sensors
():
def
apsct_sensors
(
self
):
for
sens_line
in
range
(
7
):
read_voltage
(
sens_line
)
read_temp
()
self
.
read_voltage
(
sens_line
)
self
.
read_temp
()
def
read_voltage
(
input_channel
=
0
):
addr
=
0x74
def
read_voltage
(
self
,
input_channel
=
0
):
#
# Function to read a voltages of APSCT
#
# input_channel = sens port
# return value
#
Vref
=
3.0
one_step
=
Vref
/
(
2
**
(
16
))
I2C_device
=
I2C
(
addr
,
BUSNR
=
I2CBUSNR
)
one_step
=
Vref
/
(
2
**
16
)
channel_select_word
=
0xB0
|
((
input_channel
%
2
)
<<
3
)
|
((
input_channel
>>
1
)
&
0x7
)
if
DEBUG
:
stri
=
"
Word to select sens input is 0x{0:x}
"
.
format
(
channel_select_word
)
print
(
stri
)
sleep
(
0.1
)
I2C_device
.
write_bytes
(
channel_select_word
,
0xB8
)
self
.
dev_i2c_sensor
.
write_bytes
(
channel_select_word
,
0xB8
)
sleep
(
0.5
)
ret_ack
,
ret_value
=
I2C_device
.
read_last_reg
(
3
)
if
1
:
#ret_ack:
ret_ack
,
ret_value
=
self
.
dev_i2c_sensor
.
read_last_reg
(
3
)
if
DEBUG
:
stri
=
"
Return value input 0 : 0x{0}
"
.
format
(
ret_value
)
print
(
stri
)
...
...
@@ -272,20 +352,19 @@ def read_voltage(input_channel=0):
voltage
=
((
4.7
+
2.2
)
/
2.2
)
*
2
*
voltage
string
=
"
Voltage sens line {1} is {0:.4f} V
"
.
format
(
voltage
,
input_channel
)
print
(
string
)
else
:
stri
=
"
No ACK on device 0x{0:x}
"
.
format
(
addr
)
print
(
stri
)
def
read_temp
():
def
read_temp
(
self
):
#
# Function to read temperature of APSCT
#
# return value
#
Vref
=
3.0
addr
=
0x74
one_step
=
Vref
/
(
2
**
(
16
))
I2C_device
=
I2C
(
addr
,
BUSNR
=
I2CBUSNR
)
temp_slope
=
93.5E-6
*
2
**
(
16
+
1
)
/
Vref
sleep
(
1.0
)
I2C_device
.
write_bytes
(
0xA0
,
0xC0
)
self
.
dev_i2c_sensor
.
write_bytes
(
0xA0
,
0xC0
)
sleep
(
1.0
)
ret_ack
,
ret_value
=
I2C_device
.
read_last_reg
(
3
)
ret_ack
,
ret_value
=
self
.
dev_i2c_sensor
.
read_last_reg
(
3
)
if
ret_ack
:
raw_value
=
(
int
(
ret_value
,
16
)
&
0x1FFFFF
)
>>
6
temperature_K
=
(
raw_value
/
temp_slope
)
...
...
@@ -295,68 +374,3 @@ def read_temp():
else
:
print
(
"
Error reading tempeature
"
)
def
read_lol
(
pll_frequency
=
'
200MHz
'
):
I2C_IO_device_A
=
I2C
(
0x20
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_A
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
I2C_IO_device_A
.
write_bytes
(
0x07
,
0x00
)
# '0' is output
I2C_IO_device_B
=
I2C
(
0x21
,
BUSNR
=
I2CBUSNR
)
I2C_IO_device_B
.
write_bytes
(
0x06
,
0x2C
)
# '0' is output
I2C_IO_device_B
.
write_bytes
(
0x07
,
0xFF
)
# '0' is output
ack
,
ret_value
=
I2C_IO_device_B
.
read_bytes
(
0x01
,
1
)
status_reg
=
int
(
ret_value
,
16
)
if
(
pll_frequency
==
'
200MHz
'
)
&
((
status_reg
&
0x10
)
>
0
):
print
(
"
lost lock 200MHz
"
)
if
((
status_reg
&
0x20
)
>
0
)
&
(
pll_frequency
==
'
160MHz
'
):
print
(
"
lost lock 160MHz
"
)
ack
,
ret_value
=
I2C_IO_device_A
.
read_bytes
(
0x01
,
1
)
old_reg
=
int
(
ret_value
,
16
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
(
old_reg
|
0x10
))
# '0' is output
sleep
(
1
)
I2C_IO_device_A
.
write_bytes
(
0x03
,
(
old_reg
&
0xEF
))
# '0' is output
#if READ_REGS:
# read_all_regs_pll(CLK_FREQ)
read_temp
()
if
CHECK_EEPROM
:
wr_rd_eeprom
()
if
PWR_RST
:
power
(
False
)
sleep
(
10
)
power
(
True
)
if
SET_PLL
:
setup_pll
(
CLK_FREQ
)
if
READ_LOCK
:
if
CLK_FREQ
==
'
160MHz
'
:
pll_addr
=
PLL_160M
else
:
pll_addr
=
PLL_200M
ret_value
=
Read_byte_PLL
(
0x00
,
nof_bytes
=
1
,
ADDRESS
=
pll_addr
)
status_pll
=
int
(
ret_value
,
2
)
if
status_pll
==
0x04
:
print
(
"
PLL in lock
"
)
elif
(
status_pll
&
0x10
)
>
0
:
print
(
"
Not Locked --> No 10 MHz ref
"
)
else
:
print
(
"
Not locked --> PLL Error
"
)
if
READ_REGS
:
read_all_regs_pll
(
CLK_FREQ
)
if
READ_ALL
:
read_all_regs_pll
(
CLK_FREQ
)
read_IO_expanderis
()
if
READ_SENSOR
:
apsct_sensors
()
read_lol
(
CLK_FREQ
)
This diff is collapsed.
Click to expand it.
production_apsct.py
0 → 100644
+
59
−
0
View file @
1676306e
"""
Copyright 2021 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
ASTRON Netherlands Institute for Radio Astronomy
Licensed under the Apache License, Version 2.0 (the
"
License
"
);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an
"
AS IS
"
BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Set APSCT_CLK
"""
import
time
import
apsct_lib
DEBUG
=
False
SET_PLL
=
True
READ_LOCK
=
True
READ_ALL
=
True
CHECK_EEPROM
=
False
PWR_RST
=
False
# True
READ_SENSOR
=
False
# True
READ_REGS
=
False
# True
CLK_FREQ
=
'
200MHz
'
apsct
=
apsct_lib
.
ApsctClass
()
apsct
.
sensors
.
read_temp
()
if
CHECK_EEPROM
:
apsct
.
eeprom
.
wr_rd_eeprom
()
if
PWR_RST
:
apsct
.
power
(
False
)
time
.
sleep
(
10
)
apsct
.
power
(
True
)
if
SET_PLL
:
apsct
.
set_apsct
(
CLK_FREQ
)
if
READ_LOCK
:
apsct
.
pll_200
.
read_lol
()
if
READ_REGS
:
apsct
.
pll_200
.
read_all_regs_pll
()
if
READ_ALL
:
apsct
.
pll_200
.
read_all_regs_pll
()
apsct
.
pll_160
.
read_all_regs_pll
()
apsct
.
read_IO_expanderis
()
if
READ_SENSOR
:
apsct
.
sensors
.
apsct_sensors
()
apsct
.
pll_200
.
read_lol
(
CLK_FREQ
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment