题解 | 数据串转并电路

`timescale 1ns/1ns

module s_to_p(
	input 				clk 		,   
	input 				rst_n		,
	input				valid_a		,
	input	 			data_a		,
 
 	output	reg 		ready_a		,
 	output	reg			valid_b		,
	output  reg [5:0] 	data_b
);

reg [2:0] cnt ;
reg [5:0] data_reg;

    always @(posedge clk or negedge rst_n)           
        begin                                        
            if(!rst_n) begin                              
                ready_a <= 1'b0;   
            end                                    
            else begin
                ready_a <= 1'b1;
            end                                                                                                                     
        end

    always @(posedge clk or negedge rst_n)           
        begin                                        
            if(!rst_n) begin                              
                data_reg <= 6'b0;   
            end                                    
            else if(valid_a) begin
                data_reg <= {data_a,data_reg[5:1]};
            end                                                                                  
                                                 
        end

    always @(posedge clk or negedge rst_n)           
        begin                                        
            if(!rst_n) begin                              
                cnt <= 3'b0;   
            end
            else if(cnt == 3'd5) begin
                cnt <= 3'b0;
            end                                   
            else if(valid_a) begin
                cnt <= cnt + 1'b1;
            end                                                                                  
                                                 
        end

    always @(posedge clk or negedge rst_n)           
        begin                                        
            if(!rst_n) begin                              
                valid_b <= 1'b0;   
            end                                    
            else if(cnt == 3'd5) begin
                valid_b <= 1'b1;
            	end                                                                                  
            else begin
                valid_b <= 1'b0;   
            end                                    
        end

    always @(posedge clk or negedge rst_n)           
        begin                                        
            if(!rst_n) begin                              
                data_b <= 6'b0;   
            end
            else if(cnt == 3'd5) begin
                data_b <= {data_a,data_reg[5:1]};
            end   
        end


endmodule

全部评论

相关推荐

在笔试的大西瓜很矫健:校招数分不用想了,这经历和学历都不够用,大厂更别想,初筛都过不了,说点不好听的小厂数分都进不去(小厂也是假数分),要两个对口实习+3个项目(或者3+2),而且要有含金量才能补一点你的学历劣势。 建议刷实习,社招找数分,校招看运气,能入行业就行,可以运营转数分
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务