<?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>hairy.geek.nz</title>
	<atom:link href="http://hairy.geek.nz/feed/" rel="self" type="application/rss+xml" />
	<link>http://hairy.geek.nz</link>
	<description>Tech and Electronics</description>
	<lastBuildDate>Mon, 06 Feb 2012 10:24:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>NTP 1.4 works!</title>
		<link>http://hairy.geek.nz/2012/02/ntp-1-4-works/</link>
		<comments>http://hairy.geek.nz/2012/02/ntp-1-4-works/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 10:24:44 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=234</guid>
		<description><![CDATA[It&#8217;s taken a while to get back to this point, but there we are. Verison 1.4 of the board finally works well enough it will be accepted by a real ntpd.]]></description>
			<content:encoded><![CDATA[<p><a href="http://hairy.geek.nz/wp-content/uploads/2012/02/ntp-1.4-synced.png"><br />
<img class="aligncenter size-full wp-image-235" title="ntp-1.4-synced" src="http://hairy.geek.nz/wp-content/uploads/2012/02/ntp-1.4-synced.png" alt="" width="564" height="139" /></a></p>
<p>It&#8217;s taken a while to get back to this point, but there we are. Verison 1.4 of the board finally works well enough it will be accepted by a real ntpd.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2012/02/ntp-1-4-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LCA and yet more new projects</title>
		<link>http://hairy.geek.nz/2012/02/lca-and-yet-more-new-projects/</link>
		<comments>http://hairy.geek.nz/2012/02/lca-and-yet-more-new-projects/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 21:51:13 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=219</guid>
		<description><![CDATA[A few weeks ago I attended linux.conf.au 2012 in Ballarat, Australia. I&#8217;ve attended it for many years now (every year since 2006!) and the conference has always been a great place to see what other people are doing with open &#8230; <a href="http://hairy.geek.nz/2012/02/lca-and-yet-more-new-projects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I attended linux.conf.au 2012 in Ballarat, Australia. I&#8217;ve attended it for many years now (every year since 2006!) and the conference has always been a great place to see what other people are doing with open source, discover new things I want to play with when I get back, and generally feel it&#8217;s okay to be a huge open source nerd.</p>
<p>This year was also the first time I&#8217;d presented at the conference, although just in one of the miniconfs. The Arduino miniconf is usually quite popular as the first half of the day is spent assembling a project &#8211; this year a full Arduino clone with a bunch of extra peripherals - and then more conventional presentations on things related.</p>
<p>I&#8217;ve embedded my talk below, you can probably guess the subject given how often I&#8217;ve posted about it. (The clip is a bit of a wonky encode, the AV team didn&#8217;t quite trim it properly so it doesn&#8217;t start until 57m into the video. It&#8217;s not really an hour an a half long!)</p>
<p>In other news, I&#8217;ve started to embark on designing an Arduino clone based off the XMEGA MCU line, probably a D3 to begin with as it&#8217;s what I&#8217;m most familar with. The rough bought layout has been done, although it&#8217;s missing switching power sources between the DC jack and USB. It&#8217;s also deliberately not using the USB capabilities of some of the XMEGAs since there&#8217;s a lack of good code around to support it and it complicates the board layout a fair bit.</p>
<p>The rest of the projects are slowly making their way towards further progress!</p>
<p><iframe src="http://www.youtube.com/embed/uUuroWJRpsI#t=56m56s" frameborder="0" width="480" height="360"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2012/02/lca-and-yet-more-new-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heat</title>
		<link>http://hairy.geek.nz/2012/01/heat/</link>
		<comments>http://hairy.geek.nz/2012/01/heat/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 22:23:06 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=213</guid>
		<description><![CDATA[All electronics exists to convert electricity into (mostly) heat. It just happens to do something useful along the way. The progression on the design so far has been to consider digital issues first (make the circuit work at all), then &#8230; <a href="http://hairy.geek.nz/2012/01/heat/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>All electronics exists to convert electricity into (mostly) heat. It just happens to do something useful along the way. The progression on the design so far has been to consider digital issues first (make the circuit work at all), then mechanical (fit to the case), and now is down to thermal &#8211; what to do with the heat.</p>
<p>Now that I&#8217;ve started to run the prototypes in the target case I have some idea of the temp of the board, components, and how the case feels. And it&#8217;s warmer than I want.</p>
<p>This is somewhat of an issue since the stability of the clock is related to the temperature. If a crystal has a stability of, say, 20ppm, it is always stated with a temperature range at which that holds true. For (most) cheap crystals that&#8217;s 25 degrees. As it gets colder or warmer it gets worse.</p>
<p>During the design some of this was taken into consideration. Firstly, since we are aligning ourselves to GPS sources, the stability is less critical: we have a stable external reference less influenced by our local temperature. It does mean we&#8217;re limiting how long we can run without GPS sources (it&#8217;s currently in the &#8220;minutes&#8221; range, which is not far off what a $4k device does and this costs nothing like that). This is currently implemented in a coarse-grain way, we just adjust our internal clock being fed by the DS3234 output.</p>
<p>Secondly, the decision to use the DS3234 RTC instead of a watch crystal was driven by the fact it&#8217;s a Temperature Compensated Crystal Oscillator, that is it has a temp sensor and can tune the crystal inside it to compensate for the local temperature. Over the range 0 to 40 degrees it claims 2ppm out of the box, and 3.5ppm between -40 and +85. So even with a lot of heat it&#8217;s still significantly more stable than a cheap watch crystal.</p>
<p>There are some things I haven&#8217;t implemented yet which I&#8217;ll now need to consider.</p>
<p>The DS3234 exposes it&#8217;s tuning interface, and the datasheet mentions that with an external trusted reference (oh hai GPS) you can feed it extra offset information to further compensate for both aging and to obtain finer precision (you get about +/- 0.1ppm of control). I&#8217;ll need to add an extra step after GPS lock to tune the DS3234 against the GPS pulses, and retune it from time to time.</p>
<p>Once the case is closed up properly (it&#8217;s not fully closed right now), it may need some holes cut in specific places to improve natural convection. Likely places will be right under the (not very efficient, therefore a source of a lot of heat) LDO regulator. It also will likely need holes in both endplates to ensure any air that is around can get into the case.</p>
<p>We&#8217;re also running the main MCU at full clock rate without any regard for clocking down based on demand. While it&#8217;s a lot of work to implement, I could look at power management for the MCU by implementing dynamic clocking.</p>
<p>Those things can be done without changing any aspect of the board design.  But there&#8217;s board design changes I&#8217;m looking at as well.</p>
<p>The 1.5 board now has space for a 16x16x4mm fan in one endplate, with PWM control so we can run it as slow as possible. Like many things, it&#8217;s there if I finally decide it needs a fan, but it&#8217;s something I&#8217;m going to try to avoid. The fan is 3.3V so doesn&#8217;t need it&#8217;s own LDO (since a lot of fans are 12V, fewer 5V), but should probably have a transistor between the MCU and it to source as little current from the MCU as possible.</p>
<p>The LDO has also been re-arranged to make it easier to attach a small heatsink to. Ideally this will move heat away from going into the board so much, as I suspect that&#8217;s what is really causing the reported temps to be as high as they are. It might only work best with real airflow over it, but we&#8217;ll see how that goes.</p>
<p>There&#8217;s also some evidence the Ethernet section is drawing more power than it should do, as a result of not quite getting the front-end right. There&#8217;s fixes for that in 1.5 as well.</p>
<p>All in all, it feels like I&#8217;m getting into the real tail end of the project now to be considering these sorts of issues. There&#8217;s less making-it-work-at-all, and more making-it-awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2012/01/heat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NTP 1.4 SVN Merge</title>
		<link>http://hairy.geek.nz/2011/12/ntp-1-4-svn-merge/</link>
		<comments>http://hairy.geek.nz/2011/12/ntp-1-4-svn-merge/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 20:18:08 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=188</guid>
		<description><![CDATA[Just a wee note for anyone (as unlikely as that is!) following the Hardware NTP Server SVN tree that I&#8217;ve merged the XMEGA branch into trunk, since we have an XMEGA based 1.4 up and running. If you want to &#8230; <a href="http://hairy.geek.nz/2011/12/ntp-1-4-svn-merge/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a wee note for anyone (as unlikely as that is!) following the <a title="Hardware NTP Server" href="http://hairy.geek.nz/projects/hardware-ntp-server/">Hardware NTP Server</a> SVN tree that I&#8217;ve merged the XMEGA branch into trunk, since we have an XMEGA based 1.4 up and running.</p>
<p>If you want to see any of the pre-XMEGA code, there&#8217;s a release tagged &#8220;board-1.3&#8243; which was the last working version for the MEGA MCU on a rev 1.3 board.</p>
<p>Should it come to pass we need a rev 1.5, I will tag the last working 1.4 release in the same way.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/12/ntp-1-4-svn-merge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Production</title>
		<link>http://hairy.geek.nz/2011/12/production/</link>
		<comments>http://hairy.geek.nz/2011/12/production/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 09:20:04 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Production]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=180</guid>
		<description><![CDATA[One of the reasons I picked the Breadboard PSU as the first project to attempt to ship and sell was its simple. At the same time, its representative of what would be required for any design to be seen though &#8230; <a href="http://hairy.geek.nz/2011/12/production/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the reasons I picked the <a title="Breadboard PSU" href="http://hairy.geek.nz/projects/breadboard-psu/">Breadboard PSU</a> as the first project to attempt to ship and sell was its simple. At the same time, its representative of what would be required for any design to be seen though to actually being in people&#8217;s hands &#8211; other designs just have more parts.</p>
<p>Unexpectedly this week a bunch of the PSUs sold, and more needed to be built in a (relatively) short time. This is quite different as an experience to the prototyping phase, where every build is unique and new, and the timeline is as long or short as you feel like. I&#8217;m glad that I chose something simple to start with, because I&#8217;ve very quickly found the things I need to think about for larger and more complex designs going into production.</p>
<h2>Inventory management is important</h2>
<p>During the prototyping phase on all of the projects I have underway at the moment, I&#8217;ve built up quite a stack of parts. Some of these parts overlap with other designs, but most are design-specific. For example, every design will probably involve a ton of 100nF power supply decoupling caps scattered all around various ICs. But this is the exception, not the rule.</p>
<p>For a while, &#8220;inventory management&#8221; was a pile of parts in bags. It started out in small bins, when it was mostly PTH parts which really were easier to store in little bins, but as the number of parts escalated it fell off a little. I only knew if I could build one by actually finding all the parts at the time.</p>
<p>Inventory management is really critical if you need to know quickly how <em>many</em> you can build beyond just one. One is easy. Five or ten imposes more need to know how many you have of all your components. At least twice now I&#8217;ve been caught out by problems in inventory &#8211; one part important part wasn&#8217;t tracked at all, and a second wasn&#8217;t updated properly to reflect builds completed.</p>
<p>Some of this comes from the fact upstream part suppliers probably won&#8217;t sell you one of a part, but often if you want good prices you&#8217;ll need to buy 10, or 50, or 150 at a time anyway. And they&#8217;ll get used at different rates, so you need to track the build usage carefully as well.</p>
<h2>Plastic stencils last; stencilling jig needs work</h2>
<p>I&#8217;ve only ever used plastic stencils for assembling my mostly-SMD boards, and had some concerns about how long they would last. It turns out more than long enough, and now I have a cheap source to make them (<a href="http://www.ponoko.com">Ponoko</a>) I&#8217;m less worried about exactly how long they&#8217;ll last. Still, I&#8217;ve gotten sixteen builds out of the first stencil and they&#8217;ve effectively cost a buck for each stencil, so it&#8217;s a good run.</p>
<p>The more significant problem with the stenciling approach is the jig I use is .. primitive. I&#8217;ve just used spare boards I had from prior prototypes to form something to wedge the target board in place, and it does the job, but only just. It would be easier with something more purpose cut to surround the board as much as possible. One option is to get something laser cut by Ponoko but I&#8217;ll need to figure out how close their material thicknesses will get to a PCB thickness.</p>
<h2>Frypan works, reflow oven nicer</h2>
<p>Despite how primitive the frypan cooking method for board soldering is, it actually does work, and I can manage to get a few boards at a time being soldered up. The reliability has been reasonable so far, although we&#8217;ll see how these turn out in the field. The main problem is actually the need to watch it. A controlled oven I could put a set of boards on a tray, stick them in, and just run the cook profile.</p>
<p>This will mean I might have to step up efforts to work on building a reflow oven myself. A full commercial one is both far too large, too expensive, and probably not a lot better than a hacked up toaster oven, but something with control is better than none.</p>
<h2>SMD parts are great for production</h2>
<p>It feels very strange to be so in favour of surface mount parts, but they are so much easier to solder together a bunch of components than PTH by hand with a soldering iron. I had already come to the conclusion SMD parts made things easier in general, but it wasn&#8217;t until I realised I was spending 33% of the build time on just a single PTH component that it really hit home how much easier.</p>
<p>There are still some challenges, getting tiny parts orientated out of the tape they often come in is a pain, and tweezers are a bit prone to too much force causing the part to fly off and disappear to never be seen again .. but those are mostly going to come down to practice. I&#8217;ve also ordered a cheap vacuum pencil to see how that works for part pick-up and placement, as a sort of poor human pick-and-place machine.</p>
<h2>Production is confidence-building</h2>
<p>Lastly, production builds confidence in two ways. Being able to reproduce a build and have them pass basic QA tests first time, every time, gives you a lot more certainty about the way something has been designed. It works, so your understanding of how it works looks a bit better each time.</p>
<p>Having other people using your builds is also helps out a bit with motivation to build other things. It&#8217;s fun, no doubt about it I have enjoyed all the things I&#8217;ve built whether they worked or not, but it&#8217;s a very nice feeling having <em>new</em> devices you made, put for the first time into an anti-static bag, all clean and ready to be used by someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/12/production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New boards have arrived!</title>
		<link>http://hairy.geek.nz/2011/12/new-boards-have-arrived/</link>
		<comments>http://hairy.geek.nz/2011/12/new-boards-have-arrived/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 19:19:31 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[AVR Programmer]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>
		<category><![CDATA[LUFA]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=151</guid>
		<description><![CDATA[The new revision of the NTP Server and a test build of the LUFA AVR Programmer boards have arrived. The service from Seeedstudio was pretty quick and excellent for pricing, although one of the boards had some drills not correctly &#8230; <a href="http://hairy.geek.nz/2011/12/new-boards-have-arrived/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://hairy.geek.nz/wp-content/uploads/2011/12/ntp-14-avrprog-10-boards.jpg"><img class="aligncenter size-medium wp-image-152" title="ntp-14-avrprog-10-boards" src="http://hairy.geek.nz/wp-content/uploads/2011/12/ntp-14-avrprog-10-boards-300x180.jpg" alt="" width="300" height="180" /></a></p>
<p>The new revision of the NTP Server and a test build of the LUFA AVR Programmer boards have arrived. The service from Seeedstudio was pretty quick and excellent for pricing, although one of the boards had some drills not correctly done. Still, it&#8217;s far cheaper than getting larger runs made so I am quite happy.</p>
<p>Sadly, I appear to have made some mistakes with the stencils that were cut by Ponoko &#8211; the detail has been lost a lot more than previous cuts. I suspect I didn&#8217;t take into account laser kerf enough, but I also think they were cut without protective paper on both sides as previous ones were done. That seems to make a lot of difference. I shall get them re-cut in the next few days.</p>
<p>Now off to order more parts from Element 14 to prepare for the first builds of these new designs!</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/12/new-boards-have-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New boards on the way</title>
		<link>http://hairy.geek.nz/2011/11/new-boards-on-the-way/</link>
		<comments>http://hairy.geek.nz/2011/11/new-boards-on-the-way/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 00:09:56 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[AVR Programmer]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>
		<category><![CDATA[LUFA]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=144</guid>
		<description><![CDATA[I finally committed to a new set of boards for a couple of projects. NTP Server 1.4 and the LUFA-based AVR programmer both have been sent off to be manufactured, and assembly should take place in a few weeks time. I&#8217;ll separately post &#8230; <a href="http://hairy.geek.nz/2011/11/new-boards-on-the-way/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I finally committed to a new set of boards for a couple of projects. NTP Server 1.4 and the LUFA-based AVR programmer both have been sent off to be manufactured, and assembly should take place in a few weeks time. I&#8217;ll separately post about the changes for the NTP Server.</p>
<p>The LUFA board is an quick prototype to see how badly I&#8217;ve misread the USB AVR datasheets. It is based off the hints provided in a readme associated with some LUFA code, and vague attempts to read the USB sections of the Mega 16U2 datasheets. It includes a level shifter to support 1.8 &#8211; 5V targets which covers all the useful ranges of both Mega and XMega MCUs.</p>
<p>I&#8217;m not sure how the little LUFA board is going to turn out, but it was fairly cheap to get made and I&#8217;m bound to learn something out of it as a result.</p>
<p>These are the first boards being made by Seeedstudio&#8217;s Fusion PCB service, which for very short runs looks cheaper than previous options. It&#8217;s only 10 boards (compared to the 25 or so I was getting from other runs) so it&#8217;s more expensive per board but much cheaper to do a run because it&#8217;s a smaller number of  boards. We&#8217;ll see how they turn out.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/11/new-boards-on-the-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Final revision no really!</title>
		<link>http://hairy.geek.nz/2011/10/final-revision-no-really/</link>
		<comments>http://hairy.geek.nz/2011/10/final-revision-no-really/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 22:30:47 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=139</guid>
		<description><![CDATA[I think the number of times I&#8217;ve said &#8220;this is really the final revision&#8221; is now too numerous to count, but honestly this time I think it&#8217;s fairly close to final. (That&#8217;s downgraded from yesterday&#8217;s remark to people that asked, &#8230; <a href="http://hairy.geek.nz/2011/10/final-revision-no-really/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I think the number of times I&#8217;ve said &#8220;this is really the final revision&#8221; is now too numerous to count, but honestly this time I think it&#8217;s fairly close to final. (That&#8217;s downgraded from yesterday&#8217;s remark to people that asked,  where I said &#8220;actually is final&#8221;.)</p>
<p>The most recent scare with the design was what looked like a short in the antenna cable causing various things to reset and may now be damaged. It&#8217;s unclear to me exactly what happened, but we&#8217;re no longer getting a stable consistent GPS lock. The antenna is active &#8211; it has 3.3V fed up into it to power an LNA in the weather-sealed puck antenna &#8211; but there&#8217;s no current limitation on what&#8217;s fed up this path.</p>
<p>The datasheet for the GPS has a large example circuit to provide hints to the GPS chip that either the antenna is disconnected (only works for active antennas), or has a short and automatically disables the power into the antenna. But the design is far more than I really need, and takes up enough board space I&#8217;d have to do some serious rearrangement. It&#8217;d be nice to use the GPS chip&#8217;s LNA control line and reporting antenna modes, but the main thing is just limit current and suppress shorts.</p>
<p>I&#8217;ve generally ignored putting any significant additional current limitation into the design because none of it is exposed to any external connections. All the failure modes of any of the parts would just result in the board being tossed rather than fixed, and none of them actually are subject to external connectors &#8211; except now realising the antenna is directly. (The ethernet jack does have power going into the internal side of the transformer, but since it&#8217;s internal side a broken cable plugged into the jack doesn&#8217;t cause more power to be drawn.)</p>
<p>Instead, I&#8217;ve decided to just add a simple PTC fuse to the power input side of the antenna, limiting it to 125mA which is comfortably more than any active antenna should need, but should blow fast enough to prevent significant damage to the board. Whether I add some remote control of that power using a MOSFET or some sort of reporting of the failure to the GPS or MCU I haven&#8217;t decided. It depends on how much board space I need. A PTC fuse is small enough to just throw one on there without much concern.</p>
<p>(PTC fuses are tiny resistors which have a Positive Temperature Coefficient, that is as they try to carry more current they heat up, and a high enough current/temp will result in a very high resistance, enough to stop the current flowing. They reset themselves by cooling down. Their self-resetting nature and simplicity makes them useful for this sort of case. PTC fuses are commonly used in external power ports such as USB.)</p>
<p>Hopefully, that&#8217;ll reduce the risk of a short! Soon it will be ready!</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/10/final-revision-no-really/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XMega Clock System</title>
		<link>http://hairy.geek.nz/2011/10/xmega-clock-system/</link>
		<comments>http://hairy.geek.nz/2011/10/xmega-clock-system/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 06:31:10 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[xmega]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=137</guid>
		<description><![CDATA[The change between the AVR Mega and XMega architectures that I like the most is the clock system. It would be fair to say I have little love for the way that the Mega implements clock options, and given the &#8230; <a href="http://hairy.geek.nz/2011/10/xmega-clock-system/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The change between the AVR Mega and XMega architectures that I like the most is the clock system. It would be fair to say I have little love for the way that the Mega implements clock options, and given the changes in how it works in the XMega I don&#8217;t think I was alone.</p>
<p>On a Mega, the choice of system clock is set by fuses. It generally isn&#8217;t intended that you change fuses from your main code, instead they should be changed mostly by external programming or when asked by a bootloader. That is, you set fuses when doing a brand new build on an out of the box chip and never at any other time.</p>
<p>Mega fuses are a pain to work with. Apart from being inverted in sense (ie, 0 and 1 are called programmed and unprogrammed, and programmed means &#8220;active&#8221;) a single incorrect write to them can brick the chip and disable important programming interfaces. If you wanted to run a Mega at full clock speed, you had to carefully ensure an external crystal was present and then write the appropriate fuses. And hope.</p>
<p>(Pedant alert: technically there was one clocking option you could change from within your main code, that was system clock prescaler. It&#8217;s initalised from a fuse (CLKDIV8) to divide by 8 for a safe default from a variety of possible sources, but you could switch that to undivided in your main code quite easily and non-destructively. That still limited you do the internal 8MHz RC oscillator, however.)</p>
<p>The XMega does away with this disaster, and instead allows you to change the system clock source from within your main code at any time. It allows you to run the chips at their full speed without external components. You can use external components of a variety of speeds and multiply the clock in addition to dividing it. It&#8217;s a vastly better design.</p>
<p>By default, an XMega will always boot off the internal 2MHz RC oscillator, with the PLL multipler disabled and no prescaler divisions, giving us a nice simple reliable default clock to work with. Should any clock option you set later fail (and, yes, it has clock failure detection) the chip will always force itself back to the 2MHz RC oscillator. (It also generates a non-maskable interrupt for this situation, so you main code can do something about it.)</p>
<p>This means, in general, whatever you do to the chip is a simple flash of some new code to apply a different set of clocking options, even if you have pieces missing off the board you&#8217;ve built.</p>
<p>All XMegas are capable of running at 32MHz @ 3.3V and there&#8217;s a variety of ways to get this. The easiest to start with is using the internal 32MHz RC oscillator and run everything at the same clock rate. The only trick to enabling this is to ensure the oscillator is running before attempting to use it, and then changing the clock via a protection mechanism:</p>
<pre>OSC.CTRL = OSC_RC32MEN_bm; /* start 32MHz RC oscillator */
while (!(OSC.STATUS &amp; OSC_RC32MRDY_bm)); /* wait for ready */
CCP = CCP_IOREG_gc; /* allow changing CLK.CTRL */
CLK.CTRL = CLK_SCKLSEL_RC32M_gc; /* system clock is internal 32MHz RC */</pre>
<p>This does mean all peripheral modules are running at  32MHz as well, which all modules will accept by default. Some modules (EBI, HiRes Timer Extensions) run off faster clocks, which can be twice (PER2) or four times (PER4) the maximum system clock speed. Setting up the clock system for those I might cover at a later date.</p>
<p>Otherwise, that&#8217;s all which is required to get an XMega with no external components running at full clock speed. A lot nicer than a Mega!</p>
<p>An external crystal is not much harder, again you need to start the appropriate oscillator, wait for it to be ready, and change the clock via a protection mechanism. But in this case, we&#8217;re going to start with an 8MHz crystal and multiply it up to 32MHz using the PLL:</p>
<pre>OSC.XOSCCTRL = OSC_FREQRANGE_2TO9_gc | OSC_XOSCSEL_XTAL_256CLK_gc; /* configure the XTAL input */
OSC.CTRL |= OSC_XOSCEN_bm; /* start XTAL */
while (!(OSC.STATUS &amp; OSC_XOSCRDY_bm)); /* wait until ready */
OSC.PLLCTRL = OSC_PLLSRC_XOSC_gc | 0x4; /* XTAL-&gt;PLL, 4x multiplier */
OSC.CTRL |= OSC_PLLEN_bm; /* start PLL */
while (!(OSC.STATUS &amp; OSC_PLLRDY_bm)); /* wait until ready */
CCP = CCP_IOREG_gc; /* allow changing CLK.CTRL */
CLK.CTRL = CLK_SCLKSEL_PLL_gc; /* use PLL output as system clock */</pre>
<p>While this is quite a lot more code than using a crystal clock on a Mega, it is still better since we get flexibility about what kind of crystal we&#8217;re using and the desired real clock rate we want from it. We could have done this with just a 32MHz crystal, and avoided the PLL. But only needing a cheaper 8MHz one and being able to multiply it up to the desired clock rate is a nice feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/10/xmega-clock-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It would help if I knew what done looked like</title>
		<link>http://hairy.geek.nz/2011/10/it-would-help-if-i-knew-what-done-looked-like/</link>
		<comments>http://hairy.geek.nz/2011/10/it-would-help-if-i-knew-what-done-looked-like/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 07:02:02 +0000</pubDate>
		<dc:creator>dave2</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hardware NTP Server]]></category>
		<category><![CDATA[xmega]]></category>

		<guid isPermaLink="false">http://hairy.geek.nz/?p=132</guid>
		<description><![CDATA[Clearly posting about the NTP Server v1.4 board being done was a mistake, as I ended up launching myself into a major overhaul of it anyway. Yep, 1.4c was forked into 1.4d and has many many changes. Part of the &#8230; <a href="http://hairy.geek.nz/2011/10/it-would-help-if-i-knew-what-done-looked-like/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Clearly posting about the NTP Server v1.4 board being done was a mistake, as I ended up launching myself into a major overhaul of it anyway. Yep, 1.4c was forked into 1.4d and has many many changes.</p>
<p>Part of the problem is I&#8217;m not settled on what &#8220;done&#8221; looks like. I was originally planning on not migrating from a simple watch crystal RTC to the DS3234 RTC until after 1.4 was completed. But working with the XMega RTC has given me a lot of niggly issues around getting it to behave well with aligning the clock.</p>
<p>The problems with the XMega RTC are a mix of just the result of using a 20ppm crystal (ie, you get 20ppm accuracy, and that&#8217;s not so cool) and some interesting choices about how it&#8217;s built.</p>
<p>Some AVR Megas have an async clock timer, usually it&#8217;s the single 8-bit timer. It&#8217;s pretty basic, but 8-bit is actually a good choice since you can cover off the rest of the needed bits for a 32.768kHz crystal off interrupts, once every 256 ticks is not a heavy interrupt workload. The Xmega doesn&#8217;t have an async clock timer, instead there&#8217;s an explicit 16-bit RTC with a crystal input.</p>
<p>At first (mostly when reading the datasheet) this looks pretty good. But, there&#8217;s a few annoyances. A number of Megas (and, more specifically, the ones I&#8217;ve been using like the 1284P) allow not only a 32.768kHz crystal but an external clock input. This allows you to use a variety of other clock options. The Xmega RTC has no such option, not in the A and D series anyway, and that&#8217;s almost all of the ones actually shipping. (You can brute force an external clock into a crystal input but I&#8217;d prefer to stay within what the datasheet says the chip is expecting.)</p>
<p>The other issue with the RTC is the way you access it. Because it&#8217;s running in it&#8217;s own clock domain &#8211; specifically off whatever 32-ish-kHz source you chose &#8211; you have to jump through a lot of busywaiting to get configuration pushed into it. Busywait. Set something. Busywait. Set something else. And so on. The same problem plagues accessing the current count, if you want to change it yet more busywaiting.</p>
<p>You also don&#8217;t get any capture options with the RTC, it has just compare and period registers, that&#8217;s it.</p>
<p>This makes it quite difficult to align the RTC to a fine degree. Sure, it&#8217;s great if you just need a simple timer to fire, say, a 1Hz interrupt to do something else in your code. It&#8217;s actually very good at that. But if you actually care what &#8220;now&#8221; really is, then it doesn&#8217;t cut it.</p>
<p>Falling out of that has been a large redesign, and involving the DS3234 RTC to replace the simple crystal. Thankfully while they did take away async clocking for a timer, they replaced it with a much more awesome system and the result is any of the normal 16-bit timers can provide a better replacement with finer control and more reliable capture. I&#8217;ll probably post about that some other time.</p>
<p>I&#8217;ll still be using the Xmega RTC, but it&#8217;ll just be there as a system clock for trivial event timing that we don&#8217;t really care about alignment for. Hell, 1% RC oscillators used as an RTC will be fine for many other timing needs in the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://hairy.geek.nz/2011/10/it-would-help-if-i-knew-what-done-looked-like/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

