原创 20分频、序列检测

2010-4-15 23:43 1326 0 分类: FPGA/CPLD

20分频器


 


题目:做一个20分频器,输入clk  reset  输出 out


要求:clk如果频率为10M的话,out输出频率为500k,即20分频,reset为低电平复位。


 


文本:


module fenpin20(clk_in,clk_out,reset);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


input clk_in,reset;


output clk_out;


integer count;


reg clk_out;


always @(negedge reset or posedge clk_in )


begin


if(!reset)


clk_out=0;


else


begin


if(count==20)


begin


clk_out=~clk_out;


count=0;


end


else


count=count+1;


end


end


endmodule



序列检测器


题目:利用状态机设计一个序列检测器,检测器在有“101”序列输入时输出为1,其他输入情况下,输出为0。画出状态转移图,并用Verilog语言描述实现。


仿真文本:



 



module xuliejiance(x,z,clk,rst,state);


input x,clk,rst;


output z;


output[2:0] state;


reg[2:0] state;


wire z;


parameter IDLE='d0,A='d1,B='d2,C='d3,G='D4;


assign z=(state==C&&x==1)?1:0;


always @(posedge clk)


  if(!rst)


          begin


          state <= IDLE;


          end


  else


          casex(state)


            IDLE : if(x==1)


                      begin


                          state <= A;


                      end


            A:    if(x==0)


                      begin


                          state <= B;


                      end


            B:    if(x==1)


                      begin


                          state <= C;


                      end


                    else


                      begin


                          state <= G;


                      end


            C:      if(x==1)


                      begin


                          state <= A;


                      end


                    else


                      begin


                          state <= G;


                      end


            G:      if(x==1)


                      begin


                          state <= A;


                      end


          default:state=IDLE; //缺省状态为初始状态。


          endcase


endmodule


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
0
关闭 站长推荐上一条 /3 下一条