13 TOUCHSCREEN CH 004 DS0013 Touch Screen Control of The LEDs
13 TOUCHSCREEN CH 004 DS0013 Touch Screen Control of The LEDs
Overview
In this session we combine our experience of controlling the RGB LEDs with PWM and a microprocessor, as well as
the ability to detect points on the touchscreen. We will control the color of the LEDs by picking a color from a color
map displayed on the TFT panel. The final stage (optional) is to load your design in to the NB3000 Flash memory and
add the ability to auto-boot your design on power up of the NB3000.
Prerequisites
This tutorial assumes you have an elementary understanding of how to create a System-on-FPGA design in Altium
Designer using OpenBus and Schematic Documents, how to configure and break-out peripherals and their
connections, and how to create a linked embedded project with the Software Platform Builder. In addition, it builds on
the work done in the previous tutorial Discovery Session 12. No additional information is required.
Design detail
This exercise builds on the design done in Discovery Session 12, adding the following components:
Component
LED_R[7..0]
LED_G[7..0]
LED_B[7..0]
Library
Name in Library
OpenBus Palette
LED controller
LEDS_RGB
The design will have the TERMINAL instrument removed as it will no longer be needed.
4. In your TFT_LEDs_OB.OpenBus document, replace the Terminal Instrument component with the LED
Controller from the OpenBus Palette. Name it LEDS on the document. The OpenBus document should then
look like Figure 1.
5. Referring to Figure 2, configure the LED Controller for 8 LEDs with Bus Enable/Output and RGB boxes both
checked, and Pins selected for Interface Type.
6. Open TFT_LEDs_TOP.SchDoc (your top-level schematic) again, and use DesignSynchronize Sheet
Entries and Ports to add the three sheet entries for breaking out the RGB LED signals.
7. Add the LEDS_RGB port plug-in component from the FPGA NB3000 Port Plug-In library.
8. Complete TFT_LEDs_TOP.SchDoc to wire up the RGB LEDs, as shown in Figure 3.
11. Open the Embedded Project Options by right-clicking on the embedded project and choosing Project Options
from the popup.
12. Drill-down to the Linker\Miscellaneous options, and add the switch
--import-object="rgbcolors.bmp" to the Additional linker options section, as shown in Figure 5.
This links a file named rgbcolors.bmp to the overall project code after compilation so we can access the
bitmap directly in our code and display it on the TFT panel.
13. Make sure that rgbcolors.bmp is saved in your embedded project folder otherwise the linker will fail as
it wont find it. This file is the 320 x 240 color palette we will be picking colors from for the LEDs shown in
Figure 6.
14. As we used the previous tutorial project as the basis for this one, all we should have to do is now add new C
code in main.c. Just to be on the safe side, check the Configure Memory tab as well to make sure its
configured with the external SRAM split into 512KB of ROM area and 512KB of RAM area.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include
#include
#include
#include
#include
#include
#include
<graphics.h>
<touchscreen.h>
<pointer.h>
<drv_led.h>
"generic_devices.h"
"devices.h"
"led_info.h"
15. Replace the C code in main.c from Discovery Session 12 with the code listed in Table 2 save your work.
16. Flip to Devices View, and rebuild and download your updated design. You will be prompted to calibrate the
TFT touch panel first, and then you can pick a color for the LEDs from the palette on the TFT panel.
Extend the design to allow control of each individual LED, using the alternative palette bitmap palette.bmp
as shown in Figure 7.
Make it such that you can touch an LED number on the display to select that LED, and then pick a color for the
LED in the palette. This file is located in the tutorial folder also.
Library
SPI_DOUT
SPI_DIN
SPI_CLK
Name in Library
SPI
OpenBus Palette
SPI Bootloader
SPI Bus
SPI_MODE
SPI_SEL
Figure 8. OpenBus System for the TFT_LEDs project with SPI Bootloader added.
19. Referring to Figure 9, configure the SPI Bootloader component to load 512KB from SPI FLASH start address
zero, to destination address 0x0100_0000 in the RAM we are setting it up this way because the XRAM code
memory region we defined in our embedded project starts at this address. Code that executed from RAM that
previously had to be downloaded using Up to Date Download, will now be loaded on startup by this IP core
from the NB3000s SPI FLASH chip.
20. Click the Manage Signals button to open the OpenBus Signal Manager shown in Figure 10. Click in the Net
to connect to field beside the TSK3000A(TSK3000A_1) component entry, and type in the net name for the
reset line for the CPU we will call this CPU_RST. Likewise, re-name the reset nets for the
Arbiter(WB_MULTIMASTER_1) and the SRAM Controller(XRAM) to MM_RST this gives the memory and
memory access component (the Arbiter) their own reset signal. The CPU_RST signal can be used by the
bootloader to give it exclusive access to the memory on start-up. Click OK to accept the changes, and save
your work.
21. Open the TFT_LEDs_TOP.SchDoc schematic and use DesignSynchronize Sheet Entries and Ports to
update the U_TFT_LEDs_OB sheet symbol shown in Figure 3. Note that you will remove the RST_I sheet
entry and add the WB_BOOTLOADER_V2_1, CPU_RST and MM_RST sheet entries.
22. Place the SPI Bus port plug-in component on the sheet, as well as the necessary pre-defined
WB_BOOTLOADER harness connector (found in PlaceHarnessPre-defined Harness Connector).
23. Wire up the new connections as shown in Figure 11, paying particular attention to the order of the harness
entries, and the reset signals. The SPI Bootloader component uses the CPU_HOLD signal to hold the CPU
and other components in a RESET state while it uploads the content of the SPI FLASH into XRAM. If these
signals arent wired correctly, the circuit will not boot.
24. Save your changes to the schematic then switch Devices View to build and download the updated hardware
design to the NB3000 you should note that so far it does not operate any differently than before. The next
step is to use the NB3000 Instrument to download our FPGA bit file and embedded code HEX files to the
FLASH boot ROMs on the NB3000.
26. Click the FPGA Boot button to bring up the Flash RAM Controller For FPGA Boot dialog. At the right of the
dialogs File Name field, click the ellipsis
to browse for the FPGA bit file we will use. The file needed
(assuming previously used names were kept) will be under your \Project folder path as \Project
Outputs\NB3000XN_04\tft_leds_cclk.bit this is the bit file used to program the FPGA itself. This
dialog should now look like Figure 13. Do not click OK yet!
27. Next, click the Program to Flash button to download the bit file selected. It could take a minute or two (or
more) depending on your system. The status of the download is shown in the lower left border of Altium
Designers main window. Click OK once the download is complete to close the notification message, and
again to close the Flash controller dialog.
28. Now we need to do the same with our embedded code, to allow the SPI bootloader to copy it from startup
from the FLASH to the XRAM memory. Click the Embedded button on the FLASH RAM control section. You
will see the same dialog open, but this time we will be browsing for the embedded program HEX file. The HEX
file needed will be in the path \Embedded\Output\embedded_tft_leds_system_ROM_XMEM.hex. Once
you have selected this file for download, click the Save File to Flash button as done before, then OK and OK
again.
10
29. Referring to Figure 14, click the Settings button on the Nanoboard Controllers instrument. You will see the
Firmware Options dialog appear (see Figure 15). Set the Auto-boot option to use Serial Flash, and click OK.
30. We are now ready to perform a hard reboot of the NB3000. Power off the NB3000 with the power switch at the
rear right, wait a second or two, and then power it up again. You will notice a delay while the FPGA bit file is
loaded into the FPGA, then the SPI Bootloader part of the FPGA design itself loads the code from the
FLASH to XRAM, and releases the CPU from reset to allow the design to run. Try timing this entire process
from the flick of the power switch approximately how long does it take to boot?
11
Revision History
Date
Revision No.
Changes
29-Jul-2009
1.0
12