Last active
April 6, 2018 15:44
-
-
Save nedos/ecc4132bbf2cd9eb6769caaeb6ab38e1 to your computer and use it in GitHub Desktop.
This script parses a saleae csv export to generate a verilog simulation file (in picoseconds)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import csv | |
def print_usage(): | |
print "Usage: {} <csv_file>".format(sys.argv[0]) | |
if len(sys.argv) != 2: | |
print "Not enough arguments" | |
print_usage() | |
exit(1) | |
input_file = sys.argv[1] | |
if input_file[-4:] != ".csv": | |
print "Requires csv file" | |
print_usage() | |
exit(1) | |
with open(input_file, 'rb') as csvfile: | |
rows = csv.reader(csvfile, delimiter=',') | |
values = [] | |
current_time = 0; | |
for row in rows: | |
time_diff = float(row[0]) - current_time | |
current_time = float(row[0]) # update current time | |
time = int(time_diff * 1e12) # convert to picoseconds | |
#print time_diff | |
#print time | |
current_time = float(row[0]) | |
bit = int(row[1]) | |
values.append([time,bit]) | |
print values | |
f = open('{}.v'.format(input_file[:-4]), 'w') | |
for value in values: | |
string = "#{:d} {} <= 1'b{:d};\n".format(value[0], input_file[:-4], value[1]) | |
print string | |
f.write(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment