-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
91 lines (74 loc) · 2.6 KB
/
Copy pathmain.py
File metadata and controls
91 lines (74 loc) · 2.6 KB
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
import math
import os
import pyvisa
import time
import pandas as pd
def setup_devices():
print("Setting parameters on devices..")
mm.write('*RST')
ps.write('*RST')
time.sleep(5);
ps.write(f"FREQ {start_freq}")
ps.write(f"VOLT {amplitude_psu}")
ps.write("OUTP ON")
mm.write("VOLTage:AC:RANGe:AUTO 1")
print(mm.query('Measure:voltage:ac?'))
def measure_range(start_f,stop_f):
current_freq = start_f
frequencies_temp = []
voltages_temp = []
index = 0
while(current_freq < stop_f):
frequencies_temp.append(float(current_freq))
print(frequencies_temp[index].__str__()+ "Hz")
ps.write(f"FREQ {current_freq}")
time.sleep(settling_time_psu)
voltages_temp.append(float(mm.query('Measure:voltage:ac?'))*math.sqrt(2)) #to get amplitude
print(voltages_temp[index].__str__() + "V")
current_freq *=freq_multiplyer
time.sleep(delay_between_measurements)
index +=1
return frequencies_temp,voltages_temp
def measure_bodeplot():
print("Starting bodeplot measurement..")
frequencies, voltages = measure_range(start_freq,stop_freq)
voltages_db = []
index = 0
for voltage in voltages:
voltages_db.append(20*math.log10(voltage/(amplitude_psu/2)))
print(voltages_db[index].__str__() + "VdB")
index +=1
df = pd.DataFrame()
df["Frequencies"] = frequencies
df["Voltages"] = voltages
df["Voltages_db"] = voltages_db
df.to_csv(file_name,sep="\t")# andere delimiter? voor komma problemen
ps.write("OUTP OFF")
print("Finished!")
if __name__ == "__main__":
file_name = 'bodeplot_1.csv'
if os.path.exists(file_name):
print('The file name you choose already exists!')
exit()
delay_between_measurements = 1 # delay between measurments
settling_time_psu = 2.5
start_freq = 100 # Hz
stop_freq = 500000 # Hz
amplitude_psu = 0.1 #this is peak to peak value
freq_multiplyer = 1.2
rm = pyvisa.ResourceManager()
print("List of available devices: " + rm.list_resources().__str__())
try:
mm = rm.open_resource('ASRL8::INSTR')
print("Multimeter: " + mm.query("*IDN?"))
except:
print("The multimeter isnt connected or couldnt be identified!")
exit()
try:
ps = rm.open_resource('ASRL9::INSTR')
print("Powersupply: " + ps.query("*IDN?"))
except:
print("The powersupply isnt connected or couldnt be identified!")
exit()
setup_devices()
measure_bodeplot()