-
Notifications
You must be signed in to change notification settings - Fork 0
/
waveform-gen-controller.py
66 lines (49 loc) · 1.55 KB
/
waveform-gen-controller.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
#!/usr/bin/env python3
import sys
import serial
import struct
from tqdm import tnrange, tqdm_notebook
import time
# We start by configuring the path to the serial fpga of the FPGA.
# Note that the Cmod A7 shows up as two serial ports,
# you can figure out which one is the right one by trial and error.
SERIAL_fpga = sys.argv[1]
SERIAL_tx1 = sys.argv[2]
fpga = serial.Serial(SERIAL_fpga, baudrate=115200)
# tx1 = serial.Serial(SERIAL_tx1, baudrate=115200, timeout=0.02)
CMD_SET_PERIOD = 66
CMD_SET_GLITCH_PULSE = 67
def cmd(fpga, command):
fpga.write(chr(command).encode("ASCII"))
def cmd_uint32(fpga, command, u32):
fpga.write(chr(command).encode("ASCII"))
data = struct.pack(">L", u32)
fpga.write(data)
def cmd_uint8(fpga, command, u8):
fpga.write(chr(command).encode("ASCII"))
data = struct.pack("B", u8)
fpga.write(data)
def cmd_read_uint8(fpga, command):
fpga.write(chr(command).encode("ASCII"))
return fpga.read(1)[0]
def cmd_read_uint32(fpga, command):
fpga.write(chr(command).encode("ASCII"))
return fpga.read(4)
def setup(period, pulse):
# 1 == 10ns
cmd_uint32(fpga, CMD_SET_PERIOD, period)
cmd_uint32(fpga, CMD_SET_GLITCH_PULSE, pulse)
def bf_pulse():
for pulse in range(PULSE_FROM, PULSE_TO, PULSE_STEP):
print(f"current pulse: {pulse}")
setup(PERIOD, pulse)
time.sleep(PERIOD * 10 / 100000000)
GLITCH_PULSE = 1190
# 100 == 1us
PERIOD = 500000000
PULSE_FROM = 250
PULSE_TO = 500
PULSE_STEP = 10
if __name__ == "__main__":
setup(PERIOD, GLITCH_PULSE)
# bf_pulse()