Verilog之流水灯

VerilogHDL那些事儿_建模篇(黑金FPGA开发板配套教程)

作者:akuei2

说明:参照该书将部分程序验证学习一遍

学习时间:2014年5月2号

 

主要收获:

1.对FPGA有初步了解;

2.功能模块和控制模块;

3.并行操作的思维;

4.使用“并行操作”进行流水灯实验。

 

FPGA是什么?

1.一个很好的比喻是:FPGA是“一堆乐高积木”,而Verilog是“搭积木的手”。FPGA并没有实际的形状,要通过Verilog描述出形状来。

2.新手们常常忽略了,FPGA其实是并存着“顺序操作”和“并行操作”的操作概念。如果打从一开始就忽略了它们,往后的日子很难避免遇见瓶颈。

 

过程赋值和assign连续赋值:

1.过程赋值改变一个寄存器的状态,是时序逻辑,用在initial和always里面;

2.连续赋值是组合逻辑,驱动线型变量(wire)。

 

流水灯实验:

1.系统整体模块以及每个功能模块示意图:

Verilog之流水灯_第1张图片

Verilog之流水灯_第2张图片

2.RTL原理图

RTL(寄存器传输级):描述数据在寄存器之间怎么流动和如何处理这些数据的模型。

Verilog之流水灯_第3张图片

3.控制模块为top_module,功能模块有led1_module~led4_module。

moduletop_module(CLK, RSTn, LED_Out);

      

       input CLK;

       input RSTn;

       output [3:0]LED_Out;

      

       wire LED1_Out;

      

       led1_module U1

       (

              .CLK(CLK),

              .RSTn(RSTn),

              .LED_Out(LED1_Out)

       );

      

       wire LED2_Out;

      

       led2_module U2

       (

              .CLK(CLK),

              .RSTn(RSTn),

              .LED_Out(LED2_Out)

       );

      

       wire LED3_Out;

      

       led3_module U3

       (

              .CLK(CLK),

              .RSTn(RSTn),

              .LED_Out(LED3_Out)

       );

      

       wire LED4_Out;

      

       led4_module U4

       (

              .CLK(CLK),

              .RSTn(RSTn),

              .LED_Out(LED4_Out)

       );

      

       assign LED_Out = {LED4_Out, LED3_Out,LED2_Out, LED1_Out};

      

endmodule

 

 

 

moduleled1_module(CLK, RSTn, LED_Out);

 

       input CLK;

       input RSTn;

       output LED_Out;

      

       parameter T10MS = 2'd3;

      

       reg[1:0]Count1;

      

       always@(posedge CLK or negedge RSTn)

              if(!RSTn)

                     Count1 <= 2'd0;

              else if(Count1 == T10MS)

                     Count1 <= 2'd0;

              else

                     Count1 <= Count1 + 1'b1;

                    

       reg rLED_Out;

      

       always@(posedge CLK or negedge RSTn)

              if(!RSTn)

                     rLED_Out <= 1'b0;

              else if(Count1 == 2'd0)

                     rLED_Out <= 1'b1;

              else

                     rLED_Out <= 1'b0;

                    

       assign LED_Out = rLED_Out;

      

endmodule

4.仿真如下:

Verilog之流水灯_第4张图片

 

知识点~~~

1.硬件描述语言 Hardware DescriptionLanguage;

2.HDL采用自顶向下的电路设计方法,主要可以分为五个抽象层次:

Verilog之流水灯_第5张图片

3.HDL语言是有时序概念的,这和平常的编程语言不一样。


你可能感兴趣的:(FPGA,Verilog)