OpenCores
URL https://opencores.org/ocsvn/pipelined_fft_128/pipelined_fft_128/trunk

Subversion Repositories pipelined_fft_128

[/] [pipelined_fft_128/] [trunk/] [TB/] [sinerom128_gen.pl] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 unicore
 
2
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
#
4
# Copyright(c) 2009 by Unicore Systems. All rights reserved
5
#
6
# DESIGN           :    FFT128_core
7
# FILENAME              :        sinerom64_gen.pl
8
# CREATED               :        10.1:2008
9
# MODIFIED              :       
10
# VERSION                       :       1.0
11
#
12
# AUTHORS:      Anatolij Sergiyenko.
13
# HISTORY       :       
14
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            
15
# DESCRIPTION   :       Test generating PERL file1
16
# FUNCTION:             Generating sine wave ROM 
17
#                                        with $n samples  which consists of 4 sine wave sum
18
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            
19
 
20
$aw=7;   ##   - address bit width
21
$n = 128; ### - period length
22
$n0 = 0; ### - init address  
23
$f1 = 1;  ## - first frequency
24
$f2 = 3;  ## -second frequency
25
$f3 = 5;  ## - 3-d frequency
26
$f4 = 7;  ## -4-th frequency
27
$Pi = 3.14159265358     ;
28
$ph =$Pi/4; ## initial phase    => 45 degree
29
    open OutFile, ">Wave_ROM128.v" || die "Cannot open file .V";    # file is open to write
30
 
31
 
32
        print OutFile   "//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
33
    print OutFile       "//   ROM with ".$n." samples of the sine waves at the frequencies = ".$f1.", ".  $f2.",". $f3." and ".$f4 ."\n";
34
    print OutFile       "//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
35
        print OutFile   "   `timescale 1 ns / 1 ps  \n";
36
        print OutFile   "module Wave_ROM128 ( ADDR ,DATA_RE,DATA_IM,DATA_REF ); \n";
37
    print OutFile       "       output [15:0] DATA_RE,DATA_IM,DATA_REF ;     \n";
38
    print OutFile       "       input [".($aw-1).":0]    ADDR ;     \n";
39
 
40
 
41
# # Cosine table generation
42
    print OutFile       "       reg [15:0] cosi[0:".($n-1)."];    \n";
43
    print OutFile       "       initial   begin    \n";
44
        for $j(0..$n/16-1){
45
          $cos_row=0;
46
         for $i(0..15){
47
$CosArr=(32767*cos(2*$Pi*$f1*(($n0+$i+16*$j)/$n)));     #23170
48
#       $CosArr=(16384*cos(2*$Pi*$f1*(($n0+$i+$j*16)/$n)));
49
#                        +16383*cos(2*$Pi*$f2*(($n0+$i+$j*16)/$n))); 
50
#       $CosArr=(8191*cos($ph+2*$Pi*$f1*(($n0+$i+$j*16)/$n))
51
   #              +8191*cos($ph+2*$Pi*$f2*(($n0+$i+$j*16)/$n))
52
        #                        +8191*cos($ph+2*$Pi*$f3*(($n0+$i+$j*16)/$n))
53
           #              +8191*cos($ph+2*$Pi*$f4*(($n0+$i+$j*16)/$n))); 
54
            $sinv= To_Hex4(int ($CosArr));
55
 
56
        print OutFile   " cosi[".($n0+$i+$j*16)."]=16'h".$sinv.";";
57
}
58
print OutFile "\n";
59
}
60
print OutFile "     end \n\n";
61
         print "\n";
62
# # Sine table generation
63
    print OutFile       "       reg [15:0] sine[0:".($n-1)."];    \n";
64
    print OutFile       "       initial   begin    \n";
65
                for $j(0..$n/16-1){
66
          $sin_row=0;
67
         for $i(0..15){
68
        $SinArr=(32767*sin(2*$Pi*$f1*(($n0+$i+16*$j)/$n)));        #16384          23170
69
#       $SinArr=(16384*sin(2*$Pi*$f1*(($n0+$i+$j*16)/$n)));        #
70
#                        +16383*sin(2*$Pi*$f2*(($n0+$i+$j*16)/$n)));    
71
#       $SinArr=(8191*sin($ph+2*$Pi*$f1*(($n0+$i+$j*16)/$n))
72
        #                 +8191*sin($ph+2*$Pi*$f2*(($n0+$i+$j*16)/$n))
73
                #                        +8191*sin($ph+2*$Pi*$f3*(($n0+$i+$j*16)/$n))
74
               #          +8191*sin($ph+2*$Pi*$f4*(($n0+$i+$j*16)/$n))); 
75
 
76
 
77
            $sinv= To_Hex4(int ($SinArr));
78
 
79
        print OutFile   " sine[".($n0+$i+$j*16)."]=16'h".$sinv.";";
80
}
81
print OutFile "\n";
82
}
83
         print "\n";
84
print OutFile "      end \n\n";
85
 
86
##Reference table generation
87
    print OutFile       "       reg [15:0] deltas[0:".($n-1)."];    \n";
88
    print OutFile       "       initial   begin    \n";
89
        for $j(0..$n/4-1){
90
         for $i(0..3){
91
        print OutFile   " deltas[".($n0+$i+$j*4)."]=16'h0000;";
92
}
93
print OutFile "\n";
94
}
95
##print OutFile " deltas[".$f1."]=16'h3fff;  deltas[".$f2."]=16'h3fff;\n";
96
$SinMag=To_Hex4(int (8191*4*sin($ph)));
97
 
98
print OutFile   " deltas[".$f1."]=16'h".$SinMag."; deltas[".$f2."]=16'h".$SinMag."; deltas[".$f3."]=16'h".$SinMag."; deltas[".$f4."]=16'h".$SinMag.";\n";
99
print OutFile "     end \n\n";
100
 
101
print OutFile " assign DATA_RE=cosi[ADDR];      \n";
102
print OutFile " assign DATA_IM=sine[ADDR];      \n";
103
print OutFile " assign DATA_REF=deltas[ADDR];   \n";
104
print OutFile "endmodule   \n";
105
 
106
   close(OutFile);
107
 
108
 
109
   sub To_Hex2{
110
        my(%Hexnumbers)= (0,0,1,1,2,2,3,3,
111
                        4,4,5,5,6,6,7,7,
112
                        8,8,9,9,10,'A',11,'B',
113
                        12,'C',13,'D',14,'E',15,'F');
114
 
115
        $_[0]=($_[0]>=0) ? $_[0] : 256+$_[0];
116
        my($h21)=$_[0] % 16;
117
        my($h22)=int($_[0] / 16);
118
        return $Hexnumbers{$h22}.$Hexnumbers{$h21};
119
   };
120
 
121
    sub To_Hex4{
122
        my(%Hexnumbers)= (0,0,1,1,2,2,3,3,
123
                        4,4,5,5,6,6,7,7,
124
                        8,8,9,9,10,'A',11,'B',
125
                        12,'C',13,'D',14,'E',15,'F');
126
 
127
   $_[0]=($_[0]>=0) ? $_[0] : 65536+$_[0];
128
        my($h21)=$_[0] % 16;
129
        my($r21)=int($_[0] / 16);
130
        my($h22)=$r21 % 16;
131
        my($r22)=int($r21 / 16);
132
        my($h23)=$r22 % 16;
133
        my($h24)=int($r22 / 16);
134
   return $Hexnumbers{$h24}.$Hexnumbers{$h23}.$Hexnumbers{$h22}.$Hexnumbers{$h21};
135
  ##return $_[0];
136
  };
137
 
138
          open (File, "Wave_ROM128.v") || die  "Cannot open r";
139
          while ($line = <File>)
140
       {
141
           print $line;         # Ready file output to the screen
142
                   }
143
 
144
 
145
          close(File);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.