Silicon Chip – April 2019

(Ben Green) #1

60 Silicon chip Australia’s electronics magazine siliconchip.com.au


The FPGA scans the 800x525 area,
uses its video RAM to determine
which character should be displayed
at any given point, then uses the font
ROM to determine whether the fore-
ground or background colour should
be displayed for each pixel. The
HSYNC signal is pulsed at the end of
each horizontal scan (ending a line),
and the VSYNC pin is pulsed every
vertical scan (ending a frame).


Generating the clocks


Since the iCEstick only has a 12MHz
oscillator, we need to use the iCE-
40HX-1k’s phase-locked loop (PLL) to
bring that up to around 25MHz. We are


generating a 100.5MHz signal, which
we divide by four to get 25.125MHz.
This is the closest the PLL can get to
our target frequency of 25.2MHz, us-
ing a 12MHz source. This small error
doesn’t end up causing any problems.
This clock signal is divided by a
factor of 800 in the FPGA, to give a
31.4kHz line clock, then again by 525
to give the frame/screen refresh clock
of 59.8Hz. That’s 0.2Hz slower than
our target of 60Hz, but it isn’t uncom-
mon to see video refresh rates that are
not an exact number of hertz, and vir-
tually all monitors will handle this.
We have created a 10-bit horizon-
tal pixel counter in the FPGA which
starts at zero and counts up to 799,

incrementing on each clock pulse (at
25.125MHz), then resets back to zero.
Each time it resets, the 10-bit verti-
cal pixel counter is incremented, and
it’s reset to zero as soon as it exceeds


  1. So these two counters allow us to
    keep track of which pixel is currently
    being emitted.
    When these pixel values are within
    the 512x384 active area in the middle
    of the screen, they are further divided
    by 16 (horizontal) and 24 (vertical) to
    determine which character position is
    currently being displayed. The FPGA
    then retrieves the 8-bit ASCII charac-
    ter value and two 4-bit colour (back-
    ground/foreground) values from its
    video RAM.
    The 4-bit colour values are then
    used to look up the 16-entry palette
    to determine the 6-bit colour values
    to use as the foreground and the back-
    ground for the character currently be-
    ing emitted. Similarly, the ASCII char-
    acter value is used to look up an entry
    in the font ROM.
    All these lookups culminate in a
    pixel colour value which is then fed
    to the RGB outputs (pins 2-4 and 8-10).
    At the same time, the HSYNC (pin 1)
    and VSYNC (pin 7) lines are driven
    based on the horizontal and vertical
    counters, to generate the required sync
    pulses for the monitor.


Screen1: this is a broad map of the functional parts of the “iCEstick VGA Terminal.ice” project. You will need to
install IceStudio, download and open that file and zoom in to see the detail of each block.

Fig.3: this shows
how font glyphs
are converted into
bitmap values, by
adding the value
of the pixels that
should show the
foreground colour.
IceStudio expects
hexadecimal
numbers in the font
ROM, so you will
need to convert
the decimal sums
to hexadecimal
format (eg, using
a programmer’s
calculator).
Free download pdf