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

Subversion Repositories two_dimensional_fast_hartley_transform

[/] [two_dimensional_fast_hartley_transform/] [trunk/] [signed_mult_const_fpga.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 irezki
/**********************************************************************
2
 * File  : signed_mult_const_fpga.v
3
 * Author: Ivan Rezki
4
 * email : irezki@gmail.com
5
 * Topic : RTL Core
6
 *                2-Dimensional Fast Hartley Transform
7
 *
8
 *
9
 * Function: Signed Multiplier - constant sqrt(2) = 1.41421
10
 *
11
 * 8 bit accuracy:
12
 * 1.41421*a = (256*1.41421)*a/256 = 362.03776*a/256 = 362*a/256
13
 * product = 362*a/2^8
14
 * wire [8:0] mult_constant = 9'd362;
15
 *
16
 * 15 bit accuracy:
17
 * 1.41421*a = (32768*1.41421)*a/32768 = 46340.95*a/32768
18
 * product = 46341*a/2^15
19
 * wire [15:0] mult_constant = 16'd46341;
20
 *
21
 * 16 bit accuracy:
22
 * 1.41421*a = (65536*1.41421)*a/65536 = 92681*a/65536
23
 * product = 92681*a/2^16
24
 * wire [16:0] mult_constant = 17'd92681;
25
 *
26
 * RIGHT TO USE: This code example, or any portion thereof, may be
27
 * used and distributed without restriction, provided that this entire
28
 * comment block is included with the example.
29
 *
30
 * DISCLAIMER: THIS CODE EXAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY
31
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
32
 * TO WARRANTIES OF MERCHANTABILITY, FITNESS OR CORRECTNESS. IN NO
33
 * EVENT SHALL THE AUTHOR OR AUTHORS BE LIABLE FOR ANY DAMAGES,
34
 * INCLUDING INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE
35
 * USE OF THIS CODE.
36
 **********************************************************************/
37 2 irezki
 
38
module signed_mult_const_fpga (
39
        rstn,
40
        clk,
41
        valid,
42
        a,
43
        p
44
);
45
 
46
parameter               N = 8;
47
input                   rstn;
48
input                   clk;
49
input                   valid;
50
input  signed [N-1:0] a; // variable - positive/negative
51
output signed [N  :0] p; // product output
52
 
53
// FHT constant
54
// wire [8:0] mult_constant; // always positive
55
// assign mult_constant = 9'd362;
56
 
57 7 irezki
//wire signed [17:0] mult_constant; // always positive
58
//assign mult_constant = {1'b0, 17'd92681};
59
parameter mult_constant = {1'b0, 17'd92681};
60 2 irezki
 
61
reg signed [N-1:0] a_FF;
62
always @(posedge clk)
63
if              (!rstn) a_FF <= #1 0;
64
else if (valid) a_FF <= #1 a;
65
 
66
wire signed [(16+1)+N-1:0] p_tmp = $signed(a_FF) * $signed(mult_constant);
67
 
68
//assign p = p_tmp[(16+1)+N-1:16];// >> 16;
69
assign p = p_tmp >> 16;
70
 
71
endmodule
72 7 irezki
 
73
// Update Log:
74
// 27 Jul. 2011
75
// wire [17:0] mult_constant replaced by parameter

powered by: WebSVN 2.1.0

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