Last time I looked at a simple 16-bit RISC processor aimed at students. It needed a little assist on documentation as well as had a missing file, however I managed to get it to simulate utilizing a free on the internet tool called EDA Playground. This time, I’ll take you with the code details as well as exactly how to run the simulation.
You’ll want to refer to the previous publish if you didn’t checked out it already. The diagrams as well as tables provide a high-level overview that will assist you comprehend the files discussed in this post.
If you wished to really program this on a genuine FPGA, you’d have a little work to do. The memory as well as register initialization is performed in a method that works fine for simulation, however wouldn’t work on a genuine FPGA. Anyway, let’s get started!
File-by-File
If you take each data individually, none of them are extremely difficult to understand. Here’s a quick rundown (I’m utilizing the data names I’ll utilize in my on the internet simulation):
Parameter.v – This is like an include data that sets some fundamental definitions for every other file.
prog.v – This is the direction memory. A simple module, it takes an address as well as presents data for that address. The $readmemb directive reads the data from a data (test.prog).
register.v – The register file. This is almost like the direction memory however it has two checked out ports as well as you can compose to it.
data.v – The RAM memory. This is almost like the registers, however larger as well as with a single checked out port. There is some simulation code that opens a data as well as prints the memory comments, however I deleted that as it was just for debugging. The preliminary content comes from the test.data file.
alu.v – You’d believe this would be complicated, however it isn’t. It just takes two inputs as well as does something to produce the output. Something simple like adds or subtracts. The always @(*) tells Verilog not to produce clocked logic for this. It just turns into some simple gates as well as muxes.
Datapath_Unit.v – This is one of the more complex files, although if you dig into it, you’ll see it is mainly bulk. This data produces all the resources (like the registers as well as memories) as well as wires them together.
Control_Unit.v – one more longer module, this just implements the direction table, setting the control lines based on the present instruction.
ALUControl.v – This data decodes instructions for the ALU. It was missing on the original post. Oddly, there is one more similar CPU on the exact same site that has an ALUControl file, however it is clearly for a different direction set. However, starting keeping that data as well as utilizing the style table, I was able to recreate it. If [fpga4students] corrects this, the files may look extremely different.
design.sv – This data is required for the EDAPlayground simulator I’m using. It contains the top-level elements (the data path as well as the control unit). since EDAPlayground only processes this file, it is necessary for it to include the other files mentioned above. This causes some warnings since each of them has a timescale directive, however this is harmless.
testbench.sv – The testbench isn’t part of the genuine design, however just sets up the simulation as well as collects results. I had to modify it a bit to work with EDAPlayground, however the operation is the same. It just produces a CPU, feeds it a clock, as well as lets it run for a while. The test program as well as memory contents are in test.prog as well as test.data.
Simulation
You can do one of two things. You can open up my copy of the style ready-to-go, however that may not be your finest option. I’d suggest you just go to EDAPlayground and produce a new Verilog project. then begin moving the files over from the original post. You’ll run into errors as well as missing files. See exactly how many you can fix. If you get stumped, then you can utilize my copy to assist you if you get stumped. You’ll discover more that way.
If you do choose to try it, right here are a few tips about EDAPlayground. You don’t requirement UVM/OVM selected, nor do you requirement any type of other libraries. I utilized Icarus Verilog 0.9.7, however you might most likely utilize any type of of the Verilog tools available. You do want to inspect the EPWave checkbox as well as you’ll requirement to add this to the inital part of testbench:
initial
begynde
$dumpfile(“dump.vcd”);
$dumpvars;
Use the + indication next to the data name tabs to make new files. EDAPlayground has a limit of ten files per pane. Remember, you’ll have to include any type of .v files you produce in either testbench.sv or design.sv. You don’t requirement to include the data files since the other files utilize them indirectly.
Løb!
Once you have all the errors worked out, you can press Run as well as you’ll get the waveform viewer, EPWave. You have at tilføje signaler af rentesats, så du kan se CPU’en på arbejdspladsen. Det ville være sjovt at tilføje nogle I / O-enheder i hukommelsen eller nogle debugging-porte, så du kan se tingene lidt bedre. Jeg vil normalt se program tælleren såvel som registret komponere havn for at få et koncept om, hvad der foregår indeni.
Den oprindelige kode havde et program, der udøvede en stor mængde instruktioner. Jeg kommenterede det ud såvel som erstattet det med dette:
0000_0100_0000_0000 // 0000: tons r0 <- mem (r2 + 0) siden r2 = 0 dette sætter 1 i r0 0000_0100_0100_0000 // 0002: tons nøjagtigt samme i R1 (R1 vil altid indeholde 1) // Placering 8 (byte), 4 (Word): 0010_0000_0101_0000 // 0004: R2 = R0 + R1 0001_0010_1000_0000 // 0006: MEM [R1] = R2 (det er MEM [1] = R2 0000_0010_0000_0000 // 0008: R0 = MEM [R1] 1101_0000_0000_0011 // 000A: Gå til sted # 4 (CPU vil multiplicere med 2 såvel som tilføj 2) // Ingen retning på 000C, men pc vil hænge der, mens det behandler hoppe Du skal være i stand til at overholde den stigende værdi, der komponerer til hukommelsen samt se programtællercyklusen tilbage til sted 4 med hver løkke. Her er en typisk session: Jeg slog ud en stor del af indvendige signaler, men du kan se, at hukommelsesadressen 1 er indstillet til 2 såvel som derefter til 3 på de første to iterationer af sløjfen. Ende spil Er dette en stor akademisk CPU? Jeg er ikke sikker. Nogle enklere CPU'er eksisterer, men de er ofte lidt, da de er vanskelige, eller de er ekstremt upraktiske. Noget mere udfordrende end dette er mest sandsynligt så godt at bide af for en nybegynder. Mens jeg tror, at du skulle have nogle forståelse af grundlæggende verilog, før du tackler noget som dette, var dokumentationen lidt sparsom (og forvirrende) på nogle områder. Det var klart, at det var stort nok siden jeg fik det til at fungere, men hvis du lige er begyndt, ville du højst sandsynligt sætte pris på lidt mere hjælp såvel som forklaringer. Har du en foretrukket akademisk verilog cpu? Jeg leder stadig efter, at en person, der er "lige rigtigt".