zxopen08 发表于 2016-8-9 16:38:59

大神帮看看 o_TxD 通过示波器看看左右抖动很严重

`timescale 1ns / 1ps

module Rec_commond(
                     i_clk, //20M
                      i_clk100m, //100M
                      i_rstn,
                      o_TxD,
                      ready //

    );
input i_clk,
   i_clk100m;
input i_rstn;
output o_TxD;
output ready;

reg RegData =11'b010_1010_1010 ;
reg pos_ready;
reg pos_Sclk;
reg start;
reg sent;

reg o_TxD;
reg cnt_start;
reg cnt_sent;
reg state;
reg Lclk;

wire i_clk;
wire i_rstn;
wire k_Sclk = 8'd20;
wire k_ready = 11'd1000;
wire Sclk;// 1M
wire ready;//20K

/////////// ready上升沿识别
always@(posedge i_clk)
begin
   if (~i_rstn) begin
   start<=0;
   pos_ready<=0;

end
    else begin
    pos_ready <= ready;
    start <= {(~pos_ready) & ready};
    end
end

///////////Sclk 上升沿识别
always@(posedge i_clk)
begin
   if (~i_rstn) begin
    sent<=0;
    pos_Sclk<=0;
    end
    else begin
    pos_Sclk <= Sclk;
    sent <= {(~pos_Sclk) & Sclk};
    end
end


always @(posedge i_clk)begin
if (~i_rstn) begin
    state <= 4'b0000;
   o_TxD<=1;
   end
else begin
case(state)
   4'b0000: if(start)begin
                        state<=4'b0001;
                               // o_TxD <= RegData;
                                 end
   4'b0001: if(sent)begin
                        state<=4'b0010;
                                 o_TxD <= RegData;
                                 end
   4'b0010: if(sent)begin
                        state<=4'b0011;
                                 o_TxD <= RegData;
                                 end
   4'b0011: if(sent)begin
                        state<=4'b0100;
                                 o_TxD <= RegData;
                                 end
   4'b0100: if(sent)begin
                        state<=4'b0101;
                                 o_TxD <= RegData;
                                 end
   4'b0101: if(sent)begin
                        state<=4'b0110;
                                 o_TxD <= RegData;
                                 end
   4'b0110: if(sent)begin
                        state<=4'b0111;
                                 o_TxD <= RegData;
                                 end
   4'b0111: if(sent)begin
                        state<=4'b1000;
                                 o_TxD <= RegData;
                                 end
   4'b1000: if(sent)begin
                        state<=4'b1001;
                                 o_TxD <= RegData;
                                 end
   4'b1001: if(sent)begin
                        state<=4'b1010;
                                 o_TxD <= RegData;
                                 end
      4'b1010: if(sent)begin
                        state<=4'b1011;
                                 o_TxD <= RegData;
                                 end
      4'b1011: if(sent)begin
                        state<=4'b0000;
                              o_TxD <= RegData;
                                 end

    default:state<=4'b0000;
    endcase
end
end

////////////////分频得到1M Sclk

Sclk U_Sclk(
                  .i_clk(i_clk),
                  .i_rstn(i_rstn),
                  .k(k_Sclk),
                  .clkk(Sclk) //1M

    );
//////////////////分频得到ready 20k
ready U_ready(
                  .i_clk(i_clk),
                  .i_rstn(i_rstn),
                  .k(k_ready),
                  .clkk(ready) //ready 20k

    );
endmodule
页: [1]
查看完整版本: 大神帮看看 o_TxD 通过示波器看看左右抖动很严重