Skip to content
GitLab
Explore
Sign in
Register
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
python_test_scripts
Commits
9d5dc319
Commit
9d5dc319
authored
Jan 23, 2023
by
Gijs Schoonderbeek
Browse files
Options
Downloads
Patches
Plain Diff
Version used for prodution run L2TS, 4 boards
parent
08aa6505
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
APSPU_I2C.py
+3
-3
3 additions, 3 deletions
APSPU_I2C.py
I2C_serial_pi3.py
+146
-0
146 additions, 0 deletions
I2C_serial_pi3.py
apspu_lib.py
+14
-10
14 additions, 10 deletions
apspu_lib.py
with
163 additions
and
13 deletions
APSPU_I2C.py
+
3
−
3
View file @
9d5dc319
...
...
@@ -37,9 +37,9 @@ VOUT_POLS = {"CTR_LBA": 8.0,
"
CTR_RCU2_A
"
:
5.60009765625
,
"
CTR_RCU2_D
"
:
3.2998046875
}
IOUT_POLS
=
{
"
CTR_LBA
"
:
0.
45
,
"
CTR_RCU2_A
"
:
0.
7
,
"
CTR_RCU2_D
"
:
0.
3
}
IOUT_POLS
=
{
"
CTR_LBA
"
:
0.
2
,
"
CTR_RCU2_A
"
:
0.
6
,
"
CTR_RCU2_D
"
:
0.
2
}
LP_VIN
=
0x88
LP_VOUT_MODE
=
0x20
...
...
This diff is collapsed.
Click to expand it.
I2C_serial_pi3.py
0 → 100644
+
146
−
0
View file @
9d5dc319
'''
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.
I2C_serial_Pi
Started by Gijs
Class for using the I2C bus of the I2C. This class is used for the
basic I2C scripts to read and write the RCU2, PCC etc.
'''
import
smbus2
import
sys
from
time
import
*
DEBUG
=
False
#True
SLOW
=
False
class
I2C
:
def
__init__
(
self
,
ADDRESS
=
'
040
'
,
BUSNR
=
3
):
self
.
I2C_Address
=
ADDRESS
self
.
bus_nr
=
BUSNR
def
close
(
self
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
bus
.
close
()
return
True
def
open
(
self
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
bus
.
open
(
self
.
bus_nr
)
return
True
def
read_bytes
(
self
,
register
,
bytes_to_read
=
2
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
try
:
rd_value
=
bus
.
read_i2c_block_data
(
self
.
I2C_Address
,
register
,
bytes_to_read
)
ret_value
=
''
for
cnt
in
range
(
bytes_to_read
):
ret_value
+=
(
hex
(
rd_value
[
cnt
])[
2
:])
ret_ack
=
1
if
SLOW
:
sleep
(
0.2
)
except
IOError
:
ret_ack
=
0
ret_value
=
'
ffff
'
if
DEBUG
:
print
(
"
Reading IO-error
"
)
return
ret_ack
,
ret_value
def
read_last_reg
(
self
,
bytes_to_read
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
rd_value
=
[]
ret_value
=
''
for
cnt
in
range
(
bytes_to_read
):
try
:
rd_value
.
append
(
bus
.
read_byte
(
self
.
I2C_Address
))
ret_ack
=
1
if
SLOW
:
sleep
(
0.2
)
except
IOError
:
ret_ack
=
0
rd_value
.
append
(
0
)
if
DEBUG
:
print
(
"
IO-Reading error
"
)
for
cnt
in
range
(
bytes_to_read
):
ret_value
+=
(
hex
(
rd_value
[
cnt
])[
2
:])
return
ret_ack
,
ret_value
def
write_bytes
(
self
,
register
,
data
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
if
type
(
data
)
is
not
list
:
data
=
[
data
]
try
:
bus
.
write_i2c_block_data
(
self
.
I2C_Address
,
register
,
data
)
ret_ack
=
1
if
SLOW
:
sleep
(
0.3
)
except
IOError
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Write IO-error
"
)
return
ret_ack
def
write_register
(
self
,
register
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
try
:
bus
.
write_byte
(
self
.
I2C_Address
,
register
)
# print(f"Wrote {register:x}")
ret_ack
=
1
if
SLOW
:
sleep
(
0.3
)
except
IOError
:
ret_ack
=
0
ret_value
=
0
# if DEBUG:
print
(
"
Write IO-error
"
)
return
ret_ack
def
write_pointer
(
self
,
register
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
try
:
ret_value
=
bus
.
read_i2c_block_data
(
self
.
I2C_Address
,
register
,
1
)
ret_ack
=
1
if
SLOW
:
sleep
(
0.3
)
except
IOError
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
Write IO-error
"
)
return
ret_ack
def
ack_check
(
self
):
bus
=
smbus2
.
SMBus
(
self
.
bus_nr
)
try
:
print
(
"
check ACK
"
)
ret_value
=
bus
.
write_quick
(
self
.
I2C_Address
)
ret_ack
=
1
if
SLOW
:
sleep
(
0.3
)
except
IOError
:
ret_ack
=
0
ret_value
=
0
if
DEBUG
:
print
(
"
No ACK IO-Error
"
)
return
ret_ack
if
__name__
==
"
__main__
"
:
I2C_Device
=
I2C
(
0x40
)
I2C_Device
.
write_bytes
(
0x00
,
0x00
)
ret_ack
,
ret_value
=
I2C_Device
.
read_bytes
(
0x8C
,
2
)
print
(
ret_value
)
This diff is collapsed.
Click to expand it.
apspu_lib.py
+
14
−
10
View file @
9d5dc319
...
...
@@ -25,13 +25,13 @@ from APSPU_I2C import *
if
os
.
name
==
"
posix
"
:
from
I2C_serial_pi
import
*
from
I2C_serial_pi
3
import
*
else
:
from
I2C_serial
import
*
I2CBUSNR
=
1
# Bus used on the Pi
DEBUG
=
False
# Set True to print debug information on the screen
I_OK_MARGIN
=
0.5
# I_error in Amps
class
ApspuClass
:
#
...
...
@@ -308,12 +308,16 @@ class PolClass:
#
# return is always True
#
print
(
f
"
Store to NVM for POL
{
self
.
name
}
"
)
if
False
:
ret_ack
=
self
.
pol_dev
.
write_register
(
0x15
)
# command = f"i2cset -y 1 0x{CTR_POLS[self.name]:02X} 0x15 cp"
# print(command)
# os.system(command)
# os.system(command)
sleep
(
5
)
sleep
(
1
)
else
:
self
.
pol_dev
.
close
()
command
=
f
"
i2cset -y 1 0x
{
CTR_POLS
[
self
.
name
]
:
02
X
}
0x15 cp
"
os
.
system
(
command
)
os
.
system
(
command
)
self
.
pol_dev
.
open
()
return
True
def
read_vin
(
self
):
...
...
@@ -467,8 +471,8 @@ class PolClass:
check_ok
=
False
print
(
f
"
POL
{
self
.
name
:
10
}
TEMP not OK, expected
{
temp_low
}
C -
{
temp_high
}
C, measured
{
self
.
temp
}
C
"
)
return
check_ok
i_low
=
0.75
*
IOUT_POLS
[
self
.
name
]
i_high
=
1.25
*
IOUT_POLS
[
self
.
name
]
i_low
=
(
1
-
I_OK_MARGIN
)
*
IOUT_POLS
[
self
.
name
]
i_high
=
(
1
+
I_OK_MARGIN
)
*
IOUT_POLS
[
self
.
name
]
if
i_low
<
self
.
iout
<
i_high
:
check_ok
=
True
else
:
...
...
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