aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp2/top/u2_rev3_iad/impulse.v
blob: 7f0cdc9beb97a5605bfe5b0644f095da51198b25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module impulse
  (input clk,
   input rst,
   input ena,
   
   input [13:0] dc_offset_a,
   input [13:0] dc_offset_b,
   input [13:0] amplitude,
   input [15:0] impulse_len,
   input [15:0] zero_len,

   output [13:0] adc_a,
   output [13:0] adc_b,
   output        adc_ovf_a,
   output        adc_ovf_b
   );

   reg [13:0] adc_a_int = 0;
   reg [15:0] count;

   localparam ST_ZERO = 0;
   localparam ST_HIGH = 1;
   reg 	      state;
   
   always @(posedge clk)
     if (rst | ~ena)
       begin
	  adc_a_int <= 0;
	  count <= 0;
	  state <= ST_ZERO;
       end
     else
       case(state)
	 ST_ZERO:
	   if (count == zero_len)
	     begin
		adc_a_int <= amplitude;
		state <= ST_HIGH;
		count <= 0;
	     end
	   else
	     count <= count + 1;

	 ST_HIGH:
	   if (count == impulse_len)
	     begin
		adc_a_int <= 0;
		state <= ST_ZERO;
		count <= 0;
	     end
	   else
	     count <= count + 1;

       endcase // case (state)

   assign adc_a = adc_a_int + dc_offset_a;

   // Ignore for now
   assign adc_b = dc_offset_b;
   assign adc_ovf_a = 0;
   assign adc_ovf_b = 0;

endmodule // impulse