02fpga开发之VIVADO仿真的使用之呼吸灯
02fpga开发之VIVADO仿真的使用之呼吸灯
1
Machine Translated by Google
Table of contents
2
Machine Translated by Google
This document implements the simulation of the design code, using VIVADO's own tools for simulation, and learn how to use it through this tutorial
VIVADO software has its own simulation function. For the method of creating a new project, please refer to the document "Installation and Introduction of Development Software/Introduction to VIVADO and
Speed->7010 selection-1,7020
Click Next->
NewProjectSummary (new project overview) Confirm project information, type selection, etc., click Finish to complete
For the method of creating a new verilog file, please refer to "01fpga Development: The Simplest LED Flow Lamp". No further details are given here,
The file name we created is: breath_led.v, the module name is breath_led, and the module realizes the breathing light effect of 4 LEDs in turn.
The breath_led.v code is as follows (do not copy the code from here, please copy from the corresponding demo, the format will change when the pdf document is copied
change):
module breath_led #
Frequency 50M
parameter SET_COMPARE_FRQ=1000,//comparison
3
Machine Translated by Google
Output frequency 1K
parameter
parameter
count parameter
);
[31:0]counter_breath; reg
[31:0]counter_compare; reg
[31:0]compare_value; reg
pwm_period_clk_view; reg
breath_period_clk_view; reg
compare_period_clk_view; reg
[3:0]led_number;
assign led=led_reg;
if(rstn==0)led_reg<=0; case
(led_number) 8'b000:
led_reg[0]<=led_breath_view;
led_reg[2]<=led_breath_view; 8'b011:
led_reg[3]<=led_breath_view; default:
led_reg[0]<=led_breath_view; endcase
end
//pwm
if(rstn==0) begin
counter_pwm<=0;
4
Machine Translated by Google
pwm_period_clk_view<=0;
end
else
begin
counter_pwm<=counter_pwm+1;
if(counter_pwm<compare_value)led_breath_view<=1; else
led_breath_view<=0; if(counter_pwm>PWM_COUNTER_MAX-1)
begin
counter_pwm<=0;
pwm_period_clk_view<=~pwm_period_clk_view;
end
end
end
reg [3:0]led_number_state;
if(rstn==0)
begin
led_number=0;
counter_breath<=0;
breath_period_clk_view<=0;
breath_dir<=0; led_number_state<=0;
end
else
begin
counter_breath<=counter_breath+1;
if(counter_breath>BREATH_COUNTER_MAX-1) begin
counter_breath<=0;
breath_period_clk_view<=~breath_period_clk_view;
case (led_number_state)
0:
begin led_number_state=1;led_number=0; end begin
1:
led_number_state=2;led_number=1; end begin
2:
led_number_state=3;led_number=2; end begin
3:
led_number_state=4;led_number=3; end begin
4: led_number_state=5;led_number=2; end begin
5:
led_number_state=6;led_number=1; end begin
6:
led_number_state=0;led_number=0; end default: begin
end
5
Machine Translated by Google
end
end
end
if(rstn==0)
begin
counter_compare<=0;
compare_period_clk_view<=0;
compare_value<=0;
end
else
begin
counter_compare<=counter_compare+1;
if(counter_compare>SET_COMPARE_COUNTER_MAX-1) begin
counter_compare<=0;
if(breath_dir==0) begin
if(compare_value<PWM_COUNTER_MAX)compare_value<=compare_value+COMPARE_VALUE_STEP;
end
else if(breath_dir==1)
begin
if(compare_value>0)compare_value<=compare_value
COMPARE_VALUE_STEP;
end
compare_period_clk_view<=~compare_period_clk_view;
end
end
end
endmodule
In the code, first the top-level parameter list defines some parameters, such as period and PWM count related parameters. Then in the
code, there is the code generated by the breathing cycle, the PWM counting code, and the LED switching code. Our tutorial is mainly to show you how
to use VIVADO's own simulation tool to simulate the design, and the code logic will not be explained. Then we explain
How to emulate.
We can see that after creating a new verilog file breath_led.v, under the Sources file column
The breath_led.v file also appears under simulation sources->sim_1. Newly created design files will also be synchronized to the simulation file directory.
6
Machine Translated by Google
We right-click Add Sources in the simulation soruces, and the interface for adding source files will pop up. Add is checked by default.
Then click Create File to pop up a new file window. Here, the default File Type and File location remain
unchanged, and then fill in breath_led_tb for the File name, and then click OK:
7
Machine Translated by Google
Then click Finish to complete adding the testbench file. Finally, the window for defining the top-level module name of testbench pops up.
8
Machine Translated by Google
Finally, we see that the newly created breath_led_tb.v under sim_1 is newly created.
We double-click breath_led_tb.v to edit it. We first instantiate the breath_led module to be tested, and then write a series of signal initialization,
and clock driver code. Finally, the breath_led_tb.v file code is as follows:
module breath_led_tb();
reg clk_reg;
reg rstn_reg;
wire [3:0]led;
wire clk;
wire rstn;
9
Machine Translated by Google
initial begin
clk_reg=0;
rstn_reg=0;
#10
rstn_reg=1; end
breath_led #
( .CLOCK_FRQ(1000000) )
breath_led_inst (
);
endmodule
In order to improve the simulation verification speed, we changed the clock signal parameter to 100000HZ, and modified it through the form of parameter transfer. The land marked in red above the code
square. This technique can be used during simulation to improve development efficiency and greatly save time.
We set up the simulation. First, we click on Settings in the project management bar. Many settings can be made in the pop-up settings, including project settings,
10
Machine Translated by Google
We click on simulation to enter, and Vivado Simulator is selected by default. Then click OK to exit.
11
Machine Translated by Google
After returning to the main interface, right-click Run Simulation under SIMULATION in the project management bar, and select the
12
Machine Translated by Google
Finally, the simulation starts. The simulation can be started by controlling the simulation start and stop button above. Click on the third right in the middle
It can be properly rearranged by dragging and dropping. We adjust the window and wait for a while to run. can be seen,
Our LED signal output flows over time, and the breathing light waveform output.
Careful little friends will find that the cycle width of the LED high level is changing when pulling the X axis.
13
Machine Translated by Google
4. Comprehensive layout and routing to generate bit stream download verification effect
Binding pins and integrated layout and routing to generate bit files, please refer to the document "The Simplest LED Streaming Light for FPGA Development", which is no longer here
Finally, the layout and routing generate a bit file and download it to the development board. You can see the gradient brightness effect of our breathing light.
This concludes the tutorial for this section. If you need to use a third-party modelsim simulation, you can change the simulation software selection in the settings.
item, and then install modelsim for simulation. Third-party simulation software is more convenient to use than VIVADO and has higher performance. third party imitation
The real software needs to be studied by yourself, and this tutorial will not discuss it.
14