学习笔记:Verilog VHDL硬件描述语言简介及在线仿真Verilog环境

  1. RTL Verilog VHDL HLS等概念
    RTL Register Transfer Level,寄存器传输级。它是数字电路设计中的一种抽象层次,描述了电路中寄存器之间的数据传输和逻辑操作。RTL代码通常用Verilog或VHDL语言编写,是后续综合、仿真等工作的基础。

VHDL全名Very-High-Speed Integrated Circuit Hardware Description Language 超高速集成电路硬件描述语言。主要是应用在数字电路的设计中。

Verilog HDL(简称 Verilog )是一种硬件描述语言,用于数字电路的系统设计。可对算法级、门级、开关级等多种抽象设计层次进行建模。
Verilog 继承了 C 语言的多种操作符和结构,与另一种硬件描述语言 VHDL 相比,语法不是很严格,代码更加简洁,更容易上手。
Verilog 不仅定义了语法,还对语法结构都定义了清晰的仿真语义。因此,Verilog 编写的数字模型就能够使用 Verilog 仿真器进行验证。

VHDL和Verilog作为IEEE的工业标准硬件描述语言,得到众多EDA公司支持,在电子工程领域,已成为事实上的通用硬件描述语言。

Vitis HLS (High Level Synthesis)是 Xilinx 公司重新打造的高层次综合工具,通过添加适当的 directives(制导语句) 和 constrains(约束), 将其 C/C++/System C 代码直接转换成 FPGA RTL( Verilog, VHDL, System C )代码。

  1. VHDL 最简语法例子
    entity :实体的电路意义相当于器件,在电路原理图上相当于元件符号。
    architecture 描述EA的内部逻辑功能,在电路上相当于器件的内部电路结构。符号“<=”是信号赋值符,是信号传递的意思,“y<=a”表示将a获得的信号赋给y输出端.
​library ieee;
use ieee.std_logic_1164.all; --库声明

entity TONE is
port(A,B:in std_logic; --实体定义
C:out std_logic);
end TONE;
 
architecture EX of TONE is --结构体定义
begin
C<=A OR B;
end EX;

详细参考,未列出。

  1. Verilog 语法简介
    参考资料:
    https://www.runoob.com/w3cnote/verilog-tutorial.html 初级教程
    https://www.runoob.com/w3cnote/verilog2-tutorial.html 高级教程
    Verilog比VHDL更流行一点点,也相对底层一点,eco软件往往支持Verilog
module counter10(
        //端口定义
        input                   rstn,   //复位端,低有效
        input                   clk,    //输入时钟
        output [3:0]            cnt,    //计数输出
        output                  cout);  //溢出位

        reg [3:0]               cnt_temp ;      //计数器寄存器
        //always定义时序逻辑块,在时钟上升沿或复位下降沿触发。
        always@(posedge clk or negedge rstn) begin
                if(! rstn)begin         //复位时,计时归0
                        cnt_temp <= 4'b0 ; //<位宽>'<进制><数值>
                end
                else if (cnt_temp==4'd9) begin  //计时10个cycle时
                        cnt_temp        <=4'b000;//计时归0
                end
                else begin                //计时加1
                        cnt_temp        <= cnt_temp + 1'b1 ; 
                end
        end

        assign  cout = (cnt_temp==4'd9) ;       //输出周期位
        assign  cnt  = cnt_temp ;               //输出实时计时器

endmodule
  1. 在线仿真Verilog代码
    https://hdlbits.01xz.net/wiki/Iverilog
`timescale 1ns / 1ps

module top_module ();
    reg clk = 0;
    always #5 clk = ~clk; // Create clock with period=10

    reg rstn;
    wire [3:0] cnt;
    wire cout;

    initial `probe_start; // Start the timing diagram

    `probe(clk);      // Probe signal "clk"
    `probe(rstn);
    `probe(cnt);
    `probe(cout);

    counter10 inst_counter (
        .clk(clk),
        .rstn(rstn),
        .cnt(cnt),
        .cout(cout)
    );

    initial begin
        rstn = 0;
        #20 rstn = 1; // 20ns 后撤销复位
        #100 $finish; // 仿真 100ns 后结束
    end

    initial begin
        $monitor("Time = %0t, rstn = %b, clk = %b, cnt = %d, cout = %b", $time, rstn, clk, cnt, cout);
    end

endmodule

module counter10(
    input           rstn,  //复位端,低有效
    input           clk,   //输入时钟
    output [3:0]    cnt,   //计数输出
    output          cout); //溢出位

    reg [3:0]       cnt_temp; //计数器寄存器

    always @(posedge clk) begin // 只在时钟上升沿触发
        if (!rstn) begin      // 复位时,计时归0
            cnt_temp <= 4'b0000;
        end else begin
            if (cnt_temp == 4'd9) begin //计时10个cycle时,计时归0
                cnt_temp <= 4'b0000;
            end else begin        //计时加1
                cnt_temp <= cnt_temp + 1'b1;
            end
        end
    end

    assign cout = (cnt_temp == 4'd9);  //输出周期位
    assign cnt = cnt_temp;      //输出实时计时器

endmodule

以上代码并不是标准的Verilog,结合在线仿真做了适配变更。说明如下:
为了在时序图中显示信号,定义了三个 Verilog 宏:
probe(signal) : Adds signal to the timing diagram. probe(signal) :将信号添加到时序图中。
probe_start : Use this inside an initial block to start a new timing diagram probe_start :在 initial block 中使用 this 来启动新的时序图
probe_stop : Use this inside an initial block to stop the current timing diagram probe_stop :在 initial 块中使用 this 来停止当前的时序图

运行效果如下:
在这里插入图片描述

第1 章绪 论 ....................................................................................................................1 § 1.1 关于EDA...............................................................................................................1 § 1.2 关于 VHDL............................................................................................................3 § 1.3 关于自顶向下的系统设计方法 ............................................................................5 § 1.4 关于应用 VHDL 的EDA 过程.............................................................................6 § 1.5 关于在系统编程技术 ............................................................................................9 § 1.6 关于 FPGA/CPLD 的优势...................................................................................10 § 1.7 关于 VHDL 的学习.............................................................................................10 第2 章 VHDL 入门..............................................................................................................12 § 2.1 用 VHDL 设计多路选择器和锁存器.................................................................12 § 2.2 用 VHDL 设计全加器.........................................................................................15 第3 章 VHDL 程序结构......................................................................................................19 § 3.1 实 体 ENTITY ..............................................................................................19 § 3.2 结构体 ARCHITECTURE ............................................................................26 § 3.3 块语句结构 BLOCK .....................................................................................29 § 3.4 进程 PROCESS .............................................................................................32 § 3.5 子程序(SUBPROGRAM)....................................................................................35 3.5.1 函数FUNCTION ..................................................................................36 3.5.2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值