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

Subversion Repositories sqmusic

[/] [sqmusic/] [trunk/] [sqm/] [sq_pg.v] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 gryzor
/*
2
        SQmusic
3
 
4
  (c) Jose Tejada Gomez, 9th May 2013
5
  You can use this file following the GNU GENERAL PUBLIC LICENSE version 3
6
  Read the details of the license in:
7
  http://www.gnu.org/licenses/gpl.txt
8
 
9
  Send comments to: jose.tejada@ieee.org
10
 
11
*/
12
 
13 18 gryzor
`timescale 1ns/1ps
14
 
15
module sq_slot(
16
        input clk,
17
        input reset_n,
18
        input [10:0] fnumber,
19
        input [2:0] block,
20
  input [3:0] multiple
21
);
22
 
23
wire [9:0]phase;
24
wire [12:0] sin_log, sin_linear;
25
 
26
sq_pg pg(
27
  .clk     (clk),
28
  .reset_n (reset_n),
29
  .fnumber (fnumber),
30
  .block   (block),
31
  .multiple(multiple),
32
  .phase   (phase) );
33
 
34
sq_sin sin(
35
  .clk     (clk),
36
  .reset_n (reset_n),
37
  .phase   (phase),
38
  .val     (sin_log) );
39
 
40
sq_pow pow(
41
  .clk     (clk),
42
  .reset_n (reset_n),
43
  .x       (sin_log),
44
  .y       (sin_linear) );
45
 
46
endmodule
47
 
48 12 gryzor
module sq_pg(
49
        input clk,
50
        input reset_n,
51
        input [10:0] fnumber,
52
        input [2:0] block,
53
  input [3:0] multiple,
54
        output [9:0]phase );
55
 
56
reg [19:0] count;
57
assign phase = count[19:10];
58
 
59 18 gryzor
wire [19:0]fmult = fnumber << block;
60 12 gryzor
 
61
always @(posedge clk or negedge reset_n ) begin
62
        if( !reset_n )
63
                count <= 20'b0;
64
        else begin
65 18 gryzor
          count <= count + ( multiple==4'b0 ? fmult>> 1 : fmult*multiple);
66 12 gryzor
        end
67
end
68
 
69
endmodule
70
 
71 18 gryzor
///////////////////////////////////////////////////////////////////
72 12 gryzor
module sq_sin(
73 18 gryzor
  input clk,
74
  input reset_n,
75 12 gryzor
  input [9:0]phase,
76 18 gryzor
  output [12:0] val // LSB is the sign. 0=positive, 1=negative
77
);
78 12 gryzor
 
79 18 gryzor
reg [12:0] sin_table[1023:0];
80 12 gryzor
 
81
initial begin
82 18 gryzor
  $readmemh("../tables/sin_table.hex", sin_table);
83 12 gryzor
end
84 18 gryzor
reg [9:0]last_phase;
85
assign val = sin_table[last_phase];
86 12 gryzor
 
87 18 gryzor
always @(posedge clk or negedge reset_n ) begin
88
        if( !reset_n )
89
                last_phase <= 10'b0;
90
        else begin
91
          last_phase <= phase;
92
        end
93
end
94
endmodule
95
///////////////////////////////////////////////////////////////////
96
// sq_pow => reverse the log2 conversion
97
module sq_pow(
98
  input clk,
99
  input reset_n,
100
  input [12:0]x,
101
  output [12:0]y // LSB is the sign. 0=positive, 1=negative
102
);
103 12 gryzor
 
104 18 gryzor
reg [12:0] pow_table[255:0];
105
 
106
initial begin
107
  $readmemh("../tables/pow_table.hex", pow_table);
108 12 gryzor
end
109 18 gryzor
reg [7:0]index;
110
reg [2:0]exp;
111
reg sign;
112
 
113
wire [12:0] raw = pow_table[index] >> exp;
114
assign y = sign ? ~raw+13'b1 : raw; // regular 2's complement
115
 
116
always @(posedge clk or negedge reset_n ) begin
117
        if( !reset_n ) begin
118
                index <= 8'b0;
119
                exp   <= 3'b0;
120
                sign  <= 1'b0;
121
        end
122
        else begin
123
          exp   <= x[12:10];
124
          index <= x[9:1];
125
          sign  <= x[0];
126
        end
127
end
128
 
129
endmodule

powered by: WebSVN 2.1.0

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