|
1 | | -#!/usr/bin/env python |
2 | | -# coding: utf-8 |
3 | | - |
4 | | -# author: Konstantin Pavlov |
5 | | - |
6 | | - |
7 | | -# boilerplate script to generate ASCII hex files to initialize RAMs in Verilog |
8 | | - |
9 | | -import math |
10 | | -import os |
11 | | - |
12 | | -# settings ===================================================================== |
13 | | -N = 128 |
14 | | -tablename = "sin" |
15 | | -filename = tablename + ".hex" |
16 | | - |
17 | | -# main ========================================================================= |
18 | | -if os.path.exists(filename): |
19 | | - os.remove(filename) |
20 | | - print("Old file version removed") |
21 | | - |
22 | | -f = open(filename, "x") |
23 | | -f.write("// ascii hex file for " + tablename + " function\n\n") |
24 | | - |
25 | | -for i in range(0, N): |
26 | | - # computing and scaling |
27 | | - rad = math.pi/4/N*i |
28 | | - val = math.floor(math.sin(rad) * 256) |
29 | | - # formatting to HEX string of specified length |
30 | | - val_str = format(val, "#06x") |
31 | | - # additional prefix |
32 | | - prefix_str = format(i, "#04x") |
33 | | - # cutting '0x' prefix away |
34 | | - f.write(prefix_str[2:] + "_" + val_str[2:] + "\n") |
35 | | - |
36 | | -f.close() |
37 | | - |
| 1 | +#!/usr/bin/env python |
| 2 | +# coding: utf-8 |
| 3 | + |
| 4 | +# author: Konstantin Pavlov |
| 5 | +# published as part of https://github.com/pConst/basic_verilog |
| 6 | + |
| 7 | + |
| 8 | +# boilerplate script to generate ASCII hex files to initialize RAMs in Verilog |
| 9 | + |
| 10 | +import math |
| 11 | +import os |
| 12 | + |
| 13 | +# settings ===================================================================== |
| 14 | +N = 1024 |
| 15 | +tablename = "1024sin" |
| 16 | +filename = tablename + ".mem" |
| 17 | + |
| 18 | +# main ========================================================================= |
| 19 | +if os.path.exists(filename): |
| 20 | + os.remove(filename) |
| 21 | + print("Old file version removed") |
| 22 | + |
| 23 | +f = open(filename, "x") |
| 24 | +#f.write("// ascii hex file for " + tablename + " function\n\n") |
| 25 | + |
| 26 | +for i in range(0, N): |
| 27 | + # computing and scaling |
| 28 | + rad = math.pi/4/N*i |
| 29 | + val = round(math.sin(rad) * 65535) |
| 30 | + # formatting to HEX string of specified length |
| 31 | + val_str = format(val, "#06x") |
| 32 | + # additional prefix |
| 33 | + prefix_str = format(i, "#06x") |
| 34 | + # cutting '0x' prefix away |
| 35 | + f.write(prefix_str[2:] + "_" + val_str[2:] + "\n") |
| 36 | + |
| 37 | +f.close() |
| 38 | + |
0 commit comments