SPI AD8370 Verilog控制逻辑参考

/*
*  Av = wr_dat[6:0] × 0.055744 × (1 + (7.079458 − 1) × wr_dat[7])
*/
module spi8370 #(parameter DIV = 10)(
    input       wire        clk     ,
    input       wire        rst_n   ,

    input       wire        wr_en   ,
    input       wire [7:0]  wr_dat  ,
    output      reg         wr_fin  ,

    output      reg         sclk    ,
    output      wire        mosi    ,
    output      reg         ltch    
);
reg [9:0] cnt;
reg [7:0] dat;
reg [2:0] dnt;
reg       req;

wire      clr;
wire      hlf;
assign    clr = (cnt == DIV   - 1);
assign    hlf = (cnt == DIV/2 - 1);
assign    mosi= ltch==1'd0 ? dat[7-dnt] :1'd0;
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        sclk <=  1'd0;
    end else if (hlf) begin
        sclk <= 1'd1;
    end else if (clr) begin
        sclk <= 1'd0;
    end
end
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        cnt  <= 10'd0;
    end else if (clr) begin
        cnt  <= 10'd0;
    end else begin
        cnt  <= cnt  + 1'd1;
    end
end
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        req <= 1'd0;
        dat <= 8'd0;
    end else if (wr_fin) begin
        req <= 1'd0;
    end else if(wr_en) begin
        req <= 1'd1;
        dat <= wr_dat;
    end
end
always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        dnt     <= 3'd0;
        ltch    <= 1'd1;
        wr_fin  <= 1'd0;
    end else if(req && clr && (!wr_fin))begin
        if (&dnt) begin
            ltch    <= 1'd1;
            wr_fin  <= 1'd1;
            dnt     <= 3'd0;
        end else begin
            ltch    <= 1'd0;
            if(!ltch)
                dnt <= dnt + 1'd1;
        end
    end else if(wr_fin)begin
        wr_fin  <= 1'd0;
    end
end
endmodule
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值