Imported Upstream version 3.0
[debian/gnuradio] / usrp / fpga / sdr_lib / phase_acc.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2003 Matt Ettus
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
20 //
21
22
23
24 // Basic Phase accumulator for DDS
25
26
27 module phase_acc (clk,reset,enable,strobe,serial_addr,serial_data,serial_strobe,phase);   
28    parameter FREQADDR = 0;
29    parameter PHASEADDR = 0;
30    parameter resolution = 32;
31    
32    input     clk, reset, enable, strobe;
33    input [6:0] serial_addr;
34    input [31:0] serial_data;
35    input        serial_strobe;
36    
37    output reg [resolution-1:0] phase;
38    wire [resolution-1:0] freq;
39
40    setting_reg #(FREQADDR) sr_rxfreq0(.clock(clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(freq));
41
42    always @(posedge clk)
43      if(reset)
44        phase <= #1 32'b0;
45      else if(serial_strobe & (serial_addr == PHASEADDR))
46        phase <= #1 serial_data;
47      else if(enable & strobe)
48        phase <= #1 phase + freq;
49
50 endmodule // phase_acc
51
52