Skip to content

Commit f1c3542

Browse files
Set TX7332 Default Clock to 10MHz (#75)
* some new test scripts for dfu mode and update tx7332 bfclk to be 10MHz by default * checking in scripts
1 parent e5aabbf commit f1c3542

File tree

6 files changed

+271
-2
lines changed

6 files changed

+271
-2
lines changed
File renamed without changes.

notebooks/test_transmitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
print("Set Trigger")
4949
json_trigger_data = {
50-
"TriggerFrequencyHz": 25,
50+
"TriggerFrequencyHz": 10,
5151
"TriggerMode": 1,
5252
"TriggerPulseCount": 0,
5353
"TriggerPulseWidthUsec": 20000

notebooks/test_transmitter2.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
import numpy as np
6+
7+
from openlifu.bf.pulse import Pulse
8+
from openlifu.bf.sequence import Sequence
9+
from openlifu.geo import Point
10+
from openlifu.io.LIFUInterface import LIFUInterface
11+
from openlifu.plan.solution import Solution
12+
13+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
14+
# python notebooks/test_transmitter2.py
15+
"""
16+
Test script to automate:
17+
1. Connect to the device.
18+
2. Test HVController: Turn HV on/off and check voltage.
19+
3. Test Device functionality.
20+
"""
21+
print("Starting LIFU Test Script...")
22+
23+
interface = LIFUInterface()
24+
tx_connected, hv_connected = interface.is_device_connected()
25+
26+
if not tx_connected:
27+
print("TX device not connected. Attempting to turn on 12V...")
28+
sys.exit(1)
29+
30+
print("Ping Transmitter device")
31+
interface.txdevice.ping()
32+
33+
print("Get Version")
34+
version = interface.txdevice.get_version()
35+
print(f"Version: {version}")
36+
print("Get Temperature")
37+
temperature = interface.txdevice.get_temperature()
38+
print(f"Temperature: {temperature} °C")
39+
40+
print("Enumerate TX7332 chips")
41+
num_tx_devices = interface.txdevice.enum_tx7332_devices()
42+
if num_tx_devices > 0:
43+
print(f"Number of TX7332 devices found: {num_tx_devices}")
44+
else:
45+
raise Exception("No TX7332 devices found.")
46+
47+
# set focus
48+
xInput = 0
49+
yInput = 0
50+
zInput = 50
51+
52+
frequency = 400e3
53+
voltage = 12.0
54+
duration = 2e-5
55+
56+
pulse = Pulse(frequency=frequency, amplitude=voltage, duration=duration)
57+
pt = Point(position=(xInput,yInput,zInput), units="mm")
58+
sequence = Sequence(
59+
pulse_interval=0.1,
60+
pulse_count=10,
61+
pulse_train_interval=1,
62+
pulse_train_count=1
63+
)
64+
65+
# Calculate delays and apodizations to perform beam forming
66+
67+
solution = Solution(
68+
delays = np.zeros((1,64)),
69+
apodizations = np.ones((1,64)),
70+
pulse = pulse,
71+
sequence = sequence
72+
)
73+
74+
sol_dict = solution.to_dict()
75+
profile_index = 1
76+
profile_increment = True
77+
print("Set Solution")
78+
interface.txdevice.set_solution(
79+
pulse = sol_dict['pulse'],
80+
delays = sol_dict['delays'],
81+
apodizations= sol_dict['apodizations'],
82+
sequence= sol_dict['sequence'],
83+
mode = "continuous",
84+
profile_index=profile_index,
85+
profile_increment=profile_increment
86+
)
87+
88+
print("Get Trigger")
89+
trigger_setting = interface.txdevice.get_trigger_json()
90+
if trigger_setting:
91+
print(f"Trigger Setting: {trigger_setting}")
92+
else:
93+
print("Failed to get trigger setting.")
94+
95+
print("Starting Trigger...")
96+
if interface.txdevice.start_trigger():
97+
print("Trigger Running Press enter to STOP:")
98+
input() # Wait for the user to press Enter
99+
if interface.txdevice.stop_trigger():
100+
print("Trigger stopped successfully.")
101+
else:
102+
print("Failed to stop trigger.")
103+
else:
104+
print("Failed to get trigger setting.")

notebooks/test_tx_dfu.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
import time
5+
6+
from openlifu.io.LIFUInterface import LIFUInterface
7+
8+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
9+
# python notebooks/test_tx_dfu.py
10+
11+
print("Starting LIFU Test Script...")
12+
interface = LIFUInterface()
13+
tx_connected, hv_connected = interface.is_device_connected()
14+
15+
if not hv_connected:
16+
print("✅ LIFU Console not connected.")
17+
sys.exit(1)
18+
19+
if not tx_connected:
20+
print("TX device not connected. Attempting to turn on 12V...")
21+
interface.hvcontroller.turn_12v_on()
22+
23+
# Give time for the TX device to power up and enumerate over USB
24+
time.sleep(2)
25+
26+
# Cleanup and recreate interface to reinitialize USB devices
27+
interface.stop_monitoring()
28+
del interface
29+
time.sleep(5) # Short delay before recreating
30+
31+
print("Reinitializing LIFU interface after powering 12V...")
32+
interface = LIFUInterface()
33+
34+
# Re-check connection
35+
tx_connected, hv_connected = interface.is_device_connected()
36+
37+
if tx_connected and hv_connected:
38+
print("✅ LIFU Device fully connected.")
39+
else:
40+
print("❌ LIFU Device NOT fully connected.")
41+
print(f" TX Connected: {tx_connected}")
42+
print(f" HV Connected: {hv_connected}")
43+
sys.exit(1)
44+
45+
46+
print("Ping the device")
47+
if not interface.txdevice.ping():
48+
print("❌ failed to communicate with transmit module")
49+
sys.exit(1)
50+
51+
print("Get Version")
52+
version = interface.txdevice.get_version()
53+
print(f"Version: {version}")
54+
55+
56+
# Ask the user for confirmation
57+
user_input = input("Do you want to Enter DFU Mode? (y/n): ").strip().lower()
58+
59+
if user_input == 'y':
60+
print("Enter DFU mode")
61+
if interface.txdevice.enter_dfu():
62+
print("Successful.")
63+
elif user_input == 'n':
64+
pass
65+
else:
66+
print("Invalid input. Please enter 'y' or 'n'.")

notebooks/test_tx_trigger.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
import time
5+
6+
from openlifu.io.LIFUInterface import LIFUInterface
7+
8+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
9+
# python notebooks/test_tx_trigger.py
10+
11+
def get_user_input():
12+
while True:
13+
print("\nEnter parameters (or 'x' to exit):")
14+
try:
15+
freq = input("Trigger Frequency (Hz): ")
16+
if freq.lower() == 'x':
17+
return None
18+
19+
pulse_width = input("Pulse Width (μs): ")
20+
if pulse_width.lower() == 'x':
21+
return None
22+
23+
return {
24+
"freq": float(freq),
25+
"pulse_width": float(pulse_width)
26+
}
27+
except ValueError:
28+
print("Invalid input. Please enter numbers or 'x' to exit.")
29+
30+
def main():
31+
print("Starting LIFU Test Script...")
32+
interface = LIFUInterface()
33+
tx_connected, hv_connected = interface.is_device_connected()
34+
35+
if not tx_connected and not hv_connected:
36+
print("✅ LIFU Console not connected.")
37+
sys.exit(1)
38+
39+
if not tx_connected:
40+
print("TX device not connected. Attempting to turn on 12V...")
41+
interface.hvcontroller.turn_12v_on()
42+
time.sleep(2)
43+
44+
interface.stop_monitoring()
45+
del interface
46+
time.sleep(3)
47+
48+
print("Reinitializing LIFU interface after powering 12V...")
49+
interface = LIFUInterface()
50+
tx_connected, hv_connected = interface.is_device_connected()
51+
52+
if tx_connected and hv_connected:
53+
print("✅ LIFU Device fully connected.")
54+
else:
55+
print("❌ LIFU Device NOT fully connected.")
56+
print(f" TX Connected: {tx_connected}")
57+
print(f" HV Connected: {hv_connected}")
58+
sys.exit(1)
59+
60+
print("Ping the device")
61+
if not interface.txdevice.ping():
62+
print("❌ Failed comms with txdevice.")
63+
sys.exit(1)
64+
65+
while True:
66+
params = get_user_input()
67+
if params is None:
68+
print("Exiting...")
69+
break
70+
71+
json_trigger_data = {
72+
"TriggerFrequencyHz": params["freq"],
73+
"TriggerPulseCount": 1,
74+
"TriggerPulseWidthUsec": params["pulse_width"],
75+
"TriggerPulseTrainInterval": 0,
76+
"TriggerPulseTrainCount": 0,
77+
"TriggerMode": 1,
78+
"ProfileIndex": 0,
79+
"ProfileIncrement": 0
80+
}
81+
82+
trigger_setting = interface.txdevice.set_trigger_json(data=json_trigger_data)
83+
84+
if trigger_setting:
85+
print(f"Trigger Setting: {trigger_setting}")
86+
else:
87+
print("Failed to set trigger setting.")
88+
continue
89+
90+
if interface.txdevice.start_trigger():
91+
print("Trigger Running. Press Enter to STOP:")
92+
input() # Wait for the user to press Enter
93+
if interface.txdevice.stop_trigger():
94+
print("Trigger stopped successfully.")
95+
else:
96+
print("Failed to stop trigger.")
97+
98+
if __name__ == "__main__":
99+
main()

src/openlifu/io/LIFUTXDevice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
MAX_REPEAT = 2**5-1
9595
MAX_ELASTIC_REPEAT = 2**16-1
9696
DEFAULT_TAIL_COUNT = 29
97-
DEFAULT_CLK_FREQ = 64e6
97+
DEFAULT_CLK_FREQ = 10e6
9898
ProfileOpts = Literal['active', 'configured', 'all']
9999
TriggerModeOpts = Literal['sequence', 'continuous','single']
100100
TRIGGER_MODE_SEQUENCE = 0

0 commit comments

Comments
 (0)