<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mikestirling.co.uk &#187; Embedded</title>
	<atom:link href="http://mikestirling.co.uk/category/embedded/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikestirling.co.uk</link>
	<description></description>
	<lastBuildDate>Sun, 18 Sep 2011 11:19:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>128K ZX Spectrum on FPGA loads from SD card</title>
		<link>http://mikestirling.co.uk/2011/09/128k-zx-spectrum-on-fpga-loads-from-sd-card/</link>
		<comments>http://mikestirling.co.uk/2011/09/128k-zx-spectrum-on-fpga-loads-from-sd-card/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 23:47:10 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Home Stuff]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=192</guid>
		<description><![CDATA[So as promised I spent a bit of the bank holiday weekend hacking on the FPGA Spectrum to fix a few bugs.  In the end I got carried away and finished up with a full implementation of the 128K Spectrum +2A running ResiDOS and loading emulator images from an SD card.  It&#8217;s still not cycle [...]]]></description>
			<content:encoded><![CDATA[<p>So as promised I spent a bit of the bank holiday weekend hacking on the FPGA Spectrum to fix a few bugs.  In the end I got carried away and finished up with a full implementation of the 128K Spectrum +2A running <a href="http://www.worldofspectrum.org/residos/" target="_blank">ResiDOS</a> and loading emulator images from an SD card.  It&#8217;s still not cycle accurate, but it is feature complete apart from the disk controller, which isn&#8217;t really needed thanks to the <a href="http://www.zxbada.bbk.org/zxmmcp/" target="_blank">ZXMMC+</a> compatibility that went in as well.</p>
<p>Emulating bus contention and improving the cycle accuracy of the T80 core is definitely on the cards, but for now the ability to finally load emulator images from SD makes the machine extremely usable.  An explanation of how to get this up and running is a job for another post (hint: format the card as IDEDOS and bootstrap ResiDOS into the extra RAM), but for the time being here is a <a title="ZX Spectrum on an FPGA" href="http://mikestirling.co.uk/zx-spectrum-on-an-fpga/">detailed write-up</a> and the <a href="http://www.mikestirling.co.uk/files/spectrum_release_20110901.zip">full VHDL source</a>.</p>
<p>And let&#8217;s not forgot the obligatory eye candy&#8230;</p>
<p><iframe src="http://player.vimeo.com/video/28420449" width="640" height="360" frameborder="0"></iframe></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2011/09/128k-zx-spectrum-on-fpga-loads-from-sd-card/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VHDL BBC B Design Notes</title>
		<link>http://mikestirling.co.uk/2011/08/vhdl-bbc-b-design-notes/</link>
		<comments>http://mikestirling.co.uk/2011/08/vhdl-bbc-b-design-notes/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 20:14:38 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Home Stuff]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=160</guid>
		<description><![CDATA[As promised, some more detailed design notes for my BBC B design are now available. Planning to revisit the Spectrum design next for some bug fixes, as it is clear there is still quite a bit of interest in that.]]></description>
			<content:encoded><![CDATA[<p>As promised, some more detailed design notes for my BBC B design are now <a title="BBC Micro on an FPGA – Design Detail" href="http://mikestirling.co.uk/bbc-micro-on-an-fpga-design-detail/">available</a>.</p>
<p>Planning to revisit the Spectrum design next for some bug fixes, as it is clear there is still quite a bit of interest in that.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2011/08/vhdl-bbc-b-design-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBC on FPGA in action&#8230;</title>
		<link>http://mikestirling.co.uk/2011/08/bbc-on-fpga-in-action/</link>
		<comments>http://mikestirling.co.uk/2011/08/bbc-on-fpga-in-action/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 21:05:24 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Home Stuff]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=145</guid>
		<description><![CDATA[I added a video of the FPGA BBC in action, shot straight off the TV. You can see the MMBEEB ROM extensions providing access to multiple disk images on the SD card, then some messing about on Chuckie Egg and Boffin.]]></description>
			<content:encoded><![CDATA[<p>I added a video of the <a title="BBC Micro on an FPGA" href="http://mikestirling.co.uk/bbc-micro-on-an-fpga/">FPGA BBC</a> in action, shot straight off the TV.</p>
<p>You can see the MMBEEB ROM extensions providing access to multiple disk images on the SD card, then some messing about on Chuckie Egg and Boffin.</p>
<p><iframe src="http://player.vimeo.com/video/27974778" width="640" height="360" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2011/08/bbc-on-fpga-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBC Micro on an FPGA</title>
		<link>http://mikestirling.co.uk/2011/08/bbc-micro-on-an-fpga/</link>
		<comments>http://mikestirling.co.uk/2011/08/bbc-micro-on-an-fpga/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 14:40:51 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Home Stuff]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=127</guid>
		<description><![CDATA[It&#8217;s been a while since the Spectrum project and, although there is still work left to do on that, I eventually gave in and did another great British computer from my childhood &#8211; the BBC B.  Getting this machine up and running has been an interesting job given its complexity.  For something that first came out [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_99" class="wp-caption alignright" style="width: 394px"><a href="http://mikestirling.co.uk/wordpress/wp-content/uploads/2011/08/DSC_0388.jpg"><img class="size-full wp-image-99  " title="Boot screen" src="http://mikestirling.co.uk/wordpress/wp-content/uploads/2011/08/DSC_0388.jpg" alt="BBC Micro boot screen running on FPGA" width="384" height="288" /></a><p class="wp-caption-text">BBC Micro boot screen running on FPGA</p></div>
<p>It&#8217;s been a while since the <a title="ZX Spectrum on Altera DE1 – Teaser" href="http://mikestirling.co.uk/2010/09/zx-spectrum-on-altera-de1-teaser/">Spectrum</a> project and, although there is still work left to do on that, I eventually gave in and did another great British computer from my childhood &#8211; the BBC B.  Getting this machine up and running has been an interesting job given its complexity.  For something that first came out in 1981 it really is a sophisticated computer, and one that I&#8217;m sure anyone who grew up in the UK in the 80&#8242;s and early 90&#8242;s will remember.</p>
<p>I&#8217;ve written this one up on its own <a title="BBC Micro on an FPGA" href="http://mikestirling.co.uk/bbc-micro-on-an-fpga/">page</a> so that it doesn&#8217;t disappear, and the Speccy will get the same treatment in the next few weeks.  A <a href="http://www.mikestirling.co.uk/files/bbc_micro_de1_20110918.sof">bitstream image</a> is provided for you to run on your own DE1 board, if you have one, and the full <a href="http://www.mikestirling.co.uk/files/bbc_release_20110918.zip">VHDL source code</a> is available too.</p>
<p>A detailed description of the design is also in the works, and should be ready in a day or two.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2011/08/bbc-micro-on-an-fpga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZX Spectrum on Altera DE1 &#8211; Source Code</title>
		<link>http://mikestirling.co.uk/2010/11/zx-spectrum-on-altera-de1-source-code/</link>
		<comments>http://mikestirling.co.uk/2010/11/zx-spectrum-on-altera-de1-source-code/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 23:00:40 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=73</guid>
		<description><![CDATA[Sorry it took so long, but I&#8217;ve finally cleaned up the source code ready for publishing, and here it is.  This contains a Quartus project file, so it should load and compile straight away.  I used Quartus 9.1 Web Edition, available from the Altera website.  There is also a pre-compiled .sof image which should work [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikestirling.co.uk/wp-content/uploads/2010/11/miner.jpg"><img class="alignright size-full wp-image-79" title="Manic Miner in-game" src="http://mikestirling.co.uk/wp-content/uploads/2010/11/miner.jpg" alt="Manic Miner in-game screenshot" width="384" height="288" /></a>Sorry it took so long, but I&#8217;ve finally cleaned up the source code ready for publishing, and <a href="http://mikestirling.co.uk/files/spectrum_release_20101121.zip">here</a> it is.  This contains a Quartus project file, so it should load and compile straight away.  I used Quartus 9.1 Web Edition, available from the <a href="https://www.altera.com/download/dnl-index.jsp">Altera</a> website.  There is also a pre-compiled .sof image which should work straight away if you have a DE1.</p>
<p>A full write-up will follow, but here is a quick summary:</p>
<p><span id="more-73"></span>The implementation is of a standard PAL 48K Spectrum.  IO is via the DE1&#8242;s existing interfaces, with the video hardware able to drive either a normal TV (via RGB SCART) or a PC monitor.  In the latter case the picture is double-scanned to obtain the required line scan rate.  A PS/2 keyboard can be connected although you will probably need a picture of a real Speccy to work out what all the keys do!  Some key combos like caps-lock and escape (BREAK) do actually work, though. Audio input and output are both available through the normal jacks, and programs can be loaded from tape or by using something like playtzx on a PC.  Loading images from SD card is planned but not yet implemented.</p>
<p>The design runs from a PLL-derived 28 MHz clock with clock-enables used to time-slice RAM access between the CPU and video hardware.  The CPU runs for one cycle in eight, resulting in the required 3.5 MHz cycle time.  Note that because of this time-slicing there is no RAM or IO contention, so this is slightly faster than a real Spectrum meaning that some games and turbo-loaders don&#8217;t yet work properly.  The CPU is a synchronous T80 core connected to the rest of the hardware through some address decoding and multiplexing logic.  The ROM image is contained on the FPGA, but the external SRAM is used for the Spectrum&#8217;s RAM, and the entire 48K is accessed over one time-sliced bus.  The address applied to the SRAM comes from either the CPU address bus or the video logic depending on whose turn it is.</p>
<p>On the IO side the ULA&#8217;s single IO port is implemented.  The PS/2 keyboard interface applies key up/down events to an 8&#215;5 matrix representing a real Spectrum&#8217;s keyboard.  This matrix is addressed by the CPU and routed to the ULA IO port as in the real thing, so no changes to the ROM are needed.  Audio is fed both ways through the Wolfson codec which has its settings loaded on reset by a simple I2C loader block.  The register settings are hard-coded into this logic.  A bidirectional I2S&lt;&gt;parallel interface is used to interface the audio bus with the ULA register.  For recording (EAR in) the sign-bit from the capture side is used &#8211; some hysteresis would probably be beneficial here.  Note that the audio codec has its own 24 MHz clock and operates asynchronously with the rest of the design.</p>
<p>Four of the slide switches are used:</p>
<ul>
<li>SW9 &#8211; /RESET &#8211; Down to reset, up to run</li>
<li>SW8 &#8211; PLL reset &#8211; Leave this down</li>
<li>SW7 &#8211; Slow mode &#8211; Allows CPU operation to be traced on the LEDs &#8211; Normally leave down</li>
<li>SW6 &#8211; PAL/VGA &#8211; Down for PAL (SCART) or up for VGA (PC monitor)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2010/11/zx-spectrum-on-altera-de1-source-code/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>ZX Spectrum on Altera DE1 &#8211; Teaser</title>
		<link>http://mikestirling.co.uk/2010/09/zx-spectrum-on-altera-de1-teaser/</link>
		<comments>http://mikestirling.co.uk/2010/09/zx-spectrum-on-altera-de1-teaser/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 00:10:26 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Home Stuff]]></category>
		<category><![CDATA[Retro Computing]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=48</guid>
		<description><![CDATA[Last week I was made aware of this post on RS DesignSpark about a project, currently in the very early planning stage, to build a Sinclair Spectrum on an FPGA.  As it happens I have a similar project well under way, and I have promised to write it up&#8230; Several years ago I implemented most [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikestirling.co.uk/wp-content/uploads/2010/09/screenshot.jpg"><img class="alignright size-full wp-image-56" title="Quartus screenshot" src="http://mikestirling.co.uk/wp-content/uploads/2010/09/screenshot.jpg" alt="" width="439" height="312" /></a><em>Last week I was made aware of <a href="http://www.designspark.com/spectrum/" target="_blank">this post</a> on RS DesignSpark about a project, currently in the very early planning stage, to build a <a href="http://en.wikipedia.org/wiki/Zx_spectrum" target="_blank">Sinclair Spectrum</a> on an FPGA.  As it happens I have a similar project well under way, and I have promised to write it up&#8230;</em></p>
<p>Several years ago I implemented most of the ULA in VHDL on a MAX7000 CPLD, mainly as an exercise to brush up on my HDL.  I didn&#8217;t have enough space to fit the keyboard interface so it was pretty useless, but it did boot!  The complete system used a pair of SRAMs, real Z80 and the Sinclair ROM in flash.</p>
<p>Back at the beginning of this year I decided to brush up on my HDL again and I bought myself an Altera DE1 development kit.  The heart of this board is a Cyclone II FPGA with a range of support hardware including 512KB SRAM, 8MB SDRAM, 4MB flash, an I2S audio codec, VGA port and the usual switches, LEDs and buttons.  I would highly recommend it for anyone looking for a relatively cheap way to play with FPGAs.</p>
<p><span id="more-48"></span>This time I decided to put as much as possible into the FPGA.  All the core ULA logic is in there along with a Z80 soft-core (T80 from opencores), the ROM, proper bus routing (the real Spectrum used a lot of tricks that simply aren&#8217;t an option in an FPGA), VGA scan-doubling for the video output, logic to drive the I2S audio codec, plus a PS/2 keyboard interface.  Apart from the audio codec, which is absolute overkill and only used because it is already on the board, the only other key part external to the FPGA is the SRAM.  This is used for both contended and non-contended memory regions by a method which I will cover in a later installment.</p>
<p>A full write-up will follow, along with better pictures, video and full VHDL for the project once it has been cleaned up a bit.  In the meantime here are a couple of photos of the thing in action (click for bigger, and yes I did load that from a real tape!)</p>
<p><a href="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4051.jpg"><img class="size-full wp-image-50 alignnone" title="Sinclair Research" src="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4051.jpg" alt="" width="234" height="346" /></a><a href="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4055.jpg"><img class="size-full wp-image-51 alignnone" title="Spectrum on a DE1" src="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4055.jpg" alt="" width="358" height="266" /></a></p>
<p><a href="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4070.jpg"><img class="alignnone size-full wp-image-55" title="Feud in-game" src="http://mikestirling.co.uk/wp-content/uploads/2010/09/DSCN4070.jpg" alt="" width="220" height="294" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2010/09/zx-spectrum-on-altera-de1-teaser/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Programming an LPC flash with an AVR and &#8220;flashrom&#8221;</title>
		<link>http://mikestirling.co.uk/2010/08/programming-an-lpc-flash-with-an-avr-and-flashrom/</link>
		<comments>http://mikestirling.co.uk/2010/08/programming-an-lpc-flash-with-an-avr-and-flashrom/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 12:16:55 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[8-Bit]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Home Stuff]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/?p=34</guid>
		<description><![CDATA[I had a dead motherboard that had been kicking around for a while after a failed BIOS update.  The flash part on there was the Winbond W39V040B, which is 3.3V only and has an LPC interface.  The device programmer I have access to wouldn&#8217;t touch it, so I put together some simple AVR code to [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><a href="http://mikestirling.co.uk/wp-content/uploads/2010/08/flash.jpg"><img class="alignleft size-full wp-image-41" title="Flash chip" src="http://mikestirling.co.uk/wp-content/uploads/2010/08/flash.jpg" alt="" width="250" height="178" /></a>I had a dead motherboard that had been kicking around for a while after a failed BIOS update.  The flash part on there was the Winbond W39V040B, which is 3.3V only and has an LPC interface.  The device programmer I have access to wouldn&#8217;t touch it, so I put together some simple AVR code to handle the protocol and connected the device up to my STK500.  Although reading the device posed no problems, it quickly became apparent that the flash chip was not responding properly to write transactions.  This meant there was no way to erase or program it, and is presumably why the BIOS flash failed in the first place.</p>
<p style="text-align: justify;">Searching through the junk box I managed to find a dual-mode LPC/FWH device of the same size (PMC Pm49FL004).  This one was responding properly to write commands, but I needed a way of reliably transferring the new BIOS image down to the AVR.  <span id="more-34"></span>The <a href="http://flashrom.org/Flashrom">flashrom</a> project already has support for an external AVR-based programmer (called serprog) but this is for devices using a parallel interface only.  However, it was a fairly simple task to take the serprog protocol support from the existing flashrom programmer and graft it onto the LPC interface code I had already written.  The resulting AVR code can be downloaded <a href="/files/frser-avr-lpc_20100904.tar.gz">here</a> and was tested with both the Ubuntu 10.04 version of flashrom, and with the latest development build from SVN.  A Makefile is included for building the project on Linux using the GNU AVR tools.</p>
<p style="text-align: justify;">The hardware side was based around an ATMEGA88, although it could be ported to pretty much any ATMEGA device with minimal effort.  Connections to the LPC bus are defined in <em>board.h</em>, and these can be connected directly to the flash chip, although care should be taken to ensure that the supply voltage is restricted to 3.3V.  If using the STK500 then this has a programmable target supply which can be changed using AVR Studio, or with avrdude in terminal mode.  As well as the various power connections that the flash device will require (refer to its datasheet) it was also necessary to tie /WP,/TBL and /INIT high for correct operation.  Other pins can be left unconnected.  For best results the AVR clock needs to be faster than the 3.6864 MHz that the STK500 can provide by itself, but it does need to be of a suitable frequency for baud-rate generation; I used a 7.3728 MHz crystal.  The actual frequency used needs to be specified in the Makefile.</p>
<p style="text-align: justify;">Many thanks to <em>carldani</em> and others on #flashrom for their help in putting this hack together!</p>
<p style="text-align: justify;"><em>Updated: The source code archive was missing a couple of files, which are now included.</em></p>
<p style="text-align: justify;"><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2010/08/programming-an-lpc-flash-with-an-avr-and-flashrom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mono STN display on an AVR32 AP7000</title>
		<link>http://mikestirling.co.uk/2009/02/mono-stn-display-on-an-avr32-ap7000/</link>
		<comments>http://mikestirling.co.uk/2009/02/mono-stn-display-on-an-avr32-ap7000/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 21:04:50 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[AVR32]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Home Stuff]]></category>

		<guid isPermaLink="false">http://mikestirling.co.uk/wordpress/?p=5</guid>
		<description><![CDATA[I&#8217;ve had a few controllerless QVGA (320&#215;240) mono LCD modules lying around for a while looking for some use.  These are fairly easy to get going with a low-end microcontroller using an external controller IC like the SED1335, but that&#8217;s another story.  I&#8217;d been thinking about doing some sort of integrated home automation project, and [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_11" class="wp-caption alignleft" style="width: 310px"><img class="size-medium wp-image-11" title="NGW100 STN" src="http://mikestirling.co.uk/wordpress/wp-content/uploads/2009/02/stn_lcd-300x187.jpg" alt="AVR32 NGW100 Driving an STN LCD Module" width="300" height="187" /><p class="wp-caption-text">AVR32 NGW100 Driving an STN LCD Module</p></div>
<p style="text-align: justify;">I&#8217;ve had a few controllerless QVGA (320&#215;240) mono LCD modules lying around for a while looking for some use.  These are fairly easy to get going with a low-end microcontroller using an external controller IC like the SED1335, but that&#8217;s another story.  I&#8217;d been thinking about doing some sort of integrated home automation project, and since this would need a user interface and I happened to have an NGW100 going spare, getting one of these displays to run on the AP7000&#8242;s integrated LCD controller seemed like a nice idea.</p>
<p style="text-align: justify;">The NGW100 only has a 16-bit interface to its already relatively slow DRAM, so driving a high-res colour LCD from it leads to a fairly obvious slowdown.  For this application a mono display would be adequate, and easier to drive, requiring only a 4-bit data bus, the 3 clocks and a GPIO to power up the drivers.  The LCDC has no problem driving an STN panel, although I had to deviate from the datasheet in one area to get it to work &#8211; more on that later.</p>
<p style="text-align: justify;"><span id="more-5"></span>The particular panel (a Samsung UG32F05) requires a 5 V logic supply, but also calls for around -20 V for the LCD drive.  In the prototype this was generated using a nasty buck-boost converter thrown together from a 555 timer and a MOSFET, but this is not recommended (use a real switch-mode controller)!  The 5 V was derived with a linear regulator connected to the NGW100&#8242;s 2-pin power header, and the signal lines from the LCDC were connected up directly (D0-D3 straight through, PCLK to XSCL/CL2, HSYNC to LP/CL1 and VSYNC to DIN/FLM).  Because powering an STN display without the proper clocks applied can cause damage the module provides a /DISPOFF connection, which was driven from a spare GPIO on the NGW100.  Normally this would be connected to the LCDC&#8217;s PWR output, but this is shared with the SD card detect input on the NGW, and the application would be using this.  The pinout of the module goes like this:</p>
<table style="text-align: justify;" border="0">
<tbody>
<tr>
<td>Pin</td>
<td>Name</td>
<td>Function</td>
</tr>
<tr>
<td>1</td>
<td>FLM</td>
<td>Frame scan start (to LCDC_VSYNC) &#8211; P7 pin 29</td>
</tr>
<tr>
<td>2</td>
<td>M</td>
<td>Backplane sync signal (not used on this module, but connect to LCDC_MODE) &#8211; P7 pin 26</td>
</tr>
<tr>
<td>3</td>
<td>CL1</td>
<td>Data latch clock (to LCDC_HSYNC) &#8211; P7 pin 27</td>
</tr>
<tr>
<td>4</td>
<td>CL2</td>
<td>Data shift clock (to LCDC_PCLK) &#8211; P7 pin 28</td>
</tr>
<tr>
<td>5</td>
<td>/DISPOFF</td>
<td>Display inhibit (to GPIO) &#8211; P7 pin 5</td>
</tr>
<tr>
<td>6</td>
<td>D0</td>
<td>Display data input (to LCDC_D[0]) &#8211; P7 pin 1</td>
</tr>
<tr>
<td>7</td>
<td>D1</td>
<td>Display data input (to LCDC_D[1]) &#8211; P7 pin 2</td>
</tr>
<tr>
<td>8</td>
<td>D2</td>
<td>Display data input (to LCDC_D[2]) &#8211; P7 pin 3</td>
</tr>
<tr>
<td>9</td>
<td>D3</td>
<td>Display data input (to LCDC_D[3]) &#8211; P7 pin 4</td>
</tr>
<tr>
<td>10</td>
<td>Vdd</td>
<td>5V supply</td>
</tr>
<tr>
<td>11</td>
<td>Vss</td>
<td>0V supply</td>
</tr>
<tr>
<td>12</td>
<td>Vee</td>
<td>LCD supply (typically -20V)</td>
</tr>
<tr>
<td>13</td>
<td>Vo</td>
<td>Contrast (potential divider between Vee and Vss)</td>
</tr>
<tr>
<td>14</td>
<td>FG</td>
<td>Frame ground</td>
</tr>
</tbody>
</table>
<p style="text-align: justify;">To get the display working from Linux (I started from a vanilla 2.6.28.1 kernel) I created a copy of the evklcd10x.c board support module, added it to Kconfig and modified it to suit the parameters of the new LCD.  The fb_videomode structure was set up as follows:</p>
<ul style="text-align: justify;">
<li>refresh = 75</li>
<li>xres = 320, yres = 240</li>
<li>pixclock = KHZ2PICOS(1500)</li>
<li>left_margin = 1, right_margin = 1</li>
<li>upper_margin = 0, lower_margin = 0</li>
<li>hsync_len = 2, vsync_len = 1</li>
<li>sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT</li>
<li>vmode = FB_VMODE_NONINTERLACED</li>
</ul>
<p style="text-align: justify;">This gives a refresh rate of around 75 Hz, although this is mis-reported by fbset.  The settings in the fb_monspecs structure are not that critical (it seems).  I set the frequency ranges based on the quoted timing data for the display.  More important is the atmel_lcdfb_info data, which was set up like this:</p>
<ul style="text-align: justify;">
<li>default_bpp =1</li>
<li>default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN</li>
<li>default_lcdcon2 = ATMEL_LCDC_DISTYPE_STNMONO | ATMEL_LCDC_SCANMOD_SINGLE | ATMEL_LCDC_IFWIDTH_4 | ATMEL_LCDC_INVVD_INVERTED</li>
<li>guard_time = 2</li>
<li>default_monspecs = fb_monspecs_structure</li>
<li>atmel_lcdfb_power_control = lcd_power_control_function</li>
</ul>
<p style="text-align: justify;">The power control callback function is called by the driver after the controller has been set up and the timing signals are valid.  This is used to control the GPIO pin connected to the /DISPOFF input of the panel.  It is trivial, and along with an updated initialisation function it looks like this:</p>
<blockquote style="text-align: justify;"><p>#define LCD_nDISPOFF    GPIO_PIN_PE(7)</p>
<p>static void lcd_power_control_function(int on)<br />
{<br />
printk(KERN_INFO &#8220;Turning LCD power %s\n&#8221;,on ? &#8220;on&#8221;:&#8221;off&#8221;);<br />
gpio_set_value(LCD_nDISPOFF,on);<br />
}</p>
<p>static int __init lcd_board_init(void)<br />
{<br />
at32_add_device_lcdc(0, &amp;lcd_board_lcdc_data,<br />
fbmem_start, fbmem_size,<br />
/* IO port mask */<br />
ATMEL_LCDC(PE, DATA0)  | ATMEL_LCDC(PE, DATA1)  |<br />
ATMEL_LCDC(PE, DATA2)  | ATMEL_LCDC(PE, DATA3)    |<br />
ATMEL_LCDC(PE, MODE) |<br />
ATMEL_LCDC_CONTROL);<br />
at32_select_gpio(LCD_nDISPOFF,AT32_GPIOF_OUTPUT); /* LCD /DISPOFF */<br />
return 0;<br />
}</p></blockquote>
<p style="text-align: justify;">That should be it.  However, it turned out that the AP7000 was generating 1/4 the number of clocks per line that it should have been even considering the 4-bit interface (20 clocks instead of 80).  Although I established this fact prior to connecting the module, visually this results in a display of vertical stripes.  In the datasheet it states that for STN mono mode, HOZVAL (found in the LCDFRMCFG register) is equal to (number of horizontal pixels / interface width) &#8211; 1.  The Linux driver calculates HOZVAL based on the display type, but does it by the book and chooses a value of 79 (320/4-1).  It was found that going against the datasheet and setting HOZVAL=319 solved the problem.  This was implemented by patching atmel_lcdfb.c so that hozval_linesz = info-&gt;var.xres (around line 577).  Please feel free to point out where I have screwed up here, or if this is indeed a mistake in the databook!</p>
<p style="text-align: justify;">Once the board boots you can use <em>fbset -depth 4</em> to switch to 16 shade greyscale mode.  The photo above shows the Qt text editor demo running in this mode.  Certain shades of grey exhibit a slight flicker, but for an STN display the image is pretty reasonable.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikestirling.co.uk/2009/02/mono-stn-display-on-an-avr32-ap7000/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

