Lab 1: FPGA and MCU Setup and Testing
Introduction
In this lab I created code, and testbenches to control a 7-segment display. A user can use the 4 DIP switches to control the 7 segment display to show 0-F on the hexidecimal scale.
Technical Documentation
The source code for this project can be found in this github repository.
Block Diagram
The block diagram in Figure 1 demonstrates the overall architecture of the design. The top-level module top includes 4 submodules: the high-speed oscillator block (hf_osc), the led2 module, the led1 module, the led0 module and the seven segment display module.
Schematic
Figure 2 shows which pins were connected to the 7 segment display and which parts and resistor values I used.
Finding Resistor Values
Figure 3 shows the physical layout of the design. The FPGA pins are connected to a resistor before entering into the seven segment display to ensure that the LED doesn’t receive too much current and thus burns out. For the seven segment display I used 1k\(\Omega\) resistors on each segment (see math below).
For the LEDs I used about 220\(\Omega\) because that is a reasonable amount for a red LED.
Results and Discussion
I tested the circuit and I was able to get all the segments to light up and control them through the dip switches. Additionally, the LEDs also worked as planned.
LED0 waves
LED1 waves
Seven Segment waves
I think I spent a total of 25-27 hours on this lab. I ran into major issues with programming the FPGA which ended up gating me for about 4 days. Overall, the main difficulty of this lab was getting the platforms to work and getting myself familiar with them.
AI prototype
I used the given the prompt, “Write SystemVerilog HDL to leverage the internal high speed oscillator in the Lattice UP5K FPGA and blink an LED at 2 Hz. Take full advantage of SystemVerilog syntax, for example, using logic instead of wire and reg,” and gave it to ChatGPT. I chose ChatGPT because it is free for a certain number of questions. It gave me the following code:
module led_blinker_2hz (
output logic led
);
// Internal oscillator signal
logic clk_hf;
// Instantiate the internal high-frequency oscillator
SB_HFOSC #(
.CLKHF_DIV("0b00") // No division: 48 MHz
) hfosc_inst (
.CLKHFEN(1'b1), // Enable oscillator
.CLKHFPU(1'b1), // Power up oscillator
.CLKHF(clk_hf) // Output clock
);
// Counter to generate ~2 Hz blink rate from 48 MHz clock
localparam int COUNTER_MAX = 24_000_000; // Half period at 48 MHz
logic [$clog2(COUNTER_MAX)-1:0] counter = 0;
// LED state toggle
always_ff @(posedge clk_hf) begin
if (counter == COUNTER_MAX - 1) begin
counter <= 0;
led <= ~led;
end else begin
counter <= counter + 1;
end
end
endmoduleThe first thing that I noticed about this code is that it doesn’t have a reset option in it. From my lab I found that you should definitely have a reset option so that you can put your LED into a known state. I then proceeded to point that out to the ChatGPT and it came back with more code. This output (not pictured) had some problems too. One it declared a counter number with no size or type. I could have nudged it more but I didn’t feel like it and didn’t know how to improve it because I wasn’t prompting it correctly.
Overall I would say the output was good as a bare bones and could have helped me think about how to do the problem but I would not copy and paste the output directly. What I decided to do was give ChatGPT one of my files but I made some errors in it, more along the lines of forgetting a semicolon. ChatGPT was great at catching those errors. So if I were to ever use AI in my job I would use it as another set of eyes to debug.