我想把编码器发出的17位串行数据由FPGA转换为并行数据,然后输出给DSP.下面是我写的用Verilog实现串并转换,求大神看看对不对,然后能否指导一下具体怎么应用于FPGA.谢谢
这是我该写的,您看看对不对:
模17计数器:
module counter_mod_17(clock,reset,Q);
input clock; //posedge effective
input reset; // negedge effective
output [4:0] Q; //17位数据是5位宽的
reg [4:0] Q;
always@(posedge clock or negedge reset) begin
if(~reset)
Q <= 5'd0;
If else(Q<=16)
Q <= Q + 1;
else
Q<=5'd0;
end
endmodule
串转并模块:
module ser_to_par_17bit(ser_in,clk,rst,out);
input ser_in,clk,rst;
output [16:0] out;
wire [16:0] out;
reg [16:0] par_out;
wire [4:0] count;
counter_mod_17 f1(.clock(clk),.reset(rst),.Q(count));
always@(posedge clk or negedge rst) begin
if(~rst)
par_out <= 17'b0_0000_0000_0000_0000;
else begin
par_out <= {par_out[16:0],ser_in};
end
end
assign out = (count == 16)? par_out : 17'b0_0000_0000_0000_0000;
endmodule |