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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc/] [boards/] [s3e-500/] [doc/] [dac/] [dac.v] - Blame information for rev 299

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 233 hellwig
//
2
// dac.v -- DAC control circuit
3
//
4
 
5 290 hellwig
 
6 299 hellwig
`timescale 1ns/10ps
7 290 hellwig
`default_nettype none
8 233 hellwig
 
9 290 hellwig
 
10 233 hellwig
module dac(clk, reset,
11
           sample_l, sample_r, next,
12
           sck, sdi, ld);
13
    input clk;
14
    input reset;
15
    input [15:0] sample_l;
16
    input [15:0] sample_r;
17
    output next;
18
    output sck;
19
    output sdi;
20
    output reg ld;
21
 
22
  reg [9:0] timing;
23
  reg [47:0] sr;
24
  wire shift;
25
 
26
  always @(posedge clk) begin
27
    if (reset) begin
28
      timing <= 10'h0;
29
    end else begin
30
      timing <= timing + 1;
31
    end
32
  end
33
 
34
  assign sck = timing[0];
35
  assign next = (timing[9:0] == 10'h001) ? 1 : 0;
36
 
37
  always @(posedge clk) begin
38
    if (reset) begin
39
      ld <= 1'b1;
40
    end else begin
41
      if (timing[9:0] == 10'h001) begin
42
        ld <= 1'b0;
43
      end
44
      if (timing[9:0] == 10'h031) begin
45
        ld <= 1'b1;
46
      end
47
      if (timing[9:0] == 10'h033) begin
48
        ld <= 1'b0;
49
      end
50
      if (timing[9:0] == 10'h063) begin
51
        ld <= 1'b1;
52
      end
53
    end
54
  end
55
 
56
  assign shift = sck & ~ld;
57
 
58
  always @(posedge clk) begin
59
    if (reset) begin
60
      sr <= 48'h0;
61
    end else begin
62
      if (next) begin
63
        sr[47:44] <= 4'b0011;
64
        sr[43:40] <= 4'b0000;
65
        sr[39:24] <= { ~sample_l[15],
66
                        sample_l[14:0] };
67
        sr[23:20] <= 4'b0011;
68
        sr[19:16] <= 4'b0001;
69
        sr[15: 0] <= { ~sample_r[15],
70
                        sample_r[14:0] };
71
      end else begin
72
        if (shift) begin
73
          sr[47:1] <= sr[46:0];
74
          sr[0] <= 1'b0;
75
        end
76
      end
77
    end
78
  end
79
 
80
  assign sdi = sr[47];
81
 
82
endmodule

powered by: WebSVN 2.1.0

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