-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
133 lines (98 loc) · 2.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
""""""
"""
Created on Sat Jun 26 00:10:56 2021
@author: Nicolas Striebig
"""
import binascii
from modules.asic import Asic
from modules.injectionboard import Injectionboard
from modules.nexysio import Nexysio
from modules.voltageboard import Voltageboard
from modules.decode import Decode
from utils.utils import wait_progress
def main():
nexys = Nexysio()
# Open FTDI Device with Index 0
# handle = nexys.open(0)
handle = nexys.autoopen()
# Write and read directly to register
# Example: Write 0x55 to register 0x09 and read it back
nexys.write_register(0x09, 0x55, True)
nexys.read_register(0x09)
#
# Configure ASIC
#
# Write to asicSR
asic = Asic(handle)
asic.load_conf_from_yaml(3, "testconfig_v3")
# asic.asic_config['idacs']['vncomp'] = 60
asic.write_conf_to_yaml("testconfig_v3_write")
# asic.load_conf_from_yaml(2,"testconfig_write")
asic.enable_ampout_col(5)
asic.enable_inj_col(5)
asic.enable_inj_row(0)
asic.enable_pixel(5, 0)
asic.update_asic()
# Example: Update Config Bit
# asic.digitalconfig['En_Inj17'] = 1
# asic.dacs['vn1'] = 63
# asic.update_asic()
#
# Configure Voltageboard
#
# Configure 8 DAC Voltageboard in Slot 4 with list values
# 3 = Vcasc2, 4=BL, 7=Vminuspix, 8=Thpix
vboard1 = Voltageboard(handle, 4, (8, [0, 0, 1.1, 1, 0, 0, 0.7, 1.05]))
# Set measured 1V for one-point calibration
vboard1.vcal = 0.989
vboard1.vsupply = 2.8
# Update voltageboards
vboard1.update_vb()
# Write only first 3 DACs, other DACs will be 0
# vboard1.dacvalues = (8, [1.2, 1, 1])
# vboard1.update_vb()
#
# Configure Injectionboard
#
inj = Injectionboard(handle, 3)
# Set Injection Params for 330MHz patgen clock
inj.period = 100
inj.clkdiv = 4000
inj.initdelay = 10000
inj.cycle = 0
inj.pulsesperset = 1
inj.vcal = vboard1.vcal
inj.vsupply = vboard1.vsupply
inj.amplitude = 0.3
#
# SPI
#
# Enable SPI
nexys.spi_enable()
nexys.spi_reset()
# Set SPI clockdivider
# freq = 100 MHz/spi_clkdiv
nexys.spi_clkdiv = 255
# Generate bitvector for SPI ASIC config
# asic_bitvector = asic.gen_asic_vector()
# spi_data = nexys.asic_spi_vector(asic_bitvector, True, 10)
# Write Config via spi
# nexys.write_spi(spi_data, False, 8191)
# Send Routing command
nexys.send_routing_cmd()
# Reset SPI Read FIFO
nexys.spi_reset()
inj.start()
wait_progress(3)
# Read max. 10 times or until read FIFO is empty
readout = nexys.read_spi_fifo(10)
print(binascii.hexlify(readout))
decode = Decode()
list_hits = decode.hits_from_readoutstream(readout)
print(decode.decode_astropix2_hits(list_hits))
inj.stop()
# Close connection
nexys.close()
if __name__ == "__main__":
main()