<?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>Stephen&#039;s Weblog &#187; Electronics</title>
	<atom:link href="http://blog.akkit.org/category/hardware/electronics/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.akkit.org</link>
	<description>Everything is hackable</description>
	<lastBuildDate>Sun, 25 Jul 2010 07:03:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Generic USB JTAG/etc Programmer</title>
		<link>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/</link>
		<comments>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 07:03:33 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[PCB Layout]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=273</guid>
		<description><![CDATA[Despite having 2 weeks for this, I haven&#8217;t actually completed anything notable; So I&#8217;m just going to post some WIP images of a PCB I&#8217;ve designed to do general purpose programming (Generally jtag, but also AVR) I&#8217;ve been working out the concepts in software using the modified USB stick (as I mentioned previously) but just [...]]]></description>
			<content:encoded><![CDATA[<p>Despite having 2 weeks for this, I haven&#8217;t actually completed anything notable; So I&#8217;m just going to post some WIP images of a PCB I&#8217;ve designed to do general purpose programming (Generally jtag, but also AVR)</p>
<p>I&#8217;ve been working out the concepts in software using the modified USB stick (as I mentioned previously) but just haven&#8217;t had enough time to allocate to it yet. Soon, though.</p>
<p><span id="more-273"></span></p>
<p>This design is pretty simple; I have the microcontroller (ATMega32U2), a RGB LED, switch, and crystal &#8211; Then around that I am building a set of voltage level translation circuits for the jtag signals, and for additional inputs, outputs, and &#8220;pump&#8221; signals (which can strongly connect to a target&#8217;s V+ level, and drive a significant amount of current)</p>
<p>I&#8217;m including the JTAG interfaces I use commonly  on the board, and I have another additional &#8220;expansion&#8221; slot which I&#8217;ll be building new boards for to connect to yet other interfaces</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip1.png"><img class="alignnone size-medium wp-image-276" title="usbjtag_wip1" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip1-300x282.png" alt="" width="300" height="282" /></a></p>
<p>Schematic done, decided on a rough layout and started placing parts.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip2.png"><img class="alignnone size-medium wp-image-277" title="usbjtag_wip2" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip2-300x256.png" alt="" width="300" height="256" /></a></p>
<p>I got the core signals routed, and routed the level shifted jtag signals around the board, connecting to the side connectors as they go.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip3.png"><img class="alignnone size-medium wp-image-278" title="usbjtag_wip3" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip3-297x300.png" alt="" width="297" height="300" /></a></p>
<p>Added most of the other level shifting signals</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip4.png"><img class="alignnone size-medium wp-image-279" title="usbjtag_wip4" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_wip4-287x300.png" alt="" width="287" height="300" /></a></p>
<p>And now the design is essentially complete!</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1.png"><img class="alignnone size-medium wp-image-274" title="usbjtag_rev1" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1-285x300.png" alt="" width="285" height="300" /></a></p>
<p>Added ground planes, and vias to keep them well connected / allow plenty of return paths.</p>
<p>At this point I thought I was done&#8230;. Only, oops, I connected the top 3 headers backwards;  I had gone off of the pinout of the socket they plug into. Fortunately I noticed this before trying to produce the board :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1a.png"><img class="alignnone size-medium wp-image-275" title="usbjtag_rev1a" src="http://blog.akkit.org/wp-content/uploads/2010/07/usbjtag_rev1a-287x300.png" alt="" width="287" height="300" /></a></p>
<p>Ahh, now they&#8217;re correct.</p>
<p>So I&#8217;m having this board produced pretty soon and will write up more on JTAG once I have done some stuff with this.</p>
<p>In other news I&#8217;m taking a vacation in about 2 weeks! No, I&#8217;m not going anywhere interesting, just visiting family, but perhaps I&#8217;ll have something fun to write about by then :) I certainly have plenty of things I want to do!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/25/generic-usb-jtagetc-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JTAG</title>
		<link>http://blog.akkit.org/2010/07/11/jtag/</link>
		<comments>http://blog.akkit.org/2010/07/11/jtag/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 07:10:27 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware Hacking]]></category>
		<category><![CDATA[Reference Material]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=255</guid>
		<description><![CDATA[So, many of you use JTAG? I&#8217;ve been using JTAG for many years now, which started with FPGAs, and has mostly been for CPLDs and FPGAs since- but it&#8217;s also a pretty widely used protocol for programming and debugging mid range microcontrollers all the way up to high end CPUs. I&#8217;ve always wanted to look [...]]]></description>
			<content:encoded><![CDATA[<p>So, many of you use <a href="http://en.wikipedia.org/wiki/JTAG">JTAG</a>?</p>
<p>I&#8217;ve been using JTAG for many years now, which started with FPGAs, and has mostly been for CPLDs and FPGAs since- but it&#8217;s also a pretty widely used protocol for programming and debugging mid range microcontrollers all the way up to high end CPUs. I&#8217;ve always wanted to look into how JTAG worked in more depth, but never really had the time.</p>
<p>Now, I do have some time (and some projects which depend on JTAG hacking) &#8211; so this post will go into the world of JTAG.<span id="more-255"></span></p>
<p>Many of you have probably seen the following diagram, usually in some CPU or FPGA datasheet where it talks about the JTAG port. And it probably clicks to a degree, you see there&#8217;s a state model you can move around in, and the TMS signal causes that &#8211; but what doesn&#8217;t really get said is really a lot simpler than all that.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/07/jtag-state-machine-large.png"><img class="alignnone size-medium wp-image-256" title="jtag-state-machine-large" src="http://blog.akkit.org/wp-content/uploads/2010/07/jtag-state-machine-large-300x262.png" alt="(Sourced from some random site, but this diagram is pretty much everywhere - in datasheets, etc)" width="300" height="262" /></a></p>
<p>There are really only a few core truths and fundamental operations to know about when working with JTAG:</p>
<ul>
<li>There are 4 data lines important to JTAG: TDI, TDO, TMS, TCK &#8211; All of them are expected to be pulled up with resistors (either in the chip or externally). Some devices provide a &#8220;TRST&#8221; signal, which just does essentially the same as navigating to &#8220;Reset&#8221; through the state machine (only possibly without the side effect of committing a register change)</li>
<li>Pins are named in a Chip-Centric way. TDI goes into the chip, TDO is data out of the chip. TMS and TCK are controlled by the programmer</li>
<li>The device samples on the rising edge of TCK, and you should listen for its response on the falling edge.</li>
<li>A JTAG Reset should reset the test circuitry. Enter the reset state by cycling with TMS = 1 for 6 cycles (or more) &#8211; and then usually move to the &#8220;run/test/idle&#8221; state.</li>
<li>Idle in the  &#8221;run/test/idle&#8221; state by cycling the clock when TMS=0. Some devices depend on having idle clocks like this in order to perform their programming functions.</li>
<li>Write to the Instruction register &#8211; you do this by entering the Shift-IR state, Stay in this and shift bits (set TDI to your value, and listen on TDO). You need to set TMS = 1 for the last bit you shift.</li>
<li>Write to the Data register &#8211; Exactly the same way, just by entering Shift-DR</li>
<li>Another rule which it helps to know, is bitstreams are usually sent bottom-bit first &#8211; and are almost always represented with first sent bit on the right side. Important strings in documentation have been always specified in this form, in my experience (though it&#8217;s anybody&#8217;s guess what order the manufacturer will use to push their data into the port.</li>
<li>JTAG is inherently a multi-chip protocol. You can chain multiple chips by connecting TMS and TCK to all chips in the chain, Connect TDI to the first device, and connect the first device&#8217;s TDO to the second device&#8217;s TDI &#8211; And so on, finally connecting the last chip&#8217;s TDO to the header.</li>
</ul>
<p>Most of the other logic in the state machine is for devices that are tied to a fixed clock, and need to be wedged for a while if the host can&#8217;t keep up with shifting data.</p>
<p>At this point though, you can think of the JTAG system as memory mapped I/O, except for that the read/write widths are variable. Each transaction (Traveling through Capture-DR, shifting data, and then returning through Update-DR) has an impact on the system, which could be very small or very big. Everything is hardware specified, and every bit -could- have a meaning. That being said though, there are a few rules that make this manageable!</p>
<p>First, the Instruction register is typically very small. It exists so you can tell the device what mode to work in &#8211; And usually the size (Bit width) of the data register is fixed and based on the mode you are in.</p>
<p>There are a few mandated modes &#8211; The boundary scan modes were the original intent of the JTAG system &#8211; they exist so you can control and listen on the I/O pins of the device. JTAG was primarily designed as a way to test electrical connections on circuit boards between chips &#8211; This is implemented as the EXTEST and SAMPLE modes, for which the specific instruction register values are not rigidly specified (it varies per device)</p>
<p>There is a mandated &#8220;Bypass&#8221; mode, which is defined as an instruction word filled with ones &#8211; so you can technically use it even with chips that you don&#8217;t know anything about in the JTAG chain. When a chip is in BYPASS mode, it&#8217;s data register is a single bit. (Which will always clear itself to 0 when you start a new data transaction by entering Capture-DR)</p>
<p>When you enter JTAG Reset, the chip will automatically enter either IDCODE or BYPASS. IDCODE is an optional mode which is usually implemented; Its data register is a fixed 32bit value uniquely identifying the chip type, which MUST start with a &#8217;1&#8242; bit. The (slightly inobvious) advantage to this, is after resetting a JTAG chain, you can easily identify the number of devices in the chain and their types, if they entered the IDCODE state, just by shifting some bits through the data register! Based on whether the bit you receive is 0 or 1, either you know there is a bypassed device, or you will have 31 additional IDCODE bits to identify the current device with. Provided that you&#8217;re shifting in &#8217;1&#8242; bits into TDI, you can also identify the end of the chain when you encounter an IDCODE of all ones.</p>
<p>Another thing defined for your convenience, is the instruction register doubles as a status register.  The (variable size) instruction word is required to shift out as &#8220;xxxx01&#8243;; where one is sent *first* (rightmost first), and the &#8220;x&#8221; bits could be status from the device. This also gives you some clue as to how big the instruction registers are, if you didn&#8217;t know about all the devices in your chain. Though, even with this it may not be possible to concretely identify the sizes of the instruction registers in your chain. Well, there may be another trick/requirement but I don&#8217;t know it &#8211; I have been working entirely off of public documentation :)</p>
<p>It&#8217;s definitely easiest to work with chains that only have one device, but it is not too hard to set all the uninteresting devices to BYPASS if you can identify their instruction register sizes.</p>
<p>As for actually doing stuff with JTAG? Well, I think I&#8217;ll have to go over that some other time. The idea is to set some instruction, and then you get to send a data word, which is some data, some control bits, and some very strange logic sometimes. The device also trades you back a value in the exchange, and frequently you receive the results of the previous command you entered.</p>
<p>I have been starting to reverse engineer the JTAG protocols used by some Xilinx FPGAs and CPLDs (just in order to build my own programmer for them) &#8211; it&#8217;s been an interesting project that has repeatedly broken many of my assumptions about how JTAG is used. I&#8217;ll post more about this when I have worked it all out. Some things are very simple, others seem to be highly complex and mysterious, littered with commands that don&#8217;t make much sense and (apparently) unused data. (Seems I&#8217;m mostly interested in the complex ones &#8211; oh well.)</p>
<p>On the bright side, I have found a new use for my <a href="http://blog.akkit.org/2010/06/06/project-avr-usb-stick/">AVR USB Stick</a>, it currently has a bundle of wires attached to it for JTAG purposes :) I&#8217;ve written a simple protocol on the virtual serial port that lets me do JTAG stuff easily, and am probably going to set up a new PCB for dedicated USB programming, just because it&#8217;s so much faster than my existing serial port based programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/11/jtag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCI Card Revisited</title>
		<link>http://blog.akkit.org/2010/07/04/pci-card-revisited/</link>
		<comments>http://blog.akkit.org/2010/07/04/pci-card-revisited/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 07:00:02 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware Hacking]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=239</guid>
		<description><![CDATA[Remember the PCI card from a few weeks ago? Not too long after that, I did send out an order to manufacture some boards &#8211; and this last week they finally arrived! I&#8217;ve assembled a few, tested them, run into a few problems, solved them, and finally got a pretty basic PCI Port-80h debug card [...]]]></description>
			<content:encoded><![CDATA[<p>Remember the <a title="Project: PCI Card" href="http://blog.akkit.org/2010/06/13/project-pci-card/">PCI card</a> from a few weeks ago?</p>
<p>Not too long after that, I did send out an order to manufacture some boards &#8211; and this last week they finally arrived! I&#8217;ve assembled a few, tested them, run into a few problems, solved them, and finally got a pretty basic PCI Port-80h debug card working.</p>
<p>In this post I&#8217;ll walk through these things, and talk some more about the PCI interface.</p>
<p><span id="more-239"></span></p>
<p>So; Early this week I received a package from <a title="MyroPCB" href="http://www.myropcb.com/">MyroPCB</a> &#8211; A cheap outsourced PCB manufacturer; I&#8217;m rather happy with the quality of these boards &#8211; it&#8217;s a reasonably simple design to produce these days I suppose, but it is still pretty neat.</p>
<div id="attachment_242" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scan.jpg"><img class="size-medium wp-image-242  " title="pcipost_scan" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scan-300x221.jpg" alt="Scan of the PCI_POST circuit board" width="300" height="221" /></a><p class="wp-caption-text">(A Scan of some of the boards I received)</p></div>
<p>It takes some time to assemble this PCB, due to all the parts; The most annoying parts have been ones with pads strongly attached to the ground fill; Those pads have thermals seperating them from the fill, so they are not completely embedded in copper, but they&#8217;re still too well connected, and very troublesome to solder as all the heat is sucked away by the large mass of copper. Also the capacitors take some time to solder just by virtue of there being a large number of them. (And also that a large number of them have one pad attached too well to the ground fill)</p>
<div id="attachment_243" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_populated.jpg"><img class="size-medium wp-image-243 " title="pcipost_populated" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_populated-300x225.jpg" alt="The PCI_POST board populated with components" width="300" height="225" /></a><p class="wp-caption-text">(After some soldering)</p></div>
<p>At this point I didn&#8217;t do much else with this project until today;</p>
<p>Unfortunately, I had made a serious miscalculation &#8211; Note that the PCI edge connector on this card is 3.3V only&#8230; Now, I had built this card not long after seeing a PCI 3.3V only slot in a server system; so I made the assumption this would work great for me. In fact the PCI 3.0 specification (released in 1994!) no longer even includes the 5V PCI card slot</p>
<p>So that means it&#8217;s gone, right?</p>
<p>Well, No.</p>
<p>And, in fact my assumption proved to be wrong in the most incredible sense; There are literally no desktop-class motherboards on the market with 3.3V PCI slots! I spent an hour or two looking through motherboards on <a title="Newegg" href="http://www.newegg.com/">Newegg</a>, and the cheapest motherboard I could find with 3.3V PCI slots was $200. (And, only had 3.3V PCI slots by virtue of them being part of 3.3V PCI-X slots)</p>
<p>All was not lost though, first, this board was also built to be general purpose  - so it will have other uses. Also, as it turns out, it isn&#8217;t impossible to use it in modern 5V PCI slots.</p>
<p>Apparently,  system board manufacturers don&#8217;t want to sacrifice compatibility &#8211; so while modern PCI busses are all driven with 3.3V signals, they are still using the 5V connectors and maintaining 5V compatibility &#8211; This is really annoying for my project, because my FPGA isn&#8217;t 5V tolerant like their bus controllers are, but I can work on a 3.3V bus just fine. So, to actually be able to test, I have cut out the second key slot in the PCI connector and broken the VCCIO traces that would otherwise connect 5V to my 3.3V rail in the 5V slot. The PCI connector has a bundle of different voltage rails &#8211; but in a 3.3V-only card, like I made, the I/O voltage levels are intended to be connected to the 3.3V rail &#8211; so I did connect them &#8211; Unfortunately, being compatible with a 5V slot means those I/O voltage levels are 5V. It&#8217;s not ideal to just disconnect them, as they are supposed to have bypass capacitors in order to reduce noise, but I didn&#8217;t have many options with this, so I have just disconnected my card from the I/O voltages completely.</p>
<div id="attachment_244" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scratched.jpg"><img class="size-medium wp-image-244  " title="pcipost_scratched" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_scratched-300x97.jpg" alt="PCI_POST card with cut out slot and scratched out I/O voltage traces" width="300" height="97" /></a><p class="wp-caption-text">(Chopped traces and a new slot)</p></div>
<p>With this modification, my card is quite happy to work in the motherboards I have around &#8211; The caveat is, since my FPGA isn&#8217;t 5V tolerant, if I put it in with a 5V device (which does typically drive the bus up to 5V), it will likely damage my device. However, for what I&#8217;d like to do, I can live with this, and I can redesign the board if I ever actually need 5V tolerance.</p>
<p>After resolving how to test my board as a PCI device, I set out to write a first simple test firmware, to verify that the core functionality worked- This just drives the display and sets the LED values based on the switches present on the system.</p>
<div id="attachment_245" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_test.jpg"><img class="size-medium wp-image-245 " title="pcipost_test" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_test-300x225.jpg" alt="pci_post test program" width="300" height="225" /></a><p class="wp-caption-text">(Test program)</p></div>
<p>It was at this point that I noticed the green &#8220;programming done&#8221; LED had accidentally been populated with a red LED on this board &#8211; oops. I will have to go back and fix that later.</p>
<p>A few short steps further, and I converted the test program to firmware for watching the port 80h I/O Writes on the PCI bus &#8211; I had an old motherboard around from a system upgrade some time ago, connected it up, and it does appear to be working! After powering up the system, the display cycled through a number of values exactly the way it should; In the image below you can see the last 2 values it observed written to port 80h.</p>
<div id="attachment_246" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_victory.jpg"><img class="size-medium wp-image-246 " title="pcipost_victory" src="http://blog.akkit.org/wp-content/uploads/2010/07/pcipost_victory-300x225.jpg" alt="pci_post operating as a POST code display card" width="300" height="225" /></a><p class="wp-caption-text">(Victory!)</p></div>
<p>So,A few short notes about PCI devices &#8211; First, this isn&#8217;t actually a full PCI device; It does not interfere with the bus any more than is necessary to make electrical contact- it is only listening to the bus in order to see this information (as such it&#8217;s out of spec). It is actually possible to make a full PCI device with this card, and that&#8217;s on my list of  things to do eventually as well.</p>
<p>The PCI bus though, is essentially a collection of signals &#8211; there are 32 address/data lines, and a number of control signals; At its core though are the PCI Clock signal, a FRAME signal (each transaction on the bus is a frame), the 32 address/data lines, 4 lines which are used as both a control word, and as 4 individual byte enables (to enable byte granularity in the 32bit value) &#8211; Beyond these are some handshaking signals (IRDY/TRDY), sanity checking (Parity), error reporting (PERR/SERR), transaction abort (STOP), System reset (RST), and location-based device identification (IDSEL/DEVSEL)</p>
<p>In order to listen for a specific port write on the bus though, you only really need the CLK, FRAME, data lines, and the 4-bit control word / byte enable &#8211; All PCI signals are sampled on a rising clock edge, the controller starts a frame by asserting FRAME on a clock edge. When it does this, it also sets the 4-bit control word to the transaction type, and for some types of transactions also sets the address lines to the related address.</p>
<p>What my card is doing, is waiting for reset to finish; then every frame that starts, it checks if it is an I/O write with address = 0&#215;00000080; If so, it listens on the next cycle, and if byte enable 0 is set, it will accept the data in the bottom 8 bits of the data lines as a new port 80h write &#8211; In any case, it waits for the frame to finish, and then continues waiting for another frame to start.</p>
<p>Sounds simple? It really is.</p>
<p>Making a real PCI device though will be a lot more challenging, and I&#8217;ll be sure to document that when I get around to it :)</p>
<p>Small update: I should probably also mention the significance of Port 80h &#8211; System BIOS manufacturers have standardized on using port 80h as a debug port of sorts, they write a byte to that port to indicate which section of the BIOS code is running; As such, there are a number of cheaply available &#8220;PC Diagnostic&#8221; boards, which do essentially what I&#8217;m doing here, just listen for Port 80h accesses and display the values. The capability to see this code is helpful when diagnosing a difficult motherboard problem, to be sure&#8230; but it&#8217;s also helpful when writing and debugging low-level code when little else on the system is running, as you can add writes to 80h that give you information about what stage of execution your program is in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/07/04/pci-card-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USB Stick: Part 2</title>
		<link>http://blog.akkit.org/2010/06/27/usb-stick-part-2/</link>
		<comments>http://blog.akkit.org/2010/06/27/usb-stick-part-2/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:18:34 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=233</guid>
		<description><![CDATA[Oh, finally&#8230; So, this post is a little bit late as well, I almost didn&#8217;t manage to make this work :) I&#8217;ve been now tinkering with writing a USB device stack for my USB stick for literally the past two weeks now; Being a new space, I&#8217;m used to the idea of having issues, but [...]]]></description>
			<content:encoded><![CDATA[<p>Oh, finally&#8230;</p>
<p>So, this post is a little bit late as well, I almost didn&#8217;t manage to make this work :) I&#8217;ve been now tinkering with writing a USB device stack for my USB stick for literally the past two weeks now; Being a new space, I&#8217;m used to the idea of having issues, but between incredibly stupid bugs, very minimal documentation, and errors in some critical hardware documentation, this has been quite a challenging project.</p>
<p>On the plus side, I now have my <a href="http://blog.akkit.org/2010/06/06/project-avr-usb-stick/">USB stick</a> behaving as a virtual com port &#8211; so it will be trivial to write extensions and make it start to do really useful stuff (haven&#8217;t quite got around to that yet, so expect a part 3)</p>
<p>Additionally, in the process I&#8217;ve become pretty familiar with  how USB works, and I&#8217;ll try to more simply define it for those who are interested in getting started.</p>
<p><span id="more-233"></span></p>
<p>First, some detail about how I managed to make it to this point; I&#8217;ve wanted to play around with USB for quite a long time &#8211; the first time I tried was many many years ago, around the time I had mastered several much simpler serial protocols&#8230; That didn&#8217;t particularly go anywhere as I had no idea where to start with the USB specification, and every part of it seemed equally irrelevant and incomprehensible.</p>
<p>As you might imagine, I&#8217;ve since become a lot better at reading specifications &#8211; and while the USB specification is still by no means trivial, it makes quite a bit of sense now, and have been able to identify the important parts and work through the process of actually building a compatible device.</p>
<p>Since I&#8217;m using an AVR with USB support, some level of this is done for me;  the entire electrical communication layer is done, and the vast majority of the protocol work &#8211; all that remains is to handle the high level messages and instruct the hardware on how to proceed. This was indeed a pretty easy thing to do, just bugs caused quite a lot of pain.</p>
<p>One thing I&#8217;ve found very helpful in this process is USB protocol tracing; There are a number of tools out there that can capture USB traffic, and if you&#8217;re using Windows 7, a mechanism to do this exists built into the OS&#8217;s USB stack itself (take a look <a title="USB Tracing in Windows 7" href="http://blogs.msdn.com/b/usbcoreblog/archive/2009/12/04/etw-in-the-windows-7-usb-core-stack.aspx">here</a> for more information). In general the bugs I&#8217;ve hit were mainly packets that didn&#8217;t complete properly (returned an inappropriate response, or didn&#8217;t return at all), and those things are pretty easy to find in a protocol trace.</p>
<p>So, let&#8217;s start with a broad question: What is USB?</p>
<p>The USB specification defines the behavior and allowed interactions of all parts of the USB ecosystem. It provides a framework for building devices which require data transfer between the device and host, in a number of ways. The specifications for USB are available from<a href="http://www.usb.org/home"> usb.org</a> &#8211; Most modern devices are USB 2.0, and USB 3.0 is out of the scope of what I&#8217;m talking about here :)</p>
<p>It&#8217;s actually a very  wide specification, and the USB specification and related specifications seek to define a lot of things, such as:</p>
<ul>
<li>How a USB device physically attaches to a host system (Mechanical, chapter 6)</li>
<li>How a USB device electrically communicates to a host system (Electrical, chapter 7)</li>
<li>What specific sorts of message types should be sent between the host and device, and the bit patterns they map to (Protocol layer, Chapter 8)</li>
<li>How the device uses those messages to interact with the host and expose data about itself (USB Device Framework, Chapter 9)</li>
<li>How the host should behave in general</li>
<li>How hubs should work, to allow a single USB port to drive multiple devices</li>
<li>And additionally the USB Device Class specifications specify in more detail how certain types of devices should behave, in a standardized way.</li>
</ul>
<p>For what I have been doing with the USB stick and general microcontroller USB development (when hardware support is available), only the parts about the Device Framework and device class specifications are really important &#8211; it&#8217;s good to know about the protocol layer but that is for the most part taken care of for you.</p>
<p>Still, it is pretty complex &#8211; but only because there are a number of details to attend to. I&#8217;m omitting a few of the details, but I&#8217;ll go over the major points individually:</p>
<p>First, a device is a logical object composed of endpoints &#8211; There are 16 endpoint numbers and 0 is always a special number for sending control messages to the device. Everything about USB is host-centric, the host initiates all transactions, the device must only respond. So the majority of what happens in USB, is the host sends a packet of a certain type, to a specific endpoint, and then the device responds to that request with data, acknowledgement, or some error condition.</p>
<p>An endpoint is really just a buffer to send or receive data &#8211; the endpoints in USB microcontrollers typically only operate in one direction, though the USB standard allows an endpoint to both send and receive data. Typically you will have to configure your endpoint with a specific size (which will be communicated to the host via descriptors, see further below)  - Then either you will make an IN endpoint write data to the buffer, and hardware will happily send it to the host the next time the host asks about that endpoint &#8211; or you will create an OUT endpoint, wait for it to be filled by the host, and the process the incoming data. Endpoint 0 must operate in both directions, and that balance is a little elaborate to maintain.</p>
<p>The big three request packets the host uses to control the flow of data are: SETUP, IN, and OUT. IN commands are the host asking for data, OUT commands are the host sending data, and SETUP packets are slightly more complicated &#8211; a SETUP packet must only be sent to endpoint 0, and it is always followed by an 8-byte data packet, which is a data structure specifying a request. As part of the setup transaction, the host may send additional data (with an OUT), or may ask for data (with an IN); and a third stage with the opposite direction will give the device a chance to acknowledge or reject the transaction.</p>
<p>Here&#8217;s another representation&#8230;</p>
<p>Host sending data to device:  OUT &#8211; &lt;host sends data&gt; &#8211; [device ACK, handled by hardware]</p>
<p>Host requesting data from device: IN &#8211; &lt;device sends data&gt; &#8211; [host ACK, or retry logic handled by hardware]</p>
<p>Host sending a SETUP request with no extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK in hardware] &#8211; IN &#8211; &lt;Device sends zero-length data packet to acknowledge&gt; &#8211; [host ACK]</p>
<p>Host sending a SETUP request and requesting extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK] &#8211; IN &#8211; &lt;Device sends extra data&gt; &#8211; [host ACK] &#8211; OUT &#8211; &lt;Host sends zero length packet&gt; &#8211; [Device ACK to acknowledge]</p>
<p>Host sending a SETUP request and sending extra data: SETUP &#8211; &lt;host sends 8 bytes&gt; &#8211; [Device ACK] &#8211; OUT &#8211; &lt;Host sends additional data&gt; &#8211; [Device ACK]  - IN &#8211; &lt;Devices sends zero-length packet to acknowledge&gt; &#8211; [Host ACK]</p>
<p>Alternately, the device may send a STALL response instead of data / ack if it does not support a SETUP operation (or if the endpoint has an error); (to add another detail,  USB hardware will also send NAK packets to delay requests until the device is ready to respond- which I haven&#8217;t included for the sake of simplicity)</p>
<p>Another small complexity in the SETUP phase is that if your data payload exceeds the maximum endpoint length, multiple packets will be sent/requested, finally terminating with a packet less than the maximum endpoint size.</p>
<p>So, did I say this was simple? I&#8217;m sorry :)</p>
<p>That&#8217;s the very outer shell &#8211; the information you need to know to interface with the hardware; Next comes the requests themselves.</p>
<p>The requests are completely documented in the USB specification, in  sections 9.3 and 9.4; The specification leaves a little bit to be desired in the clarity of what exactly needs to be handled, but most importantly you need to focus on the &#8220;type&#8221; field in the bmRequestType and also the request code itself. If the type is a standard request, the table of standard device request IDs is in that area, If the type is a class, or vendor request, a different table of request codes applies. It is necessary to handle several of the standard requests in order for a device to work. Most importantly though, are set_address, get_descriptor, and set_configuration. Several of the others are required, but not all of them (I&#8217;m not elaborating further because the descriptions in section 9.4 are actually not bad)</p>
<p>For set_address, some interesting logic is usually required, After receiving the set_address packet, you must complete the ACK phase before actually setting the address (or else your address will change before the host commits to your new address, and it will not be possible to complete the ACK ) &#8211; the Atmel datasheet went into some detail on how it should be done. The entire transaction is done without extra data (the address is passed in one of the fields of that 8-byte SETUP data packet), so it is the software&#8217;s responsibility only to receive that, process it, and then instruct the hardware to send a zero-length data packet in response to the host&#8217;s IN (and set the address AFTER that packet completes)</p>
<p>Get_Descriptor is the most important command to get right, and you only absolutely have to handle two types of requests here. First: for descriptor type 1 and descriptor index 0 (the Device descriptor), and second: descriptor type 2 and descriptor index 0 (The first Configuration descriptor) &#8211; The descriptors I will cover in a moment, but they are relatively large data structures that describe the structure of your device, among other important details. This is probably the only setup request that is likely to need multiple packets in response (My setup endpoint is 32 bytes, and my configuration descriptor is 67 bytes &#8211; so 3 packets for me). In this case the idea is to process the SETUP data structure, reject it with STALL if it&#8217;s not one of the supported types, but otherwise send packets of max length followed by waiting for those packets to complete until  you get to the end (you either send a zero length packet or non-max-length packet as the last one). Note as well that the get_descriptor request includes a maximum length, so you may have to stop early sometimes.</p>
<p>By default, your device is in an unconfigured state, essentially all of the endpoints are supposed to be turned off (Except endpoint 0), the device should not be doing anything notable. &#8211; set_configuration allows the host to turn on a device to one of potentially several operating modes (each one of these modes gets a configuration descriptor)</p>
<p>If you can implement those three, the others will follow pretty naturally, and Class requests when implementing class devices follow the same pattern.</p>
<p>One last subject for this blog post: Descriptors!</p>
<p>The USB descriptor definitions in Section 9.6  are pretty well documented structures. The device descriptor is simple enough &#8211; when you are asked to provide a device descriptor, they mean you should send a string of bytes that correspond to the USB device descriptor (9.6.1) &#8211; Note that some of the numeric fields are a bit&#8230; distant &#8211; descriptor type numbers are in table 9-5 back in section 9.4.</p>
<p>The configuration descriptor is the tricky one. If you read about the get_descriptor device request (9.4.3) you&#8217;ll find that the configuration descriptor should actually be a configuration descriptor, followed by one or more interface descriptors, and each interface descriptor may be followed by one or more endpoint descriptors (think of a tree). In the USB world, A configuration is thought of as a mode of operation, and an interface is thought of as a logical unit  that serves a specific function. That specific function is associated with the Zero endpoint for control (typically as Vendor type requests, which you can define yourself if you want to write a driver), and possibly one or more endpoints, which serve as data pipes for interfacing with the device.</p>
<p>How should you define a configuration? Well, any way you want if you are writing your own driver&#8230; But USB-IF noticed that this wasn&#8217;t ideal, and so the notion of Class devices was brought into the world.</p>
<p>I&#8217;m not going to cover this here (this post is already so very long!), but  in addition to the USB core specification there are a large number of official class specifications, which define how specific types of devices should operate &#8211; To be more specific, they define what things you should have in your configuration, and they provide a list of class requests, notifications, and custom descriptors related to describing various types of devices. The upshoot of all this is you simply have to implement a class device, and likely the driver to make your device work on whatever computer you plug it into has already been written for you.</p>
<p>In re-reading this, I doubt I will have answered everyone&#8217;s questions, I&#8217;m happy to answer further questions if you post them; USB does seem pretty simple after wading through it for a week or two, but it is still a large array of moving parts, regardless of how simple as they may be individually.</p>
<p>I&#8217;m planning to continue this, another time, and I have been working on a USB cribsheet for my own reference that I&#8217;ll also link here sometime.</p>
<p>(And now, I am off, to implement a USB bootloader, and USB jtag programming and&#8230; )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/27/usb-stick-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Project: PCI Card</title>
		<link>http://blog.akkit.org/2010/06/13/project-pci-card/</link>
		<comments>http://blog.akkit.org/2010/06/13/project-pci-card/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 07:00:56 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=213</guid>
		<description><![CDATA[Another week has gone by already? Well, I do at least have something to show for it. So the thing I spent the most spare time on this last week has been designing a FPGA-based PCI card. This is something I&#8217;ve wanted to do for some time now (and have an earlier unfinished attempt that [...]]]></description>
			<content:encoded><![CDATA[<p>Another week has gone by already? Well, I do at least have something to show for it.</p>
<p>So the thing I spent the most spare time on this last week has been designing a FPGA-based PCI card. This is something I&#8217;ve wanted to do for some time now (and have an earlier unfinished attempt that was far more complex), but I have recently encountered some inspiration for a board that will be somewhat useful, or at least interesting.</p>
<p>This board isn&#8217;t really much of anything special, but it will fill a specific niche, and will be sufficient to try out a lot of interesting things I&#8217;ve been thinking of in the PCI space.</p>
<p>So, This isn&#8217;t going to be an exceptionally impressive post, but I did collect screenshots from various stages of the board&#8217;s development, and  I&#8217;ll also discuss the design decisions behind this board.</p>
<p><span id="more-213"></span></p>
<p>On with the screenshots!</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip1.png"><img class="alignnone size-medium wp-image-214" title="pcipost_wip1" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip1-300x185.png" alt="" width="300" height="185" /></a></p>
<p>(Just getting started, have finished the core of the schematic, have all the power and parts set up)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip2.png"><img class="alignnone size-medium wp-image-215" title="pcipost_wip2" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip2-300x191.png" alt="" width="300" height="191" /></a></p>
<p>(After working out the pin mappings from FPGA to PCI card, adding some PCI-related capacitors)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip3.png"><img class="alignnone size-medium wp-image-216" title="pcipost_wip3" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip3-300x186.png" alt="" width="300" height="186" /></a></p>
<p>(Fixed the PCI &#8211; fpga mappings slightly and started routing. This is a few hours of progress, but it takes a lot of effort&#8230;)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip4.png"><img class="alignnone size-medium wp-image-217" title="pcipost_wip4" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip4-300x188.png" alt="" width="300" height="188" /></a></p>
<p>(Continuing to route PCI-FPGA traces)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip5.png"><img class="alignnone size-medium wp-image-218" title="pcipost_wip5" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip5-300x183.png" alt="" width="300" height="183" /></a></p>
<p>(Ah. Done with that. A few things move around to pack better)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip6.png"><img class="alignnone size-medium wp-image-219" title="pcipost_wip6" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip6-300x161.png" alt="" width="300" height="161" /></a></p>
<p>(A lot of other stuff gets routed! It&#8217;s not as hard as the PCI stuff :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip7.png"><img class="alignnone size-medium wp-image-221" title="pcipost_wip7" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_wip7-300x155.png" alt="" width="300" height="155" /></a></p>
<p>And the final part done: Routing the power pins on the FPGA. (And a few pesky remaining traces due to an error)</p>
<p>The signals on the board are now 100% routed, but the board is still not complete, I have a number of cosmetic things to do still, moving component text around and adding some descriptive text. Also planning to add ground fills to unused board space.</p>
<p>So, some of you may have guessed my inspiration for this board, it&#8217;s pretty similar to those &#8220;BIOS POST code display&#8221; boards &#8211; Yup, and that is one of the intended uses of this board, but by no means all it can do. This board has been designed so it can also easily work as a standalone development board for general purpose FPGA experimentation, and it is also my intention to build a full PCI Device using this board as well. Of course it&#8217;s not going to do much with this board alone, but the I/O header should allow for some interesting external devices if I want to try anything specific.</p>
<p>Some more specific details of the design:</p>
<ul>
<li>The PCB is routed with 8 mil traces (and 8 mil spacing) &#8211; this makes it pretty challenging to route, but it was fun.</li>
<li>If operating only as a PCI card, it would be possible to remove several components (the power supply stuff and clock  on the right side of the board), without affecting anything</li>
<li>The FPGA in this case is a Spartan-3AN (XC3S50AN &#8211; not incredibly big but will work here) &#8211; the 3AN series, as opposed to most other Spartan-3 FPGAs, have onboard flash memory to store configuration data (otherwise an external chip would be needed to configure from, eating up more I/O pins)</li>
<li>There are 4 I/O pushbutton switches, and an 8-switch dipswitch</li>
<li>The PRSNT1# and PRSNT2# lines on the PCI connector are used to indicate to the system board whether or not a PCI card is present in a given slot. This board has solder-bridge jumpers potentially connecting those to ground (to indicate presence); In the case of a BIOS POST card we don&#8217;t actually want to indicate to the system that there is a board present, as we can get what we want without being a &#8220;full&#8221; pci device. But bridging those jumpers will also allow a full PCI device to be designed.</li>
<li>The PCI connector has been routed by flipping back-side signals to the top side, and trying to align the PCI signals to the FPGA pins before even starting that; On the back side, I have a thick 3.3V trace running along the length of the connector, and a GND trace above that, which makes it relatively easy to keep all the power lines connected properly. This is the fourth or so revision of my process for doing this, and it&#8217;s pretty effective &#8211; but I noticed yet another optimization&#8230; If I also were to match up the FPGA 3.3V pins with the front-side PCI 3.3V pins, it would further reduce the complexity of routing the connector, and I&#8217;d get better connected power pins as well &#8211; Something to consider for next time, the time that goes into planning and routing the PCI connector to a FPGA is pretty significant.</li>
</ul>
<p>I am planning to finish up the design work and get some of these boards produced in the next few days &#8211; and when I get them back and get some stuff working on them, I&#8217;ll post again on how it went, how PCI works, and other sorts of interesting things :)</p>
<p>Update: After a little bit more effort, I have deemed the board &#8220;complete&#8221;. Now working on getting it fabricated&#8230;</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_rev1.png"><img class="alignnone size-medium wp-image-227" title="pcipost_rev1" src="http://blog.akkit.org/wp-content/uploads/2010/06/pcipost_rev1-300x151.png" alt="" width="300" height="151" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/13/project-pci-card/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Project: AVR USB Stick</title>
		<link>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/</link>
		<comments>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 07:00:30 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=202</guid>
		<description><![CDATA[Hi again, As promised, this week&#8217;s project entry is much less entertaining; I did attempt to get this project a bit further today but distractions have taken their toll. Expect this one to come up again in the future :) So, not too long ago I had the bright idea to build a little USB [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again,</p>
<p><a href="http://blog.akkit.org/2010/05/30/project-chip-decapping/">As promised</a>, this week&#8217;s project entry is much less entertaining;</p>
<p>I did attempt to get this project a bit further today but distractions have taken their toll. Expect this one to come up again in the future :)</p>
<p>So, not too long ago I had the bright idea to build a little USB stick; My motives at the time were apparently highly questionable, so I am here about a month later with a fairly limited use USB stick</p>
<p>One of my major goals behind this project was to have an excuse to work out the details of USB, and try some stuff out, which I&#8217;m still doing now. Once I get that done with, I will attempt to explain just how all that works; USB is a bit elaborate, but it&#8217;s increasingly interesting and important these days, as serial and parallel ports are becoming more rare. I have another project along these lines too, but it&#8217;s quite a bit more low-level.</p>
<p>For this post though, I&#8217;m just talking about the hardware design of this project. <span id="more-202"></span></p>
<p>The board was really quickly designed; I thought (for some reason) that it would be neat to have a little USB stick that had an RGB LED, and a speaker to output audio. So, that&#8217;s what I made :)</p>
<p>This stick is based around a <a href="http://www.atmel.com/dyn/products/product_card_v2.asp?part_id=4602">Atmel ATMega32U2 microcontroller</a>, which has  built-in USB device support. It requires a pretty stable clock source in order to use USB, so I picked an 8MHz crystal for it. I found a <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=475-2855-1-ND">reasonably cheap RGB LED</a> on digikey, and added some passives, an op amp, and a tiny speaker I had around for sound.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_play1.png"><img class="alignnone size-medium wp-image-203" title="usb_play1" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_play1-300x124.png" alt="" width="300" height="124" /></a></p>
<p>PCB design for the board (It looks confusing because I&#8217;ve included a lot of layers, but you don&#8217;t usually work with all of those layers on, you can just look at the front/back individually)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd1.jpg"><img class="alignnone size-medium wp-image-204" title="usb_playbrd1" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd1-300x105.jpg" alt="" width="300" height="105" /></a></p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd2.jpg"><img class="alignnone size-medium wp-image-205" title="usb_playbrd2" src="http://blog.akkit.org/wp-content/uploads/2010/06/usb_playbrd2-300x98.jpg" alt="" width="300" height="98" /></a></p>
<p>And, actual implementation of the board!</p>
<p>I&#8217;m sure you can see the mistakes in this one, but probably not quite all of them. Things to check for next time I make a really rushed design:</p>
<ul>
<li>Make sure TFQFP package reflects reality. Not sure how but my pads start at the very tip of the pins :) I must have been looking at the wrong package type for spacing info.</li>
<li>Enhance font size on 0402 components (see the 2 tiny capacitors by the crystal? They&#8217;re C1 and C2 in the PCB design image.)</li>
<li>Make sure crystal doesn&#8217;t overlap other components (fortunately the crystal body isn&#8217;t connected to anything, so it can be near / short against USB V+ without issue.)</li>
<li>Pay closer attention to drill sizes. USB header shield doesn&#8217;t actually fit through the holes I designed it for. I have a caliper so these sorts of mistakes are just silly :)</li>
</ul>
<p>Some other miscellaneous design notes</p>
<ul>
<li>This AVR has a 3 PWM channels based on one 16bit timer &#8211; this is being used for the RGB LED</li>
<li>The audio output is a PWM channel on another 8bit timer &#8211; it&#8217;s feeding through a resistor into a cap, which produces a pretty stable voltage level based on the PWM duty cycle. Then the opamp is buffering that voltage level and outputting it to the speaker. It should be able to do 8bit audio with good quality, though it&#8217;s certainly not a perfect DAC.</li>
</ul>
<p>So, not bad for a few hours of looking for parts and hacking some weekend, I&#8217;m not actually sure if the utter lack of any serious purpose makes this a good or bad project :)</p>
<p>Anyway, I&#8217;m off now, as I have some other project ideas calling me now&#8230;  Perhaps this motivation drought has ended.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/06/06/project-avr-usb-stick/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Project: Chip decapping</title>
		<link>http://blog.akkit.org/2010/05/30/project-chip-decapping/</link>
		<comments>http://blog.akkit.org/2010/05/30/project-chip-decapping/#comments</comments>
		<pubDate>Sun, 30 May 2010 07:00:08 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware Hacking]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=167</guid>
		<description><![CDATA[3 blog posts already, amazing &#8211; though very shortly I may have to start talking about far less interesting projects, or post less frequently. This is starting to take quite a bit of time, and I&#8217;m running out of interesting things I&#8217;ve been doing. :) So, recently I&#8217;ve started looking into ASIC design &#8211; it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>3 blog posts already, amazing &#8211; though very shortly I may have to start talking about far less interesting projects, or post less frequently. This is starting to take quite a bit of time, and I&#8217;m running out of interesting things I&#8217;ve been doing. :)<br />
So, recently I&#8217;ve started looking into ASIC design &#8211; it&#8217;s will still be quite a long time before I can practically start thinking about trying to design my own chip, however, in the meantime some chip reverse engineering has attracted my attention.<br />
Now, I mostly operate from a home-lab environment, and it&#8217;s not really safe to involve things like&#8230; high concentrations of Nitric acid. But, having recently acquired a decent cheap USB microscope (the <a href="http://www.amazon.com/gp/product/B0025U0L8Y?ie=UTF8&amp;tag=stepswebl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B0025U0L8Y">Veho VMS004DELUXE USB Powered Microscope</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=stepswebl-20&amp;l=as2&amp;o=1&amp;a=B0025U0L8Y" border="0" alt="" width="1" height="1" />), I decided to give chip disassembly a shot for the amusement value. Given my lack of professional tools this has little potential to be really educational, but it was pretty interesting. This is a pretty picture-heavy post,  if that wasn&#8217;t clear enough already&#8230;<span id="more-167"></span></p>
<p>I went and found a few chips I had around, and got some sandpaper; For this test I just used 220, 600, 1500, and 2500 grit sandpaper; I had a few others around but these worked pretty well. The microscope is pretty nice, and has essentially two zoom settings, at around 20x and around 400x (or so is claimed). As such, a lot of the &#8220;chip-size&#8221; images are taken at the 20x level, and then I have zoomed in to the 400x level, taken sets of images, and stitched them together for full die images. Die images were stitched together using <a href="http://research.microsoft.com/en-us/um/redmond/groups/ivm/ice/">Microsoft ICE</a>, a free tool that does stuff like that, it has worked pretty well for me here.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/setup.jpg"><img class="alignnone size-medium wp-image-168" title="setup" src="http://blog.akkit.org/wp-content/uploads/2010/05/setup-300x129.jpg" alt="" width="300" height="129" /></a></p>
<p>The first of the chips was some chip I had desoldered from a board I had around a very long time ago; I had no idea what it was, but it appears to be a <a href="http://www.onsemi.com/PowerSolutions/product.do?id=MC34072">MC34072 dual op-amp</a></p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/c1.jpg"><img class="alignnone size-medium wp-image-144" title="c1" src="http://blog.akkit.org/wp-content/uploads/2010/05/c1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>On with the sandpaper; It takes a bit of time to sand down to the die layer, so patience is important here.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/c2.jpg"><img class="alignnone size-medium wp-image-145" title="c2" src="http://blog.akkit.org/wp-content/uploads/2010/05/c2-300x225.jpg" alt="" width="240" height="180" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/c3.jpg"><img class="alignnone size-medium wp-image-146" title="c3" src="http://blog.akkit.org/wp-content/uploads/2010/05/c3-300x225.jpg" alt="" width="240" height="180" /></a></p>
<p>I didn&#8217;t see any of the bond wires in this chip, possibly because I wasn&#8217;t sure what to be looking for. They aren&#8217;t obvious in these pictures either, I&#8217;m not sure why. After much sanding  though I could see the die</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/c4.jpg"><img class="alignnone size-medium wp-image-147" title="c4" src="http://blog.akkit.org/wp-content/uploads/2010/05/c4-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>I took a full set of images at the higher magnification level at this point, though it&#8217;s pretty clear the chip packaging material is still covering a lot of the die. (this is a big image! click to zoom in!). The die is upside-down in the chip orientation I chose, so I&#8217;ve rotated the die images.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/die1_stitch.jpg"><img class="alignnone size-medium wp-image-149" title="die1_stitch" src="http://blog.akkit.org/wp-content/uploads/2010/05/die1_stitch-300x281.jpg" alt="" width="300" height="281" /></a></p>
<p>That&#8217;s pretty neat, though I&#8217;ve taken a little bit of the corner of the die off already. I spent a bit more time sanding with high grit (1500) to try to clean up the rest of the die- and while I lost some of the corners I&#8217;ve made the rest of the die a lot more visible.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/c5.jpg"><img class="alignnone size-medium wp-image-148" title="c5" src="http://blog.akkit.org/wp-content/uploads/2010/05/c5-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/die1_stitch4.jpg"><img class="alignnone size-medium wp-image-150" title="die1_stitch4" src="http://blog.akkit.org/wp-content/uploads/2010/05/die1_stitch4-300x282.jpg" alt="" width="240" height="226" /></a></p>
<p>That one is pretty easy to follow, it&#8217;s a very big process as it was designed apparently a long time ago (I wonder if the &#8220;72&#8243; is the year the design was created). Unfortunately none of the other chips in this set are quite so nice :)</p>
<p>Also, even though you can very clearly see the metal traces in this die, what you don&#8217;t really see are the doped regions of the silicon underneath, so it&#8217;s difficult at best to infer the transistors being used. In some regions it&#8217;s possible to tell that something is different underneath (see some areas where the blue changes to dark gray), but I&#8217;m not sure what to infer from that (possibly that is material being used for resistors).</p>
<p>The next chip I set out to decap is one of my favorites, the <a href="http://www.xilinx.com/support/documentation/data_sheets/ds057.pdf">Xilinx XC9572XL CPLD</a>:</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x1.jpg"><img class="alignnone size-medium wp-image-157" title="x1" src="http://blog.akkit.org/wp-content/uploads/2010/05/x1-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x2.jpg"><img class="alignnone size-medium wp-image-158" title="x2" src="http://blog.akkit.org/wp-content/uploads/2010/05/x2-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>Bond wires! They actually serve as a reasonably good guide to know how well you are aligned with the die, and what areas you need to sand further so the die is more parallel to your sanded surface.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x3.jpg"><img class="alignnone size-medium wp-image-159" title="x3" src="http://blog.akkit.org/wp-content/uploads/2010/05/x3-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x4.jpg"><img class="alignnone size-medium wp-image-160" title="x4" src="http://blog.akkit.org/wp-content/uploads/2010/05/x4-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>You can see that my alignment has improved but isn&#8217;t perfect yet; Also at this point I took a closer look at the bond wires (at 400x)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x5.jpg"><img class="alignnone size-medium wp-image-161" title="x5" src="http://blog.akkit.org/wp-content/uploads/2010/05/x5-300x240.jpg" alt="" width="300" height="240" /></a></p>
<p>Can&#8217;t see the die at all yet, just the bond wires and packaging material. Continuing to sand&#8230;</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x6.jpg"><img class="alignnone size-medium wp-image-162" title="x6" src="http://blog.akkit.org/wp-content/uploads/2010/05/x6-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x7.jpg"><img class="alignnone size-medium wp-image-163" title="x7" src="http://blog.akkit.org/wp-content/uploads/2010/05/x7-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>Getting closer and starting to see the die&#8230;</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x8.jpg"><img class="alignnone size-medium wp-image-164" title="x8" src="http://blog.akkit.org/wp-content/uploads/2010/05/x8-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x9.jpg"><img class="alignnone size-medium wp-image-165" title="x9" src="http://blog.akkit.org/wp-content/uploads/2010/05/x9-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>And finally breaking through the filler material to exposing the actual die surface! I then sanded a bit further with really high grit and took a few sets of images for the full die image. Ultimately I wound up using a slightly rotated orientation for taking pictures of this die, as I noticed the LED illumination at that angle made it easier to see many of the details. This method is far from perfect though &#8211; there&#8217;s still a lot of filler on the die which is only partly transparent, but I didn&#8217;t want to sand the edges away (also, too lazy now.).</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/x10.jpg"><img class="alignnone size-medium wp-image-166" title="x10" src="http://blog.akkit.org/wp-content/uploads/2010/05/x10-300x240.jpg" alt="" width="300" height="240" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/die2_stitch2.jpg"><img class="alignnone size-medium wp-image-175" title="die2_stitch2b" src="http://blog.akkit.org/wp-content/uploads/2010/05/die2_stitch2b-203x300.jpg" alt="" width="162" height="240" /></a></p>
<p>Partly due to the microscope&#8217;s cheap optics and camera, and also due to the material remaining on the die, it&#8217;s very hard to discern details at this level, but you can see the larger elements in use and how they are generally connected together.</p>
<p>And now a very cheap AVR Chip I had around, this is an <a href="http://www.atmel.com/dyn/products/product_card_v2.asp?PN=ATtiny48">ATTiny48</a>:</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr1.jpg"><img class="alignnone size-medium wp-image-138" title="avr1" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr1-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr2.jpg"><img class="alignnone size-medium wp-image-139" title="avr2" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr2-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr3.jpg"><img class="alignnone size-medium wp-image-140" title="avr3" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr3-300x240.jpg" alt="" width="240" height="192" /></a> <a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr4.jpg"><img class="alignnone size-medium wp-image-141" title="avr4" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr4-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>I got down to the die level without too much trouble, though I exposed one corner a lot earlier than the rest of it. After looking at that one corner closer, I decided it was important to take more of the filler material off</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr5.jpg"><img class="alignnone size-medium wp-image-142" title="avr5" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr5-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr6.jpg"><img class="alignnone size-medium wp-image-143" title="avr6" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr6-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>After taking more material off I do have a much clearer view of the die but  managed to badly mess up the one corner. I did get a (mostly) complete die image &#8211; there&#8217;s a black area I somehow managed to miss :)</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/die3_stitch.jpg"><img class="alignnone size-medium wp-image-152" title="die3_stitch" src="http://blog.akkit.org/wp-content/uploads/2010/05/die3_stitch-228x300.jpg" alt="" width="228" height="300" /></a></p>
<p>It&#8217;s a pretty small process, but you can generally identify the regions and their purposes. I&#8217;m not an expert on this stuff yet, but my current assumption is the shiny stuff in the bottom center is flash, the nice structured grid in the upper middle of the chip is sram, and most of the stuff above/around it is the uC logic (But I may be completely incorrect, I can see other possible interpretations.)</p>
<p>That leaves one more chip&#8230; This chip was ill fated in many ways; first it&#8217;s a bit too big for me to be able to move the microscope around above it well &#8211; but I was a bit less than patient with decapping it, and managed to seriously scratch up the die. The die showed up earlier than I thought it would, but I&#8217;ll let the images tell the story:</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/intel1.jpg"><img class="alignnone size-medium wp-image-153" title="intel1" src="http://blog.akkit.org/wp-content/uploads/2010/05/intel1-300x240.jpg" alt="" width="240" height="192" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/intel2.jpg"><img class="alignnone size-medium wp-image-154" title="intel2" src="http://blog.akkit.org/wp-content/uploads/2010/05/intel2-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/intel3.jpg"><img class="alignnone size-medium wp-image-155" title="intel3" src="http://blog.akkit.org/wp-content/uploads/2010/05/intel3-300x240.jpg" alt="" width="240" height="192" /></a> <a href="http://blog.akkit.org/wp-content/uploads/2010/05/intel4.jpg"><img class="alignnone size-medium wp-image-156" title="intel4" src="http://blog.akkit.org/wp-content/uploads/2010/05/intel4-300x240.jpg" alt="" width="240" height="192" /></a></p>
<p>Oops. I cleaned up the remaining die a bit and tried to get some decent pictures, but this chip is on a much smaller process than the others and I couldn&#8217;t see much of anything that was big enough to see the structure of.</p>
<p>Overall this has been a pretty entertaining project for me. I think I will definitely have to try this using an acid rather than sandpaper some time in the future, and I&#8217;m already looking at better microscopes for when I get more serious with this.</p>
<p>In the meantime though, I hope you&#8217;ve found this as interesting as I have &#8211; thanks for reading!</p>
<p>Tune in next week for&#8230; Something obviously less awesome :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/05/30/project-chip-decapping/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Project: 8&#215;8 LED Matrix Controller</title>
		<link>http://blog.akkit.org/2010/05/23/8x8-led-matrix-controller/</link>
		<comments>http://blog.akkit.org/2010/05/23/8x8-led-matrix-controller/#comments</comments>
		<pubDate>Sun, 23 May 2010 06:00:49 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=113</guid>
		<description><![CDATA[Another week has gone by, and it&#8217;s time for another project! This week&#8217;s project is a little bit more complex than the last one, but it&#8217;s still pretty small. It&#8217;s a small board that drives an 8&#215;8 LED matrix. It&#8217;s actually a pretty silly project because I only have a dozen or so of these [...]]]></description>
			<content:encoded><![CDATA[<p>Another week has gone by, and it&#8217;s time for another project!</p>
<p>This week&#8217;s project is a little bit more complex than the last one, but it&#8217;s still pretty small. It&#8217;s a small board that drives an 8&#215;8 LED matrix. It&#8217;s actually a pretty silly project because I only have a dozen or so of these LED Matrices around (I&#8217;m not sure I can even buy these specific matrices anymore) &#8211; I actually bought them back in 2005 &#8211; they&#8217;re 8&#215;8 arrays of red/green LEDs. They&#8217;re organized with a common anode per row, and then red/green cathodes per column. (<a href="http://blog.davr.org/2006/03/15/smiley/">Davr also got some</a>, and has a number of entries on his blog about his efforts)</p>
<p>Just for fun, I set out to design a board that would sit on the back of the LED matrix and make it easy to drive from a small microcontroller. My design goals were to have current drivers on the common anodes, and provide a shift register to easily configure the other LEDs. I also wanted to be able to easily chain multiple boards together to make a much longer array. (Read on for more details about the design&#8230;)<span id="more-113"></span></p>
<p>So, after measuring the part and setting up a part in eagle for the LED matrix, I set to work on a circuit board.</p>
<p>This part I actually generated a timelapse video of &#8211; you can see it here:  <a href="http://www.youtube.com/watch?v=pB9d3X24IA4">PCB design: An LED Matrix Controller board </a></p>
<p>The video may be a little boring (perhaps I should add music or something), but my process went as follows:</p>
<p>First I had to design an interface, a set of pins that would let me control the board, specifying what to display and how. I settled on a pretty simple design: There is a power and ground pin, 3 pins for selecting one of the 8 rows, and finally a serial interface into a shift register for providing the graphical data. The serial interface consists of SCLK, SDATA, and LATCH &#8211; Upon a rising edge of SCLK, the internal shift register will be advanced as the value of SDATA is pushed in. LATCH serves dual duty; a rising edge of LATCH causes the shift register&#8217;s value to be latched to the display output, and also LATCH serves as an output enable, LEDs only light up when LATCH is high.</p>
<p>Additionally, since I wanted this module to be chainable, I also need a second interface on the other side of the board to attach to a second board &#8211; Most of the signals are the same, but the data signal on the other side has to be an output from the shift register &#8211; just another thing to consider. I used a CPLD (the XC9572XL again!)  to actually do all the intelligent work, and for switching the power to the common anodes, I used some P-FETs which are switched by the CPLD.</p>
<p>After getting the circuit straight, it was a bit of a challenge to actually decide what CPLD pins to use, and how exactly to lay out the board. This is always an interesting problem, and sometimes difficult, but when you keep your priorities straight it is reasonably easy to get past. In my case, power/GND and the Jtag pins dictated how certain parts of my board needed to work, and as with most cpld and fpga designs,  most of the signals could have been connected to any of the pins on the CPLD. I took care to connect the serial clock pin to one of the global clock pins on the CPLD, but the majority of the pins were just connected to nearby CPLD pins for convenience. Ultimately I ended up using a 45-degree  orientation for my CPLD, which I think simplified a lot of the routing.</p>
<p>Once the pin mappings were decided, routing was pretty simple, and didn&#8217;t take too much time; I was able to quickly route the majority of the traces, only having to move some things around for the last few traces &#8211; And that&#8217;s where the timelapse video ends. Afterwards I did wind up increasing the trace width just a bit, adding a bypass cap for the CPLD (which is important enough normally, but really important when switching power), and just cleaning some things up.</p>
<div id="attachment_122" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_pcbdesign.png"><img class="size-medium wp-image-122 " title="ledmatrix_pcbdesign" src="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_pcbdesign-300x297.png" alt="" width="300" height="297" /></a><p class="wp-caption-text">PCB Design for the LED Matrix board</p></div>
<p>So, I submitted some PCBs to be produced via <a href="http://batchpcb.com/index.php/Products">BatchPCB</a>, and  waited a few weeks for them to show up.</p>
<p>A few weeks pass, and they do finally show up!</p>
<p>It did not take long to solder one together, so the second phase of this project began: designing the CPLD code. While I designed the interface with the possibility of implementing PWM in mind (to vary the brightness of the LEDs), I opted to start with the simplest usable design first. My VHDL code which controls the CPLD performs essentially the following operations:</p>
<ul>
<li>Decodes the ROW0..2 to enable one of the 8 common row FETs (sets one line to low, all others to high)</li>
<li>Has an internal 16bit array for the row data (8 red, 8 green LEDs). If LATCH is high, the inverse of these values will be exposed to the LEDs (as low = on), otherwise the LEDs will be off (pulled high)</li>
<li>Has an internal 16bit shift register which is shifted on the rising edge of SCK (new bit is shifted in from SDATA, and the last bit is always exposed as SDATA on the other side of the board)</li>
<li>When Latch transitions from low-&gt;high, the shift register is latched into the internal LED data array.</li>
</ul>
<p>And, that&#8217;s the complete system! It is ntended to be controlled with 6 I/O pins, but you can, if you don&#8217;t mind a little bit of light bleeding, even connect SCK and Latch together and drive it with only 5 pins, which I did for testing (using an ATTiny85 chip). My ideas for improvement are a bit limited because there isn&#8217;t really much space available on this CPLD for elaborate designs&#8230; I could abandon the idea of having a separate shift register and internal display register, and use a few bits per pixel to hold a several-bit-per-pixel value, and use the LATCH signal both as a display enable and also to advance a PWM clock. The problem with this though is then setup time becomes pretty high per row (as you can no longer shift new data in the background &#8211; shifted data would be immediately visible), so you have to update at a lower frequency.</p>
<p>The JTAG connector on the bottom edge works pretty well, though it took a few attempts before I held the connector against it firmly and consistently enough to program the CPLD.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_1.jpg"><img class="alignnone size-medium wp-image-131" title="ledmatrix_1" src="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_1-294x300.jpg" alt="LED Matrix board, soldered - Complete with cat hair!" width="294" height="300" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_2.jpg"><img class="alignnone size-medium wp-image-132" title="ledmatrix_2" src="http://blog.akkit.org/wp-content/uploads/2010/05/ledmatrix_2-300x237.jpg" alt="Picture of the LED matrix with the tiny chip controlling it. Hard to get much grainier than this." width="300" height="237" /></a></p>
<p>(Some pictures above&#8230; The soldered board, and also a test pattern &#8211; I could make a happy face, but davr already did so what&#8217;s the point? ;) The red LEDs are only on due to bleeding as the line is visible as the data is being shifted. This would be avoided if I were using 6 I/O pins and using LATCH as intended, but using the attiny85, I only have 5 practical I/O pins)</p>
<p>Overall, it was a pretty entertaining project, though I probably won&#8217;t do much further with it. It was very much a spur of the moment project, so I didn&#8217;t really have any deep plans. While I could chain many of these together I would start to have serious problems supplying the power easily, as the estimated maximum of 400mA per board is actually a significant amount of power &#8211; my present lab equipment doesn&#8217;t include a proper power supply, so maybe a future project will be to build some higher power 3.3V power supplies :)</p>
<p><strong>Some Theory &#8211; A closer look at the details</strong></p>
<p>(For those of you who aren&#8217;t deeply familiar with this stuff, which might be most of you.)</p>
<p>This matrix is an 8&#215;8 array of bicolor Red/Green LEDs; to make it easier to deal with, instead of just giving you pins for each LED, they give you buses; In this case they connect the Anodes (positive terminals) of each row and give you one pin per row-anode-bus. Then they also  connect the red and green Cathodes (independently) to column buses, and expose those buses. You can&#8217;t tell this sort of system to &#8220;hold&#8221; a specific image, it&#8217;s designed for you to only draw one row at a time &#8211; however, due to <a href="http://en.wikipedia.org/wiki/Persistence_of_vision">Persistence of Vision</a> effects, you can quickly alternate between driving each row with a different pattern, and it will appear that the entire matrix is on at once. The points behind this are signal management and cost&#8230; This module gives you 8 pins for common row anodes, 8 pins for common red cathodes, and 8 pins for common green cathodes &#8211; a total of 24 pins. Actually wiring each LED independently would give you 64 LEDs * 3 pins per LED = 192 pins&#8230; Not nearly as easy to connect; and most sane designers would just connect the rows and columns together in a logical fashion on the PCB. Driving each LED independently is arguably just a bit less than 8 times as expensive as driving 8 sets of 8 LEDs and switching between them (even before you consider the PCB routing logistics to drive each LED independently!) In some systems (like giant full color LED display signs, and such) it does make sense to use per-LED driver circuitry in order to be as bright as possible, and they are rather expensive due to this and other factors :)</p>
<p>Some logistics have to be considered in a design like this &#8211; such as, just how much current is it going to draw? Assuming the CPLD is well programmed, at most 16 individual LEDs will be on at once. The LEDs have forward voltages of about 1.7-1.9V, and this board is driving them at 3.3V in series with 50 Ohm current limiting resistors. Walking through the power calculation, I&#8217;ll assume the LED has a 2.0V forward voltage drop (which is a worst case estimate), so the resistor will drop 1.3V when the LED circuit is switched on (as 2.0V + 1.3V = 3.3V); and as the voltage across the resistor is 1.3V, the current through the resistor (and as such, through the LED) will be 26mA (V = IR, or I = V/R, where V=1.3V, and R=50Ohm) &#8211; the reality is a little bit more complicated because LED voltage drops vary, and the CPLD will only allow so much current.</p>
<p>The CPLD needs to also turn individual rows on and off &#8211; but it can&#8217;t actually switch very much current on it&#8217;s own. As such, this design uses a FET that does the electrical heavy work, and the CPLD tells the FET to turn on and off. So how much current might a row take if it&#8217;s turned on? Assuming a worst case current of about 25mA per LED, the system will use 400mA if all 16 LEDs are on at once! (The CPLD by itself can only practically switch 20-30mA) I found a capable FET to handle this load though (Digikey part number <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=DMP2004KDICT-ND">DMP2004KDICT-ND</a>) &#8211; which is a P-Channel FET capable of switching 600mA. All FETs essentially switch current flow on and off based on the voltage between the Gate and Source pins, but being a P-Channel FET means that the Source pin should be the highest voltage of the three, and it will switch on (&#8220;connect&#8221; the Source pin to the Drain pin) when the Gate&#8217;s voltage is less than the Source pin voltage by a certain amount. This FET has a switching voltage of 1V, so it&#8217;s &#8220;off&#8221; when the Gate voltage is &gt; 2.3V, and &#8220;on&#8221; when the Gate voltage is &lt; 2.3V &#8211; as such a logic low applied to the Gate pin turns the FET on.</p>
<p>Final note: A lot of these technical details are pretty shallow explanations; Things really do work this way, but there be dragons and missed details in all of the numbers I&#8217;ve given; here&#8217;s a small list of examples: The CPLD driving voltage actually depends on current, so it won&#8217;t be quite 3.3V &#8211; my example is a worst case estimate. You can see these pin driving traces sometimes in CPLD datasheets (And other times they&#8217;re linked: <a href="http://www.xilinx.com/support/documentation/application_notes/xapp150.pdf">Xilinx FPGA/CPLD I/V Curves</a>, see page 6 for XC9500XL family. Also, see Page 13 of the  <a href="http://www.xilinx.com/support/documentation/user_guides/ug445.pdf">CPLD I/O User Guide</a> for more information on I/V curves). The FETs, too, add a resistance to the load passing through them (about 0.9 ohm in this case &#8211; this is shown on the Digikey page as &#8220;Rds On&#8221;, and will also be specified in the part datasheets), so that further reduces the 3.3V that I was assuming. On a completely different tangent, FETs are capable of a lot more than just turning on and off, though they are in fact really good just for switching on/off, which is why they&#8217;re used so extensively in modern electronics (CMOS digital logic is typically almost all FETs). If you want a good book that explains all the minute details for discrete circuit design, I highly recommend <a href="http://www.amazon.com/gp/product/0521370957?ie=UTF8&amp;tag=stepswebl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0521370957">The Art of Electronics</a><img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=stepswebl-20&amp;l=as2&amp;o=1&amp;a=0521370957" border="0" alt="" width="1" height="1" />- It&#8217;s a little bit older, but presents most of the important concepts in electronics very clearly and in an easily approachable way.</p>
<p>(It&#8217;s over! Phew- that was long. Now I&#8217;m thinking about what to write about for next week&#8230; I have a good idea for next week, but beyond that it&#8217;s a bit hazy&#8230; I have literally piles of projects around here, the problem is almost none of them are done&#8230; Perhaps this will be an incentive to work harder! That can only be a good thing, right?)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/05/23/8x8-led-matrix-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project: AVR Programmer</title>
		<link>http://blog.akkit.org/2010/05/16/project-avr-programmer/</link>
		<comments>http://blog.akkit.org/2010/05/16/project-avr-programmer/#comments</comments>
		<pubDate>Sun, 16 May 2010 06:00:47 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/?p=103</guid>
		<description><![CDATA[Here&#8217;s the first installment of my weekly project report thing :) Wish me luck! So, not terribly long ago I decided it was really time to give microcontrollers another go; My history with microcontrollers in general has been a little sketchy, because not only are they pretty limited systems, but they don&#8217;t really allow a [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the first installment of my weekly project report thing :) Wish me luck!</p>
<p>So, not terribly long ago I decided it was really time to give microcontrollers another go; My history with microcontrollers in general has been a little sketchy, because not only are they pretty limited systems, but they don&#8217;t really allow a lot of creativity in solving your problems. Being mostly self-taught on ARM and x86 CPU architectures, the little 8-bit uCs generally seemed more like a pain than anything else.</p>
<p>However,  I was determined not to let my history deter me, and to try again. I ordered some AVR DIP chips for prototyping and a serial programming cable. Unforuntately, like so many well laid out plans, this didn&#8217;t wind up working out &#8211; not knowing too much about the AVR landscape, I had inadvertently ordered a serial programmer that requires an actual native serial port to work (it wouldn&#8217;t do anything with my USB-serial converter&#8230; And seriously, who has a native serial port around these days?)</p>
<p>Being incredibly stubborn and unwilling to  wait further to order yet another programmer, I decided to take matters into my own hands &#8211; After reading the AVR documentation on programming their chips (which is actually quite good), I put together a small CPLD based programmer which has served my needs. Read on for the full details&#8230;</p>
<p><span id="more-103"></span></p>
<p>The original version of the programmer was a tangled ball of wirewrap wire, tightly coupling the core components, and was fortunately soldered well enough to hold together for several weeks before the first PCB arrived. I built the programmer out of materials I had readily lying around, it consists of: A 3.3V regulator (At the time, I was going to run the AVR chips at 5V &#8211; and my CPLD is 3.3V with 5V tolerant IO), a CPLD (XC9572XL), a 50MHz clock generator, and a MAX3232 equivalent serial level shifter (and a few caps for good measure). I wrote some basic VHDL to speak serial and accept some basic commands to control some pins as GPIO, and then a powershell script (yes, a powershell script) that interfaced the serial port and performed the high level programming commands. It didn&#8217;t take too terribly long, and it did finally work! I got my AVR to blink an LED, such a worthy task of all this effort :)</p>
<p>Below is the evolution of versions of this project &#8211; First the tangled mess; Second was the first PCB revision, it added an LED and had a few minor pcb errors; And third is the second PCB revision &#8211; which has 2 LEDs (one red, one green) for status.</p>
<p><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev0.jpg"><img class="alignnone size-medium wp-image-106" title="avr_cpld_rev0" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev0-264x300.jpg" alt="" width="264" height="300" /></a> <a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev1.png"><img class="alignnone size-medium wp-image-108" title="avr_cpld_rev1" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev1-253x300.png" alt="" width="253" height="300" /></a><a href="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev2.png"><img class="alignnone size-medium wp-image-107" title="avr_cpld_rev2" src="http://blog.akkit.org/wp-content/uploads/2010/05/avr_cpld_rev2-251x300.png" alt="" width="251" height="300" /></a></p>
<p>(Can you spot the PCB errors in rev 1?)</p>
<p>Another hurdle that had to be overcome was that of programming speed &#8211; using the CPLD just as GPIO worked, but manually sending a byte for each clock transition was pretty slow and tedious. So I revisited the CPLD firmware and added another mode for AVR programming, It&#8217;s a special command that operates on the following 4 bytes: for each of these bytes it will automatically generate clock transitions in sync with the serial state machine, and also send back the data received from the chip (which is also in sync with the serial state machine). This makes programming the chip approximately 16 times faster than it was &#8211; it&#8217;s not as fast as it can be but it&#8217;s pretty quick and only limited by the serial connection speed at this point.</p>
<p>So, while this project hasn&#8217;t precisely been a necessary one, it has actually been pretty interesting and useful. One of the nice things about having a few GPIO pins around is that I&#8217;ve actually reused this for other things as well, like dumping a serial eeprom :) (in fact I even wound up using the 4-byte serial mode for the EEProm serial transfer as well, it&#8217;s pretty much just a 32bit serial mode) &#8211; And I imagine this device may come in handy in the future too for similar things (though, it will probably become obsolete around the time my current big project is done&#8230; I&#8217;ll leave that one to your imagination for now.)</p>
<p>And finally, this project did indeed serve my original goal, I&#8217;ve continued to do some development for the AVR uC platform, and while I still would prefer a much more beefy CPU, I have to admit that these little chips are pretty intelligent choices for small cheap projects that need something &#8220;smart&#8221; but don&#8217;t need much in the way of power. As such, I have a few projects based around them &#8211; and while I don&#8217;t have too many projects involving uCs at the moment, they are likely to get more attention in the future.</p>
<p>Okay! So that&#8217;s the first one; I hope you found this entertaining, and who knows where this will go next week :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2010/05/16/project-avr-programmer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Displays!</title>
		<link>http://blog.akkit.org/2006/03/13/displays/</link>
		<comments>http://blog.akkit.org/2006/03/13/displays/#comments</comments>
		<pubDate>Mon, 13 Mar 2006 18:44:00 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://blog.akkit.org/2006/03/13/displays/</guid>
		<description><![CDATA[Well, a few days I put in an order with The Electronic Goldmine for a few parts, specificly including 4 of their Giant Display Assortments (at a cost of $20 for the 4). Well, suffice it to say I now have enough LED Displays for the next several rounds of crazy projects :) I got [...]]]></description>
			<content:encoded><![CDATA[<p>Well, a few days I put in an order with <a href="http://www.goldmine-elec.com/default.htm">The Electronic Goldmine</a> for a few parts, specificly including 4 of their <a href="http://www.goldmine-elec-products.com/prodinfo.asp?number=G9877&#038;variation=&#038;aitem=2&#038;mitem=2">Giant Display Assortments</a> (at a cost of $20 for the 4). Well, suffice it to say I now have enough LED Displays for the next several rounds of crazy projects :)<br />
I got a whole boatload of LED displays, and a few character LCDs, some traditional LCDs (including one with REALLY bent legs!) some VFDs, and some other stuff. On a side note, some of the LCDS/VFDs are cracked, or appear to otherwise be in non-working condition, which is sad, but really all that can be expected from a grab bag like this.<br />
There were also a huge amount of bent pins, but that&#8217;s also to be expected, and in most cases was very easy to correct with very little effort.<br />
Anyway, at this point I&#8217;m not sure what to do with all of these, but I&#8217;m not likely to attempt to rival <a href="http://tripoint.org/kevtris/">kevtris</a> and his <a href="http://blog.akkit.org/wp-content/uploads/2006/03/megaclock65.jpg">mega-clock</a>&#8230; need more displays for that :)<br />
I&#8217;ve included a picture of all the displays here, as I&#8217;m sure you&#8217;re all interested by now.<br />
<a class="imagelink" href="http://blog.akkit.org/wp-content/uploads/2006/03/displays.jpg" title="Lots of displays!"><img id="image4" src="http://blog.akkit.org/wp-content/uploads/2006/03/displays.thumbnail.jpg" alt="Lots of displays!"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akkit.org/2006/03/13/displays/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
