Table of Contents
In this lab you will create a Programmable Interval Timer (PIT) in SystemVerilog that is accessible through the CPU’s memory-mapped AXI bus.
Objectives
- Gain experience with IP-based hardware design.
- Learn about, and implement, the AXI protocol.
- Practice writing timing-sensitive HDL code.
Preliminary
In the real-time clock lab, you used a fixed-interval timer (FIT) from the IP catalog. As you may recall, the FIT generates interrupts at a fixed rate, based upon a single build parameter that cannot be changed once you have built the FPGA hardware. This makes the FIT very easy to use once your system is built, but the FIT is very inflexible. For this lab you are going to build a Programmable Interval Timer (PIT) in SystemVerilog and add it to the hardware system.
The PIT will be an AXI peripheral, allowing the CPU to control the PIT’s behavior through memory-mapped registers. The PIT logic itself is very simple, and you will likely have made more complex designs in a previous class. The challenging part of this lab is getting the AXI interface correct, which has strict protocol requirements.
You will work with two different Vivado projects in this lab:
- The first project will only contain your PIT module and some helper IP to generate AXI traffic. This project, which is the focus of Milestone 1, will only be used for simulation, as well as checking for synthesis errors.
- In Milestone 2, you will integrate your PIT into the ECEN 427 Vivado project, which contains the actual hardware system you have been working with in previous labs. This project will be used to generate a new bitstream that includes your PIT.
Specifications
PIT Hardware Design
Your PIT module must include the following:
- A 32-bit timer-counter that decrements at the system clock rate and that is controlled by elements described below.
- Interrupt: A single interrupt output (irq). The interrupt output is active high, and is asserted for a single cycle when the counter reaches 0.
-
Registers:
-
Offset 0x00: A 32-bit programmable control register, that must be readable and writeable from the CPU. You will control the behavior of the PIT by programming specific bits in the control register, as follows:
- bit 0 - enable: enables the counter to decrement if set to ‘1’, holds the counter at its current value if set to a ‘0’.
- bit 1 - interrupt enable: enables interrupts if set to a ‘1’, disables interrupts if set to a ‘0’.
- You may use the remaining bits in the programmable control register as you see fit.
- Offset 0x04: A 32-bit delay-value register that must be readable and writeable from the CPU. This value controls the period of the interrupt output.
- Write strobes: Your PIT driver should only perform full 32-bit writes, so you may ignore s_axi_wstrb. Alternatively, you may return a SLVERR response (s_axi_bresp = 2’b10) for any write whose strobe is not 4’b1111, and leave the register unchanged. Returning SLVERR is optional and not required.
-
Offset 0x00: A 32-bit programmable control register, that must be readable and writeable from the CPU. You will control the behavior of the PIT by programming specific bits in the control register, as follows:
-
Reset: Your PIT must reset along with the rest of the system. Make sure to reset your PIT using the AXI resetn signal.
- Your PIT must reset into a state equivalent to the FIT, so that you can test that it’s working without needing to perform any register writes:
- The offset 0x00 control register must reset to 3 (i.e., enable the counter and enable interrupts).
- The offset 0x04 delay-value register must reset to 1,666,667 (16.67ms at 100MHz, which is the same period as the FIT).
- Your PIT must reset into a state equivalent to the FIT, so that you can test that it’s working without needing to perform any register writes:
PIT Behavior
- The timer-counter should auto-reload (i.e., when the timer-counter reaches 0, it should be reloaded based on the delay-value register, and continue decrementing).
- If you disable the counter, and then re-enable it, it should just continue as if it had not been disabled.
- irq must stay low whenever either the enable or interrupt enable bit is 0, even if the counter is at 0 (e.g., if you happen to disable it exactly when the counter == 0).
- During normal operation, you program the delay-value register to contain a value that indicates how often an interrupt occurs. If you set the delay-value register to N, then an interrupt should occur every N cycles. For example, when the delay-value register contains a ‘2’, the interrupt output is a square wave with a 50% duty cycle. When the register is set to ‘3’, an interrupt occurs every third cycle. You don’t have to worry about what happens when the register is set to ‘0’ or ‘1’; that behavior is undefined.
- Writing the delay-value register must reload the timer-counter, so the new period takes effect immediately rather than after the current count finishes.
Implementation
⚠️ Before you start: the starter code may have been updated since you cloned your repository. Merge the latest starter code into your repository before working on this lab. See Add Starter Code Remote if you have not set up the remote yet.
git fetch startercode git merge startercode/main
Milestone 1: Simulation Project
Important: Create your Vivado simulation project in the hw directory of your repo — start Vivado from the command line in hw, then create the project there. See the Vivado documentation for details. The grading commands below assume your project lives in hw; if it doesn’t, make sim_pit and make synth_pit will fail.
To grade your lab, the TAs will run the following:
cd hw
make sim_pit
make clean
make synth_pit
make test_pit
The sim_pit and synth_pit targets use your own Vivado project and test bench. The test_pit target runs a provided stress test against your pit.sv; see AXI Stress Test below.
The make sim_pit target runs Vivado and does two things:
- It sources sim_proj.tcl, which builds your Vivado project (you don’t commit your Vivado project to your repo, only this Tcl file).
- To create this file, you will need to make your own Vivado simulation project that contains the AXI VIP and your module, connected appropriately. The Tcl script can then be exported using the Write Tcl menu option, as described on the vivado page.
- When this script is run, it should create a Vivado project with a block diagram that uses the AXI VIP to test your module.
- It sources run_sim.tcl, which simply runs functional simulation in Vivado. This means that the Vivado project must be set up with a SystemVerilog test bench that runs the VIP-driven simulation.
- The test bench must do each of the following, and each must be visible in your waveform:
-
Reset values: After reset and before any writes, read both registers and
$displaythem (expect 3 and 1,666,667). -
Register read/write: Write each register with a value different from its reset value, read it back, and
$displayboth the written and the read value. - Periodic interrupts: Set the delay-value register to 4 and the control register to 3, and run for at least 5 interrupts. irq must be high for exactly one cycle every 4 cycles.
- Enable (bit 0): Clear it partway through a count and hold it clear for at least 10 cycles. Show that the counter holds and irq stays low. Then set it again and show that the counter continues from the value it held.
- Interrupt enable (bit 1): With the counter running, clear it for at least 2 full periods. Show that the counter keeps reloading while irq stays low. Then set it again and show that irq returns.
- Delay change: While the PIT is running, change the delay-value register (e.g., 4 → 6) and show that the new period takes effect.
-
Reset values: After reset and before any writes, read both registers and
- Your simulation log must not contain any AXI protocol warnings from the VIP (see AXI Messages). The TAs will deduct points for any such warnings.
- You must have a pre-configured waveform file (.wcfg) with signals added and organized so the TAs can verify each of the items above. It must include at least:
- The clock, resetn, and irq.
- Your control register (or its enable and interrupt enable bits), your delay-value register, and your timer-counter.
- The AXI signals for all five channels (AW, W, B, AR, R): each channel’s valid and ready, plus its address, data, or response signals. Group them by channel (e.g., with dividers) so each handshake is easy to follow.
Here is an example:

- The test bench must do each of the following, and each must be visible in your waveform:
The make clean target removes all the temporary Vivado project files. You will need to update this command to delete your simulation project files, otherwise it will prevent you from recreating the project in the next step.
The make synth_pit target runs Vivado and does two things:
- Like the above target, it sources sim_proj.tcl to create your Vivado project.
- It performs Synthesis to ensure that your PIT design can be implemented in hardware. Synthesis will check certain design rules that simulation does not check.
You may want to go back and forth between these targets as you work on your PIT design. If synthesis has errors, you will need to fix them and then go back to simulation again to verify that your changes didn’t break anything.
AXI Stress Test
Passing your VIP test bench does not mean your PIT will work in hardware. The VIP’s AXI4LITE_WRITE_BURST and AXI4LITE_READ_BURST functions always use the same forgiving timing, but the real AXI bus does not. Designs that pass the VIP but fail in hardware usually:
- use s_axi_awaddr, s_axi_wdata, or s_axi_araddr after the handshake, instead of capturing them during it;
- assume the AW and W channels arrive in the same cycle;
- make bvalid/rvalid wait for bready/rready (this hangs the CPU).
The provided stress test in hw/pit_test drives your pit_sv module with randomized AXI timing and checks it against the AXI protocol and the specification above. Run it from the hw directory with make test_pit. It ends with PIT TEST RESULT: ALL TESTS PASSED when your PIT passes, along with any warnings (e.g., s_axi_rdata changing while rvalid waits for rready), which don’t affect grading but are worth fixing. The full log is hw/pit_test_proj/sim.log, and make test_pit_gui runs the test in the waveform viewer for debugging.
Your PIT must pass this test; it is part of grading.
Before Moving On
Once sim_pit and synth_pit run without errors, and test_pit passes, you are ready to move on to Milestone 2.
IMPORTANT: Students frequently forget to commit all necessary files for the TAs to run the above commands. Make sure you commit your sim_proj.tcl file, your test bench, your waveform configuration file, and any other necessary files to your repository. It is recommended that you perform a fresh clone of your repository and run the above commands to make sure that everything is committed that needs to be.
Milestone 2: Integration
Video: Lab 6 Milestone 2 walkthrough: adding your PIT to the ECEN 427 block design, building the bitstream, and testing it with int_rate.
Once you are confident that your PIT is working correctly, integrate it into the ECEN 427 Vivado project. See the Vivado documentation for information about creating a Vivado project with the existing ECEN 427 hardware system.
Here are some tips to help you integrate your PIT:
- Make sure you connect up all of the ports
- Make sure you assign your PIT an address
- You don’t need to remove the FIT from your system. Just don’t enable its interrupt.
- You will not need to add any external ports for your IP. The only extra port that you are adding is the interrupt line and it will be an internal connection. Remember that external ports are ports that connect to a pin on the FPGA.
- Make sure that the AXI connection is hooked up to the AXI interconnect. This will involve adding a new master connection to the interconnect.
- The interrupt line from the PIT should be connected to the userspace AXI Interrupt Controller.
After it is integrated:
- Verify that all of the connections are hooked up properly by running ‘Validate Design’
- Make sure you compile a new bitstream. See Compiling a New Bitstream.
Final verification:
- Pull down the new bitstream onto your PYNQ board and install it as your boot bitstream (see Loading the new Bitstream on your PYNQ board).
- Update the int_rate application to use your PIT instead of the FIT: change this line from
SYSTEM_INTC_IRQ_FIT_MASKtoSYSTEM_INTC_IRQ_PIT_MASK. - Run int_rate. Since your PIT resets to the FIT’s period, you don’t need a driver or any register writes; verify that you are getting interrupts every 16.67ms. The TAs will grade this milestone by running your int_rate on your new bitstream.
Make sure to commit:
- Your updated int_rate.cpp.
- Your changes to the ECEN 427 project. You will need to export the Tcl file for the project, overwriting the provided ecen427.tcl file.
- Your new bitstream (both the .bit file and the .bin file).
How to Get Started
- Review the available documentation on using the Vivado software and simulating AXI IP.
- Write the PIT module, implemented in pit.sv
- Write your test bench to simulate your PIT module to make sure it works correctly.
- Run the AXI stress test (
make test_pit) to check your AXI interface against the timing the real system uses. - Complete the rest of the requirements described above.
Submission
Follow the submission instructions. Make sure that you have pushed up all your new hardware to Github, including at least:
- (Milestone 1) The sim_proj.tcl file that will be used to create your simulation project.
- (Milestone 1) Your test bench.
- (Milestone 1) The waveform configuration file.
- (Milestone 1) Your pit.sv changes.
- (Milestone 2) The changes to the ecen427.tcl file.
- (Milestone 2) Your new ecen427.bit bitstream.
- (Milestone 2) Your bitstream packaged into the ecen427.bit.bin format.
Lifelong Learning: What’s Next?
Your PIT passed the AXI VIP simulation, but a simulation only checks the scenarios your test bench happens to exercise. Professional hardware teams routinely subject their RTL to adversarial review: someone (or something) whose whole job is to find the cases you didn’t think of.
Paste your completed pit.sv into an AI tool and ask it to hunt for AXI4-Lite protocol violations and corner cases. For example: What happens if the master asserts AWVALID and WVALID in different orders, or in the same cycle? What if a read and a write arrive at the same time? Does every handshake hold VALID until READY? Push back on its claims. AI reviewers are sometimes wrong, and deciding whether a reported bug is real is exactly the skill this exercise builds. If you want to take it further, paste your test bench as well and ask which scenarios it does not cover.
AI use is encouraged (and required) for this section. This is an explicit exception to the usual policy; see the Lifelong Learning: What’s Next? page.
When you’re done, record what you learned in a few sentences in lifelong_learning/lab6.txt. Submit this file with Milestone 2; it is not required for Milestone 1.