Till KTH:s startsida Till KTH:s startsida

Ändringar mellan två versioner

Här visas ändringar i "Testbench in ModelSim (en)" mellan 2014-11-05 15:05 av William Sandqvist och 2014-11-05 15:15 av William Sandqvist.

Visa < föregående | nästa > ändring.

Testbench in ModelSim (en)

en Testbench in ModelSim

Automate the testing of the code lock pdf testbench.pdf

Välj rätt programSelect the correct software version - in skolan finns flera olika installerade under school there are several versions installed in the Start menyn!¶u! Altera 13.0.1.232 Web edition\ ModelSim-Altera Starter Edition 13.0.1.232\ ModelSim-Altera 10.1d(Quartus II 13.0sp1) Starta ModelSim.

welcomewindow.bmp

KClicka på on Jumpstart. Denna gång väljer vi länken This time we choose "Open Project" föor att fortsätta med det gamlacontinue with our previous MAXsim-projektect.

jumpstartcreate.png

Testbänken Förutomench In addition to the VHDL-k coden föor låset, behöver vi nu ytterligare enthe lock, we now need another VHDL- file föor testbänkskoden.¶ ¶ newvhdl.gif¶ Skapa en ny tomhe test bench code.¶

newvhdl.gif¶

Create a new empty
VHDL-file. KCopiera och klistra in innehållet från den givnay and paste the content of the filen tb_lockmall.vhd och spara sedanand then save the filen undersing the sammae namne, tb_lockmall.vhd, bland de övriga filerna i projekteamong the other files in the project.¶

Alternatively, you can copy the file tb_lockmall.vhd to the folder with the other files of the projec
t.

Alternativt kan man kopiera över hela filen tb_lockmall.vhd till mappen med de övriga filerna i projektet.

testbench.gif tb_lockmall.vhd ( text.gif tb_lockmall.txt )

Lägg tillAdd the VHDL-filen till projektet¶ addmenu.gif¶ addfiletoproject.gif¶ Projektet har nu två filer. Filen tb_lockmall.vhd är inte kompilerad ännu, vilket syns på det blåa frågetecknet.¶ twofiles.gif¶ Välj menyvalet Compile och alternativet Compile All. Nu kompileras filen tb_lockmall.vhd. Av innehållet i den filen framgår att den styr codelock.vhd, så det är därför den har det högsta ordningsnumret.¶ twocompiled.gif¶ Ladda Designen till simulatorn.¶ Vi vill att testbänkens meddelanden ska visas (som pilar) överst i Wave-fönstret. Därför skriver vi i Transcript-fönstret:¶ vsim -msgmode both -displaymsgmode both tb_codelock¶ Därefter lägger man till signalerna i Wave-fönstret.¶ add wave *¶ Starta simuleringen¶ I filen tb_codelock.vhd står raden clk <= not clk after 10 ns;. Den skapar de klockpulser med periodtiden 20 ns som vi använt tidigare.¶ clkfreq.gif¶ Vi kan direkt starta simuleringen med kommandot run 3us i Transcript-fönstret. Tiden 3 μs räcker för att prova igenom alla tänkbara tangent-tryckningskombinationer.¶ I Transcript-fönstret kan vi läsa det uppmuntrande budskapet Note: Lock tries to open for the right sequence!. I Wave-fönstret väljer man View, Zoom, och Zoom Full och kan då se hela förloppet.¶ noerror.gif¶ De gröna pilarna visar när den önskade händelsen händer! Avsluta nu simuleringen.¶ ¶ endsimulation.gif endsimulationyes.gif ¶ Avslöja den felaktiga koden! changecode.bmp¶ Nu gäller det att i Project-fönstret dubbelklicka på filen codelock.vhd så att den visas i texteditorn och där går att förändra. Kopiera och klistra in innehållet från filen lockmall_with_error.vhd. Spara sedan filen under samma namn som tidigare och kompilera om allt.¶ vhdlfile lockmall_with_error.vhd ( text.gif lockmall_with_error.txt )¶ Simulera sedan på samma sätt som tidigare. I Transcript-fönstret kan Du läsa meddelanden från testbänken när önskade eller oönskade händelser sker.¶ Den röda pilen i Wave-fönstret visar när den oönskade händelsen händer!¶ error.gif¶ VHDL-testbänksfilen Du behöver naturligtvis inte kunna skriva en VHDL-testbänksfil efter en kort första kurs om Digital Design. Tag ändå tillfället i akt att gå igenom filen och se om Du kan förstå hur den är tänkt!o the project¶

addmenu.gif¶

addfiletoproject.gif¶

The project now has two files. The file tb_lockmall.vhd is not compiled yet, which can be seen on the blue question mark.¶

twofiles.gif¶

Choose the menu Compile and the alternative Compile All. Now the file is compiled tb_lockmall.vhd. By the content of the file we can see that it controles the other file codelock.vhd, so that's why it gets the highest order.¶

twocompiled.gif¶

Load the Design to the simulator.¶

We want to test the bench messages to appear (as arrows) at the top of the Wave-window. Therefore, we write in the Transcript window:¶

vsim -msgmode both -displaymsgmode both tb_codelock¶

Then add the signals in the Wave-window.¶

add wave *¶

Start simulation¶

In the file tb_codelock.vhd you find clk <= not clk after 10 ns;. It creates the clock pulses with a period of 20 ns, as we used before.¶

clkfreq.gif¶

We can immediately start the simulation with the command run 3us in the Transcript-window. The time 3 μs sufficient to try all possible key-press combinations.¶

In the Transcript-window we can read the encouraging message Note: Lock tries to open for the right sequence!. In Wave-window choose View, Zoom, and Zoom Full and then you can see the entire process.¶

noerror.gif¶

The green arrows show the when the desired event happens! Now exit the simulation.¶



endsimulation.gif endsimulationyes.gif ¶

Reveal the wrong code! changecode.bmp¶

Now we need to in Project window, double-click the file codelock.vhd so that it appears in the text editor where we can change it. Copy and paste the content of the file lockmall_with_error.vhd. Then save the file under the same name as before and recompile everything.¶

vhdlfile lockmall_with_error.vhd ( text.gif lockmall_with_error.txt )¶

Simulate in the same way as before. In Transcript-window you can read the message from the test bench when event happens!¶

The red arrow in the Wave-window shows when/where the undesired event happens!¶

error.gif¶

VHDL-test bench file You do not of course be able to write a VHDL Test Bench file after a short first course on Digital Design. Still take the opportunity to go through the file and see if you can understand how it is intended!¶