[Solved] ECE253 Lab 2B- The Display

$25

File Name: ECE253_Lab_2B__The_Display.zip
File Size: 244.92 KB

SKU: [Solved] ECE253 Lab 2B- The Display Category: Tag:
5/5 - (1 vote)

In Lab 2B you will connect an LCD Display to your FPGA board. This is the first lab where you will build a QP-nano automata to handle multiple peripherals. The goal of this lab is to control a graphical volume bar on the LCD using the rotary encoder to adjust the volume level. When the rotary encoder is inactive for 2 seconds the overlay graphic of the LCD will disappear, leaving only the background. A click on the rotary encoder is to be used to make the volume level 0. A second click should restore the volume to its previous value. In all cases, you should only repaint the necessary parts of the volume bar do not repaint the entire screen on updates of the volume bar! In addition to this, four push-button switches will be used to print different text items on the LCD when they are clicked. Your system will consist of:

  • TFT LCD Display (ILI9340/ILI9341)
  • Rotary Encoder
  • Push-Button Switches

1 Introduction

The LCD peripheral uses a SPI digital interface. A SPI interface to handle the communication with the peripherals microcontroller (ILI9340/ILI9341) could be implemented using software bit-level protocol coding or by making use of a hardware FSM peripheral controller. The benefit of software is program level flexibility, while a hardware interface allows for a much higher speed interface (5Mb/s = 10MHz clock in this case). Typical Arduino solutions for this display use a software interface, limiting the rate to about 100kb/s. The SPI module provided by Vivado is named AXI Quad SPI and for our LCD screen to work properly we also need to add another AXI GPIO module to the block design. This additional GPIO sets the Data/Command value for the Display (which ought to be part of the SPI protocol as a 9-bit word), but somehow that option does not work in these displays. Effectively, the interface needs to synchronize the actions of SPI hardware and the other GPIO interface so that commands and data are interpreted properly.

In this lab, you need to modify the FPGA firmware to add the SPI and GPIO peripherals to support the encoder, display and four push-button switches. You will then need to build QP-nano code to implement a screen overlay volume that displays the value of volume stored as a fixed point value from 0-63. The present value of volume is conveyed to the viewer by using a rectangular image on the LCD that is at least 1/2 of the display wide, with a bar proportional to the set value and a fixed background. The background can be of any color with 4040 triangles on top of it. Each triangle will be filled with a color that should be different from the background color. It is up to you whether you create shapes with or without borders. You can be as creative as you like with your choice of background. Two examples are shown in Figure 1.

Figure 1: Two different backgrounds. Any of these can be implemented. Be creative with your design.

The overlay for the volume bar should appear on top of the background. It should appear immediately as the encoder is turned, and stay on, updating dynamically until 2 seconds after the last encoder update. In addition to the volume bar, different text items should be displayed in response to pressing of different push-button switches (For example: pressing btn1 prints Mode:1, pressing btn2 prints Mode:2, etc.). If there is no activity on the encoder or switches for 2 seconds, the volume bar and text disappear, leaving only the background on the display. The goal here is to get two timed protocol behaviors and timed events into the software behavior. You can arrive at the final design in several ways, but we suggest making a separate program to run the display and then incrementally merge the desired behavior into a single QP state

chart.

Figure 2: The modifications to the hardware Block Design are shown above. Detailed instructions are provided below. In particular, note the reset spi port and the Clocking Wizard module.

2 Hardware Modifications

  1. Add GPIO module to supply the Data / Command signal.
    • With the Block Design open, Right click and choose Add IP.
    • Type AXI GPIO and add the module to the design.
    • Left click on the newly created module and change the name to spi dc.
    • Click on Run Connection Automation and select /spi dc/S AXI/
    • Right click on the spi dc module, select Customize Block, choose All Outputs and make the GPIO width 1.
    • Left Click on the + next to GPIO to expand the IO ports.
    • Right click on the port dash next to the terminal labeled gpio io o[0:0] and make external. Select the port and rename it to spi dc.
  2. Createing a 10MHz SPI Clock (ext spi clk )
    • Add a new Clocking Wizard block.
    • Connect the input of this clock clk in1 from the ui clk (main system clock) of the MIG.
    • Right click on the new Clocking Wizard, select Customize Block and click on the tab Output Clocks.
    • On the first tab, Ensure that the input clock is set to 100MHz.
    • Switch to the Output Clocks tab, ensure only clk out1 is selected and set it to 10MHz.
    • This results in an effective SPI clock of 5MHz(the SPI block divides by 2). You may increase this clock to 20MHz for 10MHz SPI clock if you wish.
    • Uncheck the reset and locked options in the optional input/output section.
  3. Add SPI module
    • With the Block Design open, Right click and choose Add IP.
    • Type AXI Quad SPI and add the module to the design.
    • Left click on the newly created module and change the name to spi.
    • Click on Run Connection Automation and select /spi/AXI lite/
    • Connect the Clocking Wizard pin clk out1 to ext spi clk
    • Right click on spi module, select Customize Block and make the settings: Mode: Standard, Transaction Width: 8, Frequency Ratio: 2, of Slaves: 1, Check Enable Master Mode, Check Enable FIFO, FIFO

Depth: 256. UNCHECK Enable STARTUPE2 Primitive.

  • Left Click on the + next to SPI 0 to expand the IO ports.
  • Right Click on the port dash next to the terminal labeled io0 o (letter i, letter o, number zero, underscore, letter o) and choose Make External.
  • Repeat the step to Make External for the signals sck o, ss o[0:0]
  • If any of these ports end up with a trailing 0 on the end, remove it so they end up with the same name as the

constraints below.

  • Right click near the btnCpuReset pin and Create Port.
  • Name the new port reset spi and select output.
  • Draw a wire to connect reset spi to the same wire at btnCpuReset

2.1 Update Constraints File

You now have to assign pins for the GPIO and the SPI signals spi dc, io0 o, sck o, ss o, and reset spi by updating the constraints file. You may want to use a Pmod header (for example, JB) for convenience. For the rotary encoder, the Pmod header pins should have been already assigned from Lab 2A.

2.2 Export to xSDK

After modifying your hardware, make sure that the depth of the debug core (created in Lab 2A) is less than or equal to 32768. Otherwise you may run out of space on the FPGA, and implementation will fail. Run

synthesis, implementation, generate a new bitstream and export your Vivado design to xSDK. Make sure the Board Support Package which you intend to use for the lab is updated. To make sure it is updated, open the BSP project, open system.mss and click Re-generate BSP Sources. In SDK, do not forget to run the linker script, map all sections of the memory to the DDR (mig 7series 0 memaddr) and not the BRAM. Also make sure that the the heap and stack sizes are 4096 (4 KB).

2.3 Wiring LCD Display to Nexys4 DDR Board

Figure 3 shows the pinouts for connecting the LCD display to the board. Please view the Nexys 4 manual for the pinout of the Pmod (or whatever pins you have used). The connection should be achieved by soldering a male pin header to the display (if it didnt already come with one soldered in), and then using male-female jumper wires back to the FPGA board. In Figure 3, we have used a HiLetgo ILI9341 2.8 SPI TFT LCD Display which already comes with the pin header.

In particular note that sticking a pin header through the holes on the LCD PCB will not result any sort of reliable connection. Pin header to pin header connections rely on spring action to achieve a usable connection, which an empty hole on the LCD board does not supply. Soldering is necessary in this case.

3 Software Test

Create a new Application project and copy four files lcd test.c, lcd.c, lcd.h and fonts.c . Program your FPGA and run the lcd test on your FPGA board. If the Hello World displays on the screen your hardware configuration is correct.

If the LCD does not work right away, check the wiring to the LCD and check the names of your io ports. The LCD should turn white and then draw the provided test display.

Figure 3: The Figure above shows HiLetgo ILI9341 2.8 SPI TFT LCD Display and how to connect the wires. The list of wires next to the display is in the format of LCD Pin Name Color, signal. To connect the signal wires to your Nexys4 DDR board, follow your updated constraints file. The wire color is consistent for the signal name.

4 QP Nano Program Design

The goal of this lab is to control a graphical volume bar on the LCD using the rotary encoder to adjust the volume. When the rotary encoder is inactive for 2 seconds the volume bar will disappear, leaving only the background.

  • Provided are two sets of example code, one is a partial example of QP nano. The other is an example of using the LCD. You should build your application around the QP nano framework.
    • Copy the QP nano example files as a template for your project.
    • Fill out BSP Init() with hardware initializations for your peripherals.
    • Define interrupt service routines like in c. These will be similar to Lab 2a. Edit bsp.c to connect interrupts to your Finite State Machine. This file is heavily commented, use the comments to help fill in the missing code.
    • c is an example state machine definition. Read it to understand how QP Nano models a FSM. Replace this with your own state machine.
    • q*.c and q*.h contain the QP Nano code. Do not modify these. Read to understand.
    • lcd test.c is an example of using the LCD. Include this into your QP Nano project.
  • Create a simple custom LCD function to draw your background.
  • Draw a rectangular block on the LCD to represent the volume the rotary encoder is at. The graphic must be proportional to the set value.
  • When twisting left decrease the volume. Twisting right increase the volume.
  • When the rotary encoder push button is pressed, reset the volume to 0.
  • When different push-button switches on your board are pressed, print different text values to the display.
  • Consider the design of your GUI and how the overlay should work for your volume bar. An overlay is a shape (sprite) which appears on top of a background that could incorporate a custom image. They are things like video game characters which walk around of a fixed image of a background.
  • Use the timer to measure the number of seconds since last activity on the rotary encoder or push-button switches.
  • When the inactivity time is 2 seconds, leave only the background.

5 Reporting

  1. Report on how you created your function for drawing the background and include a picture of your background pattern with your LCD photos.
  2. Report where you acquired your LCD from, and include a photo of the front and back of the LCD with your report.

(Let us know if you got it on time and if you had any problems getting it setup.)

  1. Explain how you integrated the LCD and the Rotary Encoder using QP-nano.
  2. Explain how you detect inactivity and how you quickly remove the overlay graphic or text.
  3. Draw a statechart that models the behavior of your system.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] ECE253 Lab 2B- The Display[Solved] ECE253 Lab 2B- The Display
$25