[FPGA] DAC7744 FPGA控制源码

[复制链接]
679|1
 楼主| feihufuture 发表于 2020-8-26 08:54 | 显示全部楼层 |阅读模式
[payamount]1.00[/payamount]
[pay]

  1.         `timescale 1ns / 1ps
  2.         //-----------------------------------------------------------
  3.         module DAC_CTRL(
  4.         input FCLK_50M,
  5.         input rst_n,
  6.         input [15:0] dac_dataout,
  7.         output reg [1:0] DAC_ADR,
  8.         output reg DAC_LOAD,
  9.         output DAC_RST,
  10.         output reg DAC_CS_N,
  11.         output reg [15:0] DAC_DAT,
  12.         //
  13.         input [15:0] dac_value1,
  14.         input [15:0] dac_value2,
  15.         input [15:0] dac_value3,
  16.         input [15:0] dac_value4
  17.         );
  18.          
  19.         //-----------------------------------------------------------
  20.         //posedge is active for reset.
  21.         assign DAC_RST = rst_n;
  22.         //-----------------------------------------------------------
  23.        
  24.        
  25.         //-----------------------------------------------------------
  26.         reg [5:0] wr_state;
  27.         always @(posedge FCLK_50M)
  28.         begin
  29.                 if(~rst_n) wr_state <= 6'b0;
  30.                 else wr_state <= wr_state + 1;
  31.         end
  32.         //
  33.         always @(posedge FCLK_50M)
  34.         begin
  35.                 if(~rst_n) DAC_CS_N <= 1'b1;
  36.                 else
  37.                         begin
  38.                         case(wr_state)
  39.                         6'd1 :        begin
  40.                                                 DAC_CS_N <= 1'b0 ;
  41.                                                 DAC_ADR <= 2'b00;
  42.                                                 DAC_LOAD <= 1'b0;
  43.                                                 DAC_DAT <= dac_value1;
  44.                                                 end
  45.                         6'd2 : DAC_CS_N <= 1'b0 ;
  46.                         6'd3 : DAC_CS_N <= 1'b1 ;
  47.                         6'd4 : begin DAC_CS_N <= 1'b1 ; DAC_LOAD <= 1'b1; end
  48.                         6'd5 : DAC_CS_N <= 1'b1 ;
  49.                         6'd6 : DAC_CS_N <= 1'b1 ;
  50.                         6'd7 : DAC_CS_N <= 1'b1 ;
  51.                         6'd8 : DAC_CS_N <= 1'b1 ;
  52.                         //
  53.                         6'd9 :         begin
  54.                                                 DAC_CS_N <= 1'b0 ;
  55.                                                 DAC_ADR <= 2'b01;
  56.                                                 DAC_LOAD <= 1'b0;
  57.                                                 DAC_DAT <= dac_value2;
  58.                                                 end
  59.                         6'd10 : DAC_CS_N <= 1'b0 ;
  60.                         6'd11 : DAC_CS_N <= 1'b1 ;
  61.                         6'd12 : begin DAC_CS_N <= 1'b1 ; DAC_LOAD <= 1'b1; end
  62.                         6'd13 : DAC_CS_N <= 1'b1 ;
  63.                         6'd14 : DAC_CS_N <= 1'b1 ;
  64.                         6'd15 : DAC_CS_N <= 1'b1 ;
  65.                         6'd16 : DAC_CS_N <= 1'b1 ;
  66.                         //
  67.                         6'd17 :  begin
  68.                                                 DAC_CS_N <= 1'b0 ;
  69.                                                 DAC_ADR <= 2'b10;
  70.                                                 DAC_LOAD <= 1'b0;
  71.                                                 DAC_DAT <= dac_value3;
  72.                                                 end
  73.                         6'd18 : DAC_CS_N <= 1'b0 ;
  74.                         6'd19 : DAC_CS_N <= 1'b1 ;
  75.                         6'd20 : begin DAC_CS_N <= 1'b1 ; DAC_LOAD <= 1'b1; end
  76.                         6'd21 : DAC_CS_N <= 1'b1 ;
  77.                         6'd22 : DAC_CS_N <= 1'b1 ;
  78.                         6'd23 : DAC_CS_N <= 1'b1 ;
  79.                         6'd24 : DAC_CS_N <= 1'b1 ;
  80.                         //
  81.                         6'd25 :         begin
  82.                                                 DAC_CS_N <= 1'b0 ;
  83.                                                 DAC_ADR <= 2'b11;
  84.                                                 DAC_LOAD <= 1'b0;
  85.                                                 DAC_DAT <= dac_value4;
  86.                                                 end
  87.                         6'd26 : DAC_CS_N <= 1'b0 ;
  88.                         6'd27 : DAC_CS_N <= 1'b1 ;
  89.                         6'd28 : begin DAC_CS_N <= 1'b1 ; DAC_LOAD <= 1'b1; end
  90.                         6'd29 : DAC_CS_N <= 1'b1 ;
  91.                         6'd30 : DAC_CS_N <= 1'b1 ;
  92.                         6'd31 : DAC_CS_N <= 1'b1 ;
  93.                         6'd32 : DAC_CS_N <= 1'b1 ;
  94.                        
  95.                         endcase
  96.                         end
  97.         end
  98.         //
  99.        
  100.        

  101.        

  102.         endmodule




[/pay]
正点原子FPGA 发表于 2020-8-26 19:24 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:WX:feihu612 免费合作开发ECAT主从站

171

主题

1029

帖子

101

粉丝
快速回复 在线客服 返回列表 返回顶部