Embedded Systems Spring 2024
HW 6 VGA

Name: Mason Brady
Email: mrbrady1@fortlewis.edu

HW 6

Introduction: This homework is an introduction to VGA ports

Materials: gvim, vivado

1) Repeat section 2


I copied the code from the website. I'm just going to copy it below because I'm going to overwrite it for the next step and this makes it easier for me to come back to it if I need it. This code is pretty straight forward and had no major issues.

module VGA_module(clk25, pixel_data, sx, sy, red, green, blue, Hsync, Vsync, pixel_addr);
    input clk25;
    input [7:0] pixel_data;
    input [7:0] sx, sy;
    output reg [2:0] red, green , blue;
    output reg Hsync, Vsync;
    output reg [12:0] pixel_addr;
    localparam HDISP = 640;
    localparam HFP = 16;
    localparam HPW = 96;
    localparam HLIM = 800;
    localparam VDISP = 480;
    localparam VFP = 10;
    localparam VPW = 2;
    localparam VLIM = 525;
   
    reg [10:0] hcount = 0;
    reg [10:0] vcount = 0;
    reg enable = 0;
   
    always @(posedge clk25) begin
        if(hcount < HLIM - 1) hcount <= hcount + 1;
        else begin
            hcount <= 0;
            if(vcount < VLIM - 1) vcount <= vcount + 1;
            else vcount <= 0;
        end
        if(vcount > sy) begin
            pixel_addr <= -1;
            enable <= 0;
        end
        else begin
            if (hcount < sx) begin
                enable <= 1;
                pixel_addr <= pixel_addr + 1;
            end else enable <= 0;
        end
        if(enable == 1) begin
            red <= pixel_data [2:0];
            green <= pixel_data [5:3];
            blue <= pixel_data [7:6];
        end else begin
            red <= 3'b000;
            green <= 3'b000;
            blue <= 2'b00;
        end
        if (hcount > (HDISP + HFP) && hcount <= (HDISP + HFP + HPW)) Hsync <= 0;
        else Hsync <= 1;
        if (vcount >= (VDISP + VFP) && vcount <= (VDISP + VFP + VPW)) Vsync <= 0;
        else Vsync <= 1;
    end
endmodule
module VGA_top_module(clk, vgaRed, vgaGreen, vgaBlue, Hsync, Vsync);

    input clk;
    output [2:0] vgaRed;
    output [2:0] vgaGreen;
    output [1:0] vgaBlue;
    output Hsync;
    output Vsync;
   
    parameter sx = 80;
    parameter sy = 80;
   
    wire clk25;
    wire [12:0] pixel_addr;
    wire [7:0] pixel_data;
   
    clk_wiz_0 clock(clk25, clk);
    dist_mem_gen_0 memory(.a(pixel_addr), .spo(pixel_data));
   
    VGA_module VGA(.clk25(clk25), .pixel_data(pixel_data), .sx(sx), .sy(sy), .red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .Hsync(Hsync), .Vsync(Vsync), .pixel_addr(pixel_addr));

endmodule

This created the following display:


Figure 1. Basys 3 Displays by a Basys 3 VGA.

Part 2)
For part two we had to write our own clock divider. Here I ran into some issues because I accidentally put my clkout assignment inside the if statement which broke everything but this was also pretty straightforward. I'm trying to learn to use more advanced assingment techniques to get used to them so I used this one line variable case statement that we went over before. Another way to do it would to just be to encapsulate it in an if else.

Figure 2. Clock Divider 1/4.

The display when you mess this up is just black but otherwise looks identical to the one above in Figure 1.

Part 3)
F
or part 3 we had to display solid colors. My monitor was too fancy for the VGA and refused to downscale to 640x480 so I just changed the sx and sy limits to 640 and 480 respectively.I'm still confused why this yielded a horizontal rectangle and not a vertical one but it works for this purpose. I then removed the RGB assingments in the code above and replaced them with a case statement. For the first demo color remained constant and for the second demo I just incremented color by one every 25000000 counts (1 second) and reset back to 1 (not 0 since that's white).

Figure 3. Case statement for color switching.

For the first demo I just kept color = 2'b0; which just set it to white. For the second demo I added this code above it.



Figure 4. Color incrementing for changing colors






Discussion:
This weeks work was pretty fun didn't mind this one at all.