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
f0c89056
Commit
f0c89056
authored
Dec 9, 2020
by
Gijs Schoonderbeek
Browse files
Options
Downloads
Patches
Plain Diff
Added set RCU2 version to run from PCC-CTRL
parent
5fcf7f9c
No related branches found
No related tags found
1 merge request
!2
Modified the scripts to run on Raspberry Pi.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
set_rcu2_via_PCC.py
+253
-0
253 additions, 0 deletions
set_rcu2_via_PCC.py
with
253 additions
and
0 deletions
set_rcu2_via_PCC.py
0 → 100644
+
253
−
0
View file @
f0c89056
'''
Set RCU2 via PCC
'''
import
sys
import
time
sys
.
path
.
insert
(
0
,
'
.
'
)
from
I2C_serial
import
*
sleep_time
=
0.05
CHECK_I2C_DEVICES
=
True
PWR_RST
=
False
SET_ADC
=
True
CS
=
0
SCLK
=
[
1
,
3
,
5
]
SDIO
=
[
0
,
2
,
4
]
ADC_ORDER
=
[
0
,
1
,
2
]
def
set_switch
(
addr_switch
,
RCU_nr
):
I2C_device
=
I2C
(
addr_switch
)
I2C_device
.
write_pointer
(
1
<<
RCU_nr
)
def
blink_led
(
address
=
0x76
,
times
=
5
):
print
(
"
Blink LED
"
)
I2C_device
=
I2C
(
address
)
I2C_device
.
write_bytes
(
0x06
,
00
)
I2C_device
.
write_bytes
(
0x07
,
00
)
for
cnt
in
range
(
times
):
I2C_device
.
write_bytes
(
0x03
,
0x40
)
sleep
(
0.5
)
I2C_device
.
write_bytes
(
0x03
,
0x80
)
sleep
(
0.5
)
I2C_device
.
write_bytes
(
0x03
,
0x40
)
def
Write_byte_ADC
(
ADC_reg_address
,
ADC_data
,
ADC_bytes
=
0
,
ADC_NR
=
0
,
ADDRESS
=
0x20
):
#
# Write Byte to the ADC
#
I2C_device
=
I2C
(
ADDRESS
)
ADC_rw
=
0x00
# 0 for write, 1 for read
stri
=
"
Write : {0:2x} to Address : {1:2x}
"
.
format
(
ADC_data
,
ADC_reg_address
)
print
(
stri
)
I2C_device
.
write_bytes
(
0x06
,
00
)
I2C_device
.
write_bytes
(
0x07
,
00
)
data
=
(
ADC_rw
<<
23
)
+
(
ADC_bytes
<<
21
)
+
(
ADC_address
<<
8
)
+
ADC_data
bit_array
=
"
{0:{fill}24b}
"
.
format
(
data
,
fill
=
'
0
'
)
I2C_device
.
write_bytes
(
0x03
,
(
0x0F
^
(
1
<<
ADC_NR
)))
for
bit
in
bit_array
:
for
clk
in
range
(
2
):
Write_data
=
0x00
|
(
clk
<<
SCLK
[
ADC_NR
])
|
(
int
(
bit
)
<<
SDIO
[
ADC_NR
])
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
# sleep(sleep_time)
Write_data
=
(
0x00
|
(
0
<<
SCLK
[
ADC_NR
])
|
(
0
<<
SDIO
[
ADC_NR
]
))
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
I2C_device
.
write_bytes
(
0x03
,
0x0F
)
def
Read_byte_ADC
(
ADC_reg_address
,
ADC_bytes
=
0
,
ADC_NR
=
0
,
ADDRESS
=
0x20
):
#
# Read Byte from the ADC
#
I2C_device
=
I2C
(
ADDRESS
)
ADC_rw
=
0x01
# 0 for write, 1 for read
stri
=
"
Read ADC from Address {:8x}
"
.
format
(
ADC_reg_address
)
print
(
stri
)
data
=
(
ADC_rw
<<
15
)
+
(
ADC_bytes
<<
13
)
+
ADC_reg_address
# print("write read command")
I2C_device
.
write_bytes
(
0x06
,
00
)
I2C_device
.
write_bytes
(
0x07
,
00
)
I2C_device
.
write_bytes
(
0x03
,
(
0x0F
^
(
0x01
<<
ADC_NR
)))
bit_array
=
"
{0:{fill}16b}
"
.
format
(
data
,
fill
=
'
0
'
)
for
bit
in
bit_array
:
for
clk
in
range
(
2
):
Write_data
=
0x00
|
(
clk
<<
SCLK
[
ADC_NR
])
|
(
int
(
bit
)
<<
SDIO
[
ADC_NR
]
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
# sleep(sleep_time)
I2C_device
.
write_bytes
(
0x03
,
0x0F
)
# print("read byte")
I2C_device
.
write_bytes
(
0x06
,
(
1
<<
SDIO
[
ADC_NR
]))
I2C_device
.
write_bytes
(
0x03
,
(
0x0F
^
(
0x01
<<
ADC_NR
)))
read_bit
=
''
for
cnt
in
range
(
8
*
(
ADC_bytes
+
1
)):
for
clk
in
[
1
,
0
]:
# Read after faling edge
Write_data
=
0x00
|
(
clk
<<
SCLK
[
ADC_NR
])
|
(
int
(
bit
)
<<
SDIO
[
ADC_NR
]
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
ret_ack
,
ret_value
=
I2C_device
.
read_bytes
(
0x00
,
1
)
if
ret_ack
:
read_bit
+=
str
((
int
(
ret_value
,
16
)
>>
SDIO
[
ADC_NR
])
&
0x01
)
else
:
print
(
"
ACK nok
"
)
I2C_device
.
write_bytes
(
0x03
,
0x0F
)
I2C_device
.
write_bytes
(
0x07
,
00
)
Write_data
=
0x00
|
(
0
<<
SCLK
[
ADC_NR
])
|
(
0
<<
SDIO
[
ADC_NR
]
)
I2C_device
.
write_bytes
(
0x02
,
Write_data
)
I2C_device
.
write_bytes
(
0x03
,
0x0F
)
stri
=
"
Read back data is: {0:2x}
"
.
format
(
int
(
read_bit
,
2
))
print
(
stri
)
return
read_bit
;
def
rcu_sensors
():
addr
=
0x14
Vref
=
3.3
one_step
=
Vref
/
(
2
**
(
16
+
1
))
I2C_device
=
I2C
(
addr
)
I2C_device
.
write_bytes
(
0xB8
,
0xB0
)
sleep
(
1
)
ret_ack
,
ret_value
=
I2C_device
.
read_last_reg
(
3
)
if
ret_ack
:
stri
=
"
Return value input 0 : 0x{0}
"
.
format
(
ret_value
)
print
(
stri
)
if
int
(
ret_value
,
16
)
>=
0xC00000
:
print
(
"
over range
"
)
else
:
steps
=
(
int
(
ret_value
,
16
)
&
0x1FFFFF
)
>>
6
voltage
=
one_step
*
steps
string
=
"
Voltage is {0:.4f}
"
.
format
(
voltage
)
print
(
string
)
else
:
print
(
"
ACK nok
"
)
sleep
(
1
)
temp_slope
=
93.5E-6
*
2
**
(
16
+
1
)
/
Vref
I2C_device
.
write_bytes
(
0xA0
,
0xE0
)
sleep
(
1
)
ret_ack
,
ret_value
=
I2C_device
.
read_last_reg
(
3
)
if
ret_ack
:
raw_value
=
(
int
(
ret_value
,
16
)
&
0x1FFFFF
)
>>
6
temperature_K
=
(
raw_value
/
temp_slope
)
temperature
=
temperature_K
-
273
stri
=
"
Return value : 0x{0} Temperature : {1:.2f} gr. C
"
.
format
(
ret_value
,
temperature
)
print
(
stri
)
else
:
print
(
"
ACK nok
"
)
def
rw_eeprom
(
value
=
0xAB
):
ADDR
=
0x50
I2C_eeprom
=
I2C
(
0x53
)
I2C_eeprom
.
write_bytes
(
0x00
,
value
)
I2C_eeprom
.
write_pointer
(
0x00
)
ret_ack
,
ret_value
=
I2C_eeprom
.
read_last_reg
(
1
)
if
ret_ack
:
stri
=
"
EEPROM readback : {0}
"
.
format
(
ret_value
)
print
(
stri
)
else
:
print
(
"
ACK nok
"
)
def
power
(
state
):
ADDRESS_IO
=
0x76
I2C_IO_device
=
I2C
(
ADDRESS_IO
)
I2C_IO_device
.
write_bytes
(
0x06
,
00
)
I2C_IO_device
.
write_bytes
(
0x07
,
00
)
if
state
:
bits_to_set
=
0x40
else
:
bits_to_set
=
0x0
I2C_IO_device
.
write_bytes
(
0x02
,
bits_to_set
)
def
set_gain
(
gain
,
channel
):
string
=
"
Set Channel {0} to a gain of {1} dB
"
.
format
(
channel
,
gain
)
print
(
string
)
if
channel
<=
1
:
ADDRESS_IO
=
0x75
max_gain
=
15
min_gain
=
-
6
elif
channel
<=
2
:
ADDRESS_IO
=
0x76
max_gain
=
20
min_gain
=
-
4
else
:
print
(
"
wrong channel number 0 <= Channel <= 2 channel set to 2
"
)
channel
=
2
ADDRESS_IO
=
0x76
max_gain
=
20
min_gain
=
-
4
if
min_gain
<=
gain
<=
max_gain
:
set_gain
=
max_gain
-
gain
else
:
set_gain
=
max_gain
-
min_gain
bits_to_set
=
set_gain
I2C_IO_device
=
I2C
(
ADDRESS_IO
)
I2C_IO_device
.
write_bytes
(
0x06
,
00
)
I2C_IO_device
.
write_bytes
(
0x07
,
00
)
if
channel
==
0
:
I2C_IO_device
.
write_bytes
(
0x02
,
bits_to_set
)
elif
channel
==
1
:
I2C_IO_device
.
write_bytes
(
0x03
,
bits_to_set
)
elif
channel
==
2
:
I2C_IO_device
.
write_bytes
(
0x02
,
bits_to_set
|
0x40
)
else
:
print
(
"
no update done
"
)
set_switch
(
0x70
,
1
)
if
PWR_RST
:
power
(
False
)
sleep
(
1
)
power
(
True
)
if
CHECK_I2C_DEVICES
:
blink_led
(
address
=
0x76
,
times
=
6
)
rw_eeprom
(
0xAC
)
rcu_sensors
()
for
cnt
in
range
(
3
):
if
SET_ADC
:
ADC_address
=
0x3A
# see address table
ADC_data
=
0x00
# 8 bits data
ADC_bytes
=
0x00
# 00 / 11 + 1 bytes
ADCNR
=
ADC_ORDER
[
cnt
]
set_gain
(
10
,
ADCNR
)
stri
=
"
Set channel {}
"
.
format
(
ADCNR
)
print
(
stri
)
# Check ADC is in lock
Read_byte_ADC
(
0x0A
,
ADC_NR
=
ADCNR
)
#PLL Status expt. 0x81h (129 dec)
Read_byte_ADC
(
0x09
,
ADC_NR
=
ADCNR
)
# Global Clock Def. 0x01
if
PWR_RST
:
Write_byte_ADC
(
0x08
,
0x35
,
ADC_NR
=
ADCNR
)
# Power down
Write_byte_ADC
(
0x08
,
0x00
,
ADC_NR
=
ADCNR
)
# Power up
if
0
:
Write_byte_ADC
(
0x0D
,
0x05
,
ADC_NR
=
ADCNR
)
# PN sequence long
# Write_byte_ADC(0x0D, 0x06, ADC_NR = ADCNR) # PN sequence short
# Write_byte_ADC(0x0D, 0x0F, ADC_NR = ADCNR) # ramp generation
Write_byte_ADC
(
0xFF
,
0x01
,
ADC_NR
=
ADCNR
)
# transfer settings
if
1
:
Write_byte_ADC
(
0x61
,
0x13
,
ADC_NR
=
ADCNR
)
# JESD_Test mode 10 bit PN23
# Write_byte_ADC(0x60, 0x00, ADC_NR = ADCNR) # Invert transmit bits = off (ON JESD_UB2)
Write_byte_ADC
(
0x5F
,
0x14
,
ADC_NR
=
ADCNR
)
# ILAS normal mode standard value
Write_byte_ADC
(
0x15
,
0x07
,
ADC_NR
=
ADCNR
)
# ILAS normal mode standard value
Write_byte_ADC
(
0xFF
,
0x01
,
ADC_NR
=
ADCNR
)
# transfer settings
if
READ_BYTE
:
Read_byte_ADC
(
0x0A
,
ADC_NR
=
ADCNR
)
Read_byte_ADC
(
0x79
,
ADC_NR
=
ADCNR
)
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