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

Subversion Repositories quadrature_oscillator

[/] [quadrature_oscillator/] [trunk/] [code/] [quad_oscillator.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 davimoreno
// 
2
// Davi C. M. de Almeida
3
//
4
// Quadrature Oscillator
5
//
6
// System that impulse response is sin(wo*n) / cos(wo*n) waves with period of 100 samples (wo = pi/50)
7
//
8
// Input x in 8b8 signed fixed point format
9
// Output y in 8b8 signed fixed point format
10
//
11
// To make the system oscilate just give him an impulse!
12
// (That is, put x to 1 (16'd256) for one clock cicle and 0 in the rest)
13
//
14
// If you want more bits of resolution in the waves just multiply the impulse by powers of 2
15
// Eg. For 9 bits of resolution use an impulse x of 16'd256 * 2 = 16'd512  
16
//       For 10 bits of resolution use an impulse x of 16'd256 * 4 = 16'd1024
17
 
18
module quad_oscillator(
19
        input   clk, rst,
20
        input signed [15:0] x,
21
        output signed [15:0] sin, cos
22
);
23
 
24
 
25
        // registers z^(-1)
26
        reg signed [15:0] z1, z2;
27
 
28
 
29
        // auxiliary wires
30
        wire signed [23:0] za1, za2, zb1_sin, zb1_cos, sx1;
31
        wire signed [15:0] v;
32
 
33
        // synchronism
34
        always @ (posedge clk or posedge rst) begin
35
                if (rst == 1) begin
36
                        z1 <= 16'd0;
37
                        z2 <= 16'd0;
38
                end
39
                else begin
40
                        z1 <= v;
41
                        z2 <= z1;
42
                end
43
        end
44
 
45
        // routing
46
        assign za1 = (z1 <<< 9) - z1;
47
        assign za2 = (z2 <<< 8);
48
        assign zb1_sin = (z1 <<< 4);
49
        assign zb1_cos = -(z1 <<< 8) + z1;
50
 
51
        assign sx1 = za1 - za2;
52
        assign v = x + sx1[23:8];
53
 
54
        // outputs
55
        assign sin = zb1_sin[23:8];
56
        assign cos = v + zb1_cos[23:8];
57
 
58
endmodule

powered by: WebSVN 2.1.0

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