Output_Devices
LEDs
If you need more LEDs than the 4 built-in ones, you can buy an LED Pmod. The Digilent Pmod8LD has 8 leds, or you can make your own. An 8-LED Pmod is useful for simple diagnostics, displaying the value of a byte as a bit pattern.
Here is an example with the Pmod connected to Pmod 3 / 4.
Make a directory called leds8 and add:
leds.pcf
leds.v
Makefile
RGB LEDs
RGB LEDS have three connections for red, green and blue, and can display combination of those colours, such as cyan, tallow and magenta.
A simple program to set the RGB according to three slider switches is as follows. Connect an RGB LED to pins 1, 2 and 3 of Pmod 11 (top row). A breadboard adapter from the myStorm Pmod hackers kit can be used to do this. You need resistors on each of the RGB pins to limit the current.
Create a directory called rgbled and add:
rgbled.pcf:
rgbled.v:
Makefile:
You can then use the first three dip switches on the board to set the colour of the RGB LED.
Seven segment displays
2-Digit Digilent Pmod
Digilent make the PmodSSD, a two-digit 7-segment display Pmod.
Seven segment displays are useful for diagnostics and as a simple user interface. They can display decimal or hex numbers.
Seven segment displays usually have a pin for each segment and another for the dot that optionally separates digits. The digits themselves are usually multiplexed, with a selector pin for each digit. Each digit must be selected, and its segments activated about one thousand times a second.
Here is an example of using a 7-segment display to 2-digit hex number. The example uses Pmod 7 and 9 (top row).
Note the code in this example is modified from that in Simon Monk’s Programming FPGAs book.
Create a directory called hex7seg and add:
decoder_7_seg_hex.v:
Add the multiplexer, display_7_seg_hex.v
Add seg_test.v
And seg_test.pcf:
Add a Makefile:
When you run this, you should see “fb” appear on the display.
Seven segment displays are also supported by the BlackSoC mod_pmodssd module. See the BlackSoC otl-demo example.
8-digit SPI device
There are also 7-segment modules that use an SPI interface. They typically have multiple digits, such as this 8-digit version.
Here is a BlackSoC example that displays a number on such a device.
LED Panels
You can use BlackSoC to drive an LED Panel. The Towers of Hanoi example, which comes from icoSoC, uses the module mod_ledpanel to drive the panel.
The panel is an Adafruit 32x32 one. It needs a 4A 12v power supply. The PCB for the Pmod comes from bikerglen at OSHPark. There are other BlackSoC examples that use the LED panel including Conway’s Game of Life.
VGA output
Driving a VGA monitor required a Pmod such as the Digilent PmodVGA. It uses 4-bits for each of the red, green and blue colours.
We will concentrate on supporting the standard 640 x 480 pixel resolution, but it is possible to support higher frequencies.
A clock for 640 x 480 VGA can be produced in a few different ways. Using a pre-scaler to divide the 100 Mhz clock by 3 to produce a 33.3Mhz clock works, but is slightly out of spec. Using a pre-scaler to produce a 25Mhz clock works, but not all VGA monitors support that frequency. Using a PLL to produce a 31.5 Mhz clock is the most accurate way.
We will use the pong example from the fpgafun web site to demonstrate VGA output. The only change to the code from the fpgafun.com is the addition of the 31.5Mhz clock using a PLL. This means that we are not using the full 4-bit VGA output. Instead we map the single R, G and B signals used by the code to the pin corresponding to the most significant bit of the 4-bits used by the Digilent Pmod.
This example needs a Digilent VGA Pmod in Pmods 7/8/9/10 and a rotary encoder for moving the paddle in Pmod3, pins 1 and 2 (top row). Rotary sensors are explained in the Sensors chapter below.
Make a directory called pong, and add:
pong.v
Get hvsync_generator.v from the fpga.fun site.
pong.pcf
And a Makefile:
Use the rotary encoder to move the paddle.
VGA Text
BlackSoC contains a module for writing text to a VGA monitor with 30 rows of 80 column text. There is an example program for it, which reads text from /dev/ttyUSB0 and writes it to the screen.
Neopixels
WS2811, WS2812 and WS2812B neopixel strips use PWM signals over a single wire to switch and set the colour of each pixel in a strip. Longer strips need a separate power supply.
Here is an example of driving a short 8 neopixel strip.
OLED displays
I2C OLED displays
Some of the cheaper OLED displays are driven by I2C. There are cheap 4-pin modules available on edbay and elsewhere that can be plugged in to a Pmod header via a simple homemade adapter or even directly into the Pmod header (or via a connecting cable) if VCC and GND are in the correct position. An I2C master module, mod_i2c_master, has been added to BlackSoC, with an example program. The module in the picture uses two colours, but they are fixed and not variable by software. The top lines of that display use yellow text and the other lines blue.
It is harder to access i2c oled displays and other i2c devices without a soft processor as they have complex sequences of commands for initialisation and writing data. However it is not too hard to set up a ROM with the appropriate initialisation commands.
SPI OLED displays
OLED displays such sssd1306, ssd1351 etc. Are driven either by the SPI or I2C protocol.
Icosoc has an implementation of an SPI master in mod_spi which is also in BlackSoC.
The OLED displays use a variant of SPI that is output only and so has no MISO pin, and which has an extra pin (DC) to distinguish between commands and data. They also have a reset pin. To cope with this a new BlackSoC module, mod_spi_oled has been produced.
There are BlackSoC examples for a variety of monochrome and RGB SPI OLED displays: the ssd1306 or sh1106, the ssd1331 and the ssd1335.
LCD Displays
LCD Text Displays
There are a lot of different types of LCD display. A common one is a two-line character LCD. The one in the picture is a Grove I2C RGB-backlit two-line character LCD.
There are two types of these 2-line text LCDs : serial-connected or parallel connected.
Serial-connected text LCDs
There are separate I2C devices for the backlight and the character display. The character display needs a 5v supply, which can be taken from the Arduino header on the BlackIce II.
The i2c_master module in BlackSoC can be used to drive both devices, as in the BlackSoC grovelcd example.
Parallel-connected text LCDs
The fpgafun site shows how to drive these displays, and here is the example, modified to run on the BlackIce II. You can send command to it from the command line e.g.
echo -n -e “\x00\x01” >/dev/ttyUSB0
to reset it.
Graphics LCDs
To be supplied.
Last updated