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

Subversion Repositories quadrature_oscillator

[/] [quadrature_oscillator/] [trunk/] [code/] [auto_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
// Automatic Quadrature Oscillator system
5
//
6
// wo oscillation frequency: pi/50 rad (100 samples per period)
7
// 
8
// To oscillate just hold start at 1 
9
// 
10
// Output sin(wo*n) / cos(wo*n) in 8 bits of precision (8b8 signed fixed point format)
11
//
12
// This code is a simple state machine that automatically applies an impulse to the input
13
// of the quadrature oscillator and keeps it oscillating indefinitely.
14
 
15
module auto_oscillator(
16
        input   clk, rst, start,
17
        output signed [15:0] sin, cos
18
);
19
 
20
        // declare state register
21
        reg [1:0] state, next_state;
22
 
23
        // states definitions
24
        `define S0 2'b00
25
        `define S1 2'b01
26
        `define S2 2'b11
27
 
28
        // oscillator controller regs
29
        reg x, osc_rst;
30
        quad_oscillator osc1(.clk(clk),
31
                                                                .rst(osc_rst),
32
                                                                .x({7'd0, x, 8'd0}),
33
                                                                .sin(sin),
34
                                                                .cos(cos));
35
 
36
        // synchronism
37
        always @ (posedge clk or posedge rst) begin
38
                if (rst == 1)
39
                        state <= `S0;
40
                else
41
                        state <= next_state;
42
        end
43
 
44
        // state transition     
45
        always @ (*) begin
46
                case (state)
47
                        `S0: next_state = (start)? `S1:`S0;
48
                        `S1: next_state = (start)? `S2:`S0;
49
                        `S2: next_state = (start)? `S2:`S0;
50
                endcase
51
        end
52
 
53
        // Output depends only on the state
54
        always @ (state) begin
55
                case (state)
56
                        `S0: begin
57
                                osc_rst <= 1'b1;
58
                                x <= 1'b0;
59
                        end
60
                        `S1: begin
61
                                osc_rst <= 1'b0;
62
                                x <= 1'b1;
63
                        end
64
                        `S2: begin
65
                                osc_rst <= 1'b0;
66
                                x <= 1'b0;
67
                        end
68
                endcase
69
        end
70
 
71
endmodule

powered by: WebSVN 2.1.0

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