您的位置:首页 > 其它

四、FPGA之序列信号发生器

2015-05-16 15:22 183 查看
本次试验是序列信号发生器,本次要产生的序列是00011101序列,关于序列信号发生器的原理这里就不说了,网上有很多资料。下面给出序列信号发生器的一种设计源代码。

module xulie(clk,rst_n,out);

           input clk;

           input rst_n;

           output out;

           

           reg out;

           

           parameter S0=3'd0,S1=3'd1,S2=3'd2,S3=3'd3,S4=3'd4,S5=3'd5,S6=3'd6,S7=3'd7;

           

           reg[2:0]current_state,next_state;

           

           

           always@(posedge clk or negedge rst_n)

               if(rst_n==1'b0)

                  current_state<=S0;

               else

                  current_state<=next_state;

                  

           always@(*)

               begin

                   case(current_state)

                            S0:

                               next_state=S1;

                            S1:

                               next_state=S2;

                            S2:

                               next_state=S3;

                            S3:

                               next_state=S4;

                            S4:

                               next_state=S5;

                            S5:

                               next_state=S6;

                            S6:

                               next_state=S7;

                            S7:

                               next_state=S0;

                   endcase

               end

               

           always@(posedge clk or negedge rst_n)

                   if(rst_n==1'b0)

                       out<=1'b0;

                   else

                       begin

                          if(current_state==S0)

                                 out<=1'b0;

                          else if(current_state==S1)

                                 out<=1'b0;

                          else if(current_state==S2)

                                 out<=1'b0;

                          else if(current_state==S3)

                                 out<=1'b1;

                          else if(current_state==S4)

                                 out<=1'b1;

                          else if(current_state==S5)

                                 out<=1'b1;

                          else if(current_state==S6)

                                 out<=1'b0;

                          else if(current_state==S7)

                                 out<=1'b1;

                          else;

    

                       end

             

endmodule

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  FPGA