Sunteți pe pagina 1din 12

Discovery Session 13

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

FPGA NB3000 Port Plug-In.IntLib

LEDS_RGB

Table 1. List of components required to be added to the design

The design will have the TERMINAL instrument removed as it will no longer be needed.

DS0013 - Touch Screen Control of the LEDs

Tutorial steps preparing the hardware


1. Copy all the files from Discovery Session 12 (Touch Screen Control) into a new folder.
2. Rename the project, OpenBus and Schematic Documents as TFT_LEDs.PrjFpg, TFT_LEDs_TOP.SchDoc,
and TFT_LEDs_OB.OpenBus respectively. Also, be sure to rename the matching harness definition files
TFT_TOUCH.Harness to TFT_LEDs_TOP.Harness and so on.
3. Upon opening the project, you will have to re-add the schematic and OpenBus documents to the project. You
will also have to edit the Filename parameter of the OpenBus sheet symbol to point to the right file compile
the project and Save All.

Figure 1. OpenBus System for the TFT_LEDs project.

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.

Figure 2. LED Controller Configuration.

DS0013 - Touch Screen Control of the LEDs

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.

Figure 3. Updated top-level schematic including LEDs and RGB controller.

9. In the attached Embedded Project (still named Embedded_TFT_Touch.PrjEmb), open the


TFT_TOUCH.SWPlatform document. Delete the Serial Device I/O Context, Virtual Terminal Driver, and
Terminal Wrapper from the stacks table.
10. Click Import from FPGA to bring in the wrapper for the LED Controller component, and grow the stack to
include the LED Controller Driver it should appear as shown in Figure 4.

Figure 4. Software Stack for Embedded_TFT_Touch.PrjEmb

DS0013 - Touch Screen Control of the LEDs

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.

Figure 5. Linker option to include color bitmap in HEX file.

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.

Figure 6. rgbcolors.bmp - the palette picker we will display on the TFT.

DS0013 - Touch Screen Control of the LEDs

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"

#define WIDTH 320


#define HEIGHT 240
char *cal1 = "Touch screen at marker";
graphics_t * display;
canvas_t * canvas;
touchscreen_t * tft_touch;
touchscreen_data_t * position;
touchscreen_callback_t callback;
pointer_t * ptr;
pointer_state_t * pointer_state;
led_t * leds;
extern __no_sdata graphics_bitmap_t _lc_ub_rgbcolors_bmp; // linker name for beginning of bitmap block
extern __no_sdata graphics_bitmap_t _lc_ue_rgbcolors_bmp;
graphics_bitmap_t * bmp = &_lc_ub_rgbcolors_bmp;
void update_leds (const uint32_t * col_buff);
void set_all_leds (uint32_t value);
static void draw_mark(int x, int y, int width, int height, void *vp);
void main (void)
{
// Connect to our drivers for the TFT, touch sensor.
tft_touch = touchscreen_open(TOUCHSCREEN_1);
ptr = pointer_open(POINTER_1);
display = graphics_open(GRAPHICS_1);
canvas = graphics_get_visible_canvas(display);
leds = led_open(DRV_LED_1);
// Clear screen
graphics_fill_canvas(canvas, BLACK);
graphics_set_visible_canvas(display, canvas);
// Update display and turn off LEDs
while(!graphics_visible_canvas_is_set(display));
led_turn_all_off(leds);
// Set up and calibrate touch screen.
touchscreen_set_callback(tft_touch, draw_mark, canvas);
while(!touchscreen_calibrate(tft_touch, 320, 240))
{
set_all_leds(0xFF0000); // If Touchscreen can't calibrate RED ALERT!
}
led_turn_all_off(leds);
// Put colormap on TFT
graphics_draw_bitmap(canvas, bmp, 0, 0, 320, 240, 0);
graphics_set_visible_canvas(display, canvas);

DS0013 - Touch Screen Control of the LEDs

// Start picking colors!


while(1)
{
if (pointer_update(ptr, pointer_state))
{
set_all_leds(graphics_get_pixel(canvas, pointer_state->x, pointer_state->y));
}
}
}
void set_all_leds (uint32_t value)
{
for(int i = 0; i < LEDS_NUM_LED_IDS; )
{
led_set_intensity(leds, i++, (uint8_t)(value>>16)); // Red
led_set_intensity(leds, i++, (uint8_t)(value>>8)); // Green
led_set_intensity(leds, i++, (uint8_t)value);
// Blue
}
}
static void draw_mark(int x, int y, int width, int height, void *vp)
{
graphics_draw_circle(canvas, x, y, 10, 0xff00ff);
graphics_draw_line(canvas, x - 15, y, x + 15, y, 0x00ffff);
graphics_draw_line(canvas, x, y - 15, x, y + 15, 0x00ffff);
graphics_draw_string(canvas, 50, 110, cal1, NULL, 0xffffff, 0);
graphics_set_visible_canvas(display, canvas);
}

Table 2. Code listing for TFT_LEDs

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.

Something more for you to try

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.

Figure 7. The palette.bmp file for extending project capability.

DS0013 - Touch Screen Control of the LEDs

Optional: configuring your design for auto-boot


This optional add-on exercise builds on the design work done above, adding the following components:
Component

Library

SPI_DOUT
SPI_DIN
SPI_CLK

Name in Library

SPI

OpenBus Palette

SPI Bootloader

FPGA NB3000 Port Plug-In.IntLib

SPI Bus

SPI_MODE
SPI_SEL

Table 3 List of components required to be added to the design.

Figure 8. OpenBus System for the TFT_LEDs project with SPI Bootloader added.

DS0013 - Touch Screen Control of the LEDs

Tutorial steps preparing the hardware


17. Open your TFT_LEDs_OB.OpenBus document, and add the SPI Bootloader component (refer to Table 3)
from the OpenBus Palette.
18. Add an extra port
shown in Figure 8.

to the WB_MULTIMASTER (Arbiter) component, and link in the SPI Bootloader as

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.

Figure 10. OpenBus Resets

Figure 9. SPI Bootloader Config.

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.

DS0013 - Touch Screen Control of the LEDs

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.

Figure 11. Updated top-level schematic (lower section only shown).

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.

DS0013 - Touch Screen Control of the LEDs

Tutorial Steps Downloading the boot images to FLASH


25. Right-click on the NB3000 icon in Devices View, and choose Instrument from the popup menu. The NB3000
Nanoboard Controller will be shown as in Figure 12. Note that the FPGA Boot FLASH and Embedded FLASH
controls are highlighted with the red rounded square.

Figure 12. Nanoboard Controller (FLASH control buttons highlighted).

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!

Figure 13. Flash RAM Controller dialog.

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.

DS0013 - Touch Screen Control of the LEDs

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?

Figure 14. Getting to the NB3000 Boot Options.

Figure 15. NB3000 Firmware Options.

DS0013 - Touch Screen Control of the LEDs

11

Revision History
Date

Revision No.

Changes

29-Jul-2009

1.0

New document release

Software, hardware, documentation and related materials:


Copyright 2009 Altium Limited.
All rights reserved. You are permitted to print this document provided that (1) the use of such is for personal use only and will not be copied or
posted on any network computer or broadcast in any media, and (2) no modifications of the document is made. Unauthorized duplication, in whole
or part, of this document by any means, mechanical or electronic, including translation into another language, except for brief excerpts in published
reviews, is prohibited without the express written permission of Altium Limited. Unauthorized duplication of this work may also be prohibited by local
statute. Violators may be subject to both criminal and civil penalties, including fines and/or imprisonment. Altium, Altium Designer, Board Insight,
Design Explorer, DXP, LiveDesign, NanoBoard, NanoTalk, P-CAD, SimCode, Situs, TASKING, and Topological Autorouting and their respective
logos are trademarks or registered trademarks of Altium Limited or its subsidiaries. All other registered or unregistered trademarks referenced
herein are the property of their respective owners and no trademark rights to the same are claimed.

DS0013 - Touch Screen Control of the LEDs

12

S-ar putea să vă placă și