<?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"
	>

<channel>
	<title>thinkl33t</title>
	<atom:link href="http://thinkl33t.co.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://thinkl33t.co.uk</link>
	<description>The l33test thoughts you'll ever see.</description>
	<pubDate>Fri, 30 Jul 2010 16:42:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>OpenBench Logic Sniffer Case building</title>
		<link>http://thinkl33t.co.uk/?p=316</link>
		<comments>http://thinkl33t.co.uk/?p=316#comments</comments>
		<pubDate>Fri, 30 Jul 2010 16:42:29 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[case]]></category>

		<category><![CDATA[laser]]></category>

		<category><![CDATA[obls]]></category>

		<category><![CDATA[Robotics]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=316</guid>
		<description><![CDATA[Today I went to FabLab Manchester with one mission, to create a case for my OpenBench Logic Sniffer,  an awesome little device from dangerous prototypes and the gadget factory, which ships as a bare PCB.

I started off by measuring the OBLS (93mm x 48mm), and making a test box 5mm wider than it in each [...]]]></description>
			<content:encoded><![CDATA[<p>Today I went to <a href="http://www.fablabmanchester.org/" target="_blank">FabLab Manchester</a> with one mission, to create a case for my <a href="http://www.seeedstudio.com/depot/preorder-open-workbench-logic-sniffer-p-612.html?cPath=75">OpenBench Logic Sniffer</a>,  an awesome little device from <a href="http://dangerousprototypes.com" target="_blank">dangerous prototypes</a> and <a href="http://gadgetforge.gadgetfactory.net" target="_blank">the gadget factory</a>, which ships as a bare PCB.</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/sniffer_lrg.jpg"><img class="aligncenter size-medium wp-image-318" title="sniffer_lrg" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/sniffer_lrg-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>I started off by measuring the OBLS (93mm x 48mm), and making a test box 5mm wider than it in each direction.  I added some circles for bolt holes to the corners, and cut a test piece out of cardboard out using fablab&#8217;s Epilog Laser Cutter.</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/rect2818.png"><img class="size-medium wp-image-330  aligncenter" title="rect2818" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/rect2818-178x300.png" alt="" width="178" height="300" /></a></p>
<p>This piece seemed to be the right size, so I drew up the second layer, with the middle cut out, and a 1cm wide space for the USB socket.  this was printed and checked, and I proceeded to the third layer with cutouts for the header and the USB socket.</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/cardboard.jpg"><img class="aligncenter size-medium wp-image-325" title="cardboard" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/cardboard-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>After I was happy with the measurements on this mockup case, I cut out a copy in clear acrylic:</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto.jpg"><img class="size-thumbnail wp-image-323 alignnone" title="plasticproto" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto2.jpg"><img class="alignnone size-thumbnail wp-image-322" title="plasticproto2" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto2-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>Assembled it:</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto3.jpg"><img class="aligncenter size-medium wp-image-321" title="plasticproto3" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/plasticproto3-297x300.jpg" alt="" width="297" height="300" /></a></p>
<p>Disaster!  I had given enough room for the USB plug, but not for the USB cable that plugs into it.  I modified the top of the case with a cutout for the plug, and widened the USB hole to 12mm to compensate.</p>
<p>Cut out another copy with the modifications, and a prettier colour scheme:</p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/final-1.jpg"><img class="size-medium wp-image-320 aligncenter" title="final-1" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/final-1-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p style="text-align: center;"><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/final-2.jpg"><img class="aligncenter size-medium wp-image-319" title="final-2" src="http://thinkl33t.co.uk/wp-content/uploads/2010/07/final-2-300x217.jpg" alt="" width="300" height="217" /></a></p>
<p>Perfect!</p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2010/07/obls-case.zip">Download the Laser cutter files to make your own OBLS Case</a></p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=316</wfw:commentRss>
		</item>
		<item>
		<title>r2 - Moving Day!</title>
		<link>http://thinkl33t.co.uk/?p=302</link>
		<comments>http://thinkl33t.co.uk/?p=302#comments</comments>
		<pubDate>Sun, 24 May 2009 21:56:50 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Micromouse]]></category>

		<category><![CDATA[R2]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[MicroMouse]]></category>

		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=302</guid>
		<description><![CDATA[ 
Finally got some time to work on r2 this weekend, and have movement!  He can now move arond, and spin and stuff.
Unfortunately, still need to add some odometry, not quite worked out how thats going to work yet!
]]></description>
			<content:encoded><![CDATA[<p><!-- start insertion by YouTube Brackets, robertbuzink.nl --><span class="youtube"><object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/ZImGw8d2ksc"> <param name="movie" value="http://www.youtube.com/v/ZImGw8d2ksc" /><param name="wmode" value="transparent" /></object></span><!-- end Youtube Brackets insertion --></p>
<p>Finally got some time to work on r2 this weekend, and have movement!  He can now move arond, and spin and stuff.</p>
<p>Unfortunately, still need to add some odometry, not quite worked out how thats going to work yet!</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=302</wfw:commentRss>
		</item>
		<item>
		<title>r2 update</title>
		<link>http://thinkl33t.co.uk/?p=295</link>
		<comments>http://thinkl33t.co.uk/?p=295#comments</comments>
		<pubDate>Sat, 23 May 2009 16:54:42 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Micromouse]]></category>

		<category><![CDATA[R2]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[MicroMouse]]></category>

		<category><![CDATA[r2v1]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=295</guid>
		<description><![CDATA[finally got a gearbox mount that i&#8217;m happy with, just need to work out how to add odometry to it, since Plan A had two magnets close and opposite each other.  One wheel turning would turn the other!



]]></description>
			<content:encoded><![CDATA[<p>finally got a gearbox mount that i&#8217;m happy with, just need to work out how to add odometry to it, since Plan A had two magnets close and opposite each other.  One wheel turning would turn the other!</p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot0.png"><img class="alignnone size-medium wp-image-296" title="r2, no battery" src="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot0-300x225.png" alt="" width="300" height="225" /></a></p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot1.png"><img class="alignnone size-medium wp-image-298" title="r2, with battery" src="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot1-300x225.png" alt="" width="300" height="225" /></a></p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot2.png"><img class="alignnone size-medium wp-image-297" title="r2 underside" src="http://thinkl33t.co.uk/wp-content/uploads/2009/05/bot2-300x225.png" alt="" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=295</wfw:commentRss>
		</item>
		<item>
		<title>Chomp!</title>
		<link>http://thinkl33t.co.uk/?p=286</link>
		<comments>http://thinkl33t.co.uk/?p=286#comments</comments>
		<pubDate>Fri, 19 Dec 2008 11:49:21 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=286</guid>
		<description><![CDATA[Ever had an email attachment you want to put on the web, but cant be bothered downloading it to your PC, finding your FTP details, uploading it to a server, fixing the permissions, wondering why it isnt showing up then finding you put it in the wrong folder?
Well, Dan Had the same problem, and decided [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had an email attachment you want to put on the web, but cant be bothered downloading it to your PC, finding your FTP details, uploading it to a server, fixing the permissions, wondering why it isnt showing up then finding you put it in the wrong folder?</p>
<p>Well, <a href="http://www.danros.org.uk" target="_blank">Dan</a> Had the same problem, and decided there must be an easier way, so he created <a href="http://www.chompmail.co.uk/">ChompMail</a>!</p>
<p>Just forward your email to <a href="mailto:hugo@chompmail.co.uk">hugo the hippo</a>, and he&#8217;ll chomp it up, and put it on display for all to see!</p>
<p><a href="http://www.chompmail.co.uk"><img class="alignnone" title="Hugo" src="http://www.chompmail.co.uk/res/hugo.png" alt="Hugo the Hippo" width="298" height="249" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=286</wfw:commentRss>
		</item>
		<item>
		<title>Pandora Partslist</title>
		<link>http://thinkl33t.co.uk/?p=268</link>
		<comments>http://thinkl33t.co.uk/?p=268#comments</comments>
		<pubDate>Fri, 28 Nov 2008 11:50:31 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Gaming]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=268</guid>
		<description><![CDATA[After seeing skeezix&#8217;s unboxing of the pandora devkit, i decided to make a parts list of all visible ICs on the board.
U1	8JA98/JWI92	- [Micron RAM Package] atop TI OMAP 3530 SoC
U2	TWL4030CI 	- TI Audio &#38; Power Management Chip
U3
U4
U5
U6
U7
U8
U9
U10
U11
U12	TI 1773		- Low Voltage &#38; Low Power Stereo Audio DAC with Lineout Amplifier - Thanks Moe
U13
U14
U15
U16
U17
U18	ATMega8L	- Atmel ATmega8L Micro [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing <a href="http://www.codejedi.com/cgi-bin/blog.cgi/entertainment/gaming/pandora/20081127pandora_devkit_unboxing.blog" target="_blank">skeezix&#8217;s unboxing</a> of the pandora devkit, i decided to make a parts list of all visible ICs on the board.</p>
<pre>U1	8JA98/JWI92	- [Micron RAM Package] atop TI OMAP 3530 SoC
U2	TWL4030CI 	- <a href="http://focus.ti.com/general/docs/wtbu/wtbugencontent.tsp?DCMP=WTBU&amp;HQS=ProductBulletin+OT+twl4030&amp;contentId=4634&amp;templateId=6123">TI Audio &amp; Power Management Chip</a>
U3
U4
U5
U6
U7
U8
U9
U10
U11
U12	TI 1773		- <a href="http://focus.tij.co.jp/jp/lit/ug/sleu025/sleu025.pdf" target="_blank">Low Voltage &amp; Low Power Stereo Audio DAC with Lineout Amplifier</a> - Thanks Moe
U13
U14
U15
U16
U17
U18	ATMega8L	- <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf" target="_blank">Atmel ATmega8L Micro Controller</a>
U19	ALVC00		- <a href="http://download.siliconexpert.com/pdfs/logic_ics/txn/sces115d.pdf" target="_blank">Low Voltage 2 input NAND Gate</a>
U20	ALVC00		- <a href="http://download.siliconexpert.com/pdfs/logic_ics/txn/sces115d.pdf" target="_blank">Low Voltage 2 input NAND Gate</a>
U21	WE245		- <a href="http://focus.ti.com/lit/ds/symlink/sn74avc8t245.pdf" target="_blank">TI 8-BIT DUAL-SUPPLY BUS TRANSCEIVER</a>
U22	ATMega8L	- <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf" target="_blank">Atmel ATmega8L Micro Controller</a>
U23

Can't see U#
1x WG7210 		- <a href="http://cnc.rdeasy.cn/store/showcontent.asp?id=763" target="_blank">Wireless &amp; BT Module</a> including TI <a href="ftp://ftp.ti.com/pub/dml/tij/sr-WIguide_various/WTBU%20Solutions%20Guide_new/Pictures/WiLink.eps" target="_blank">WL1251</a>, <a href="http://focus.ti.com/pdfs/wtbu/wl1251_1253_prod_bulletin.pdf" target="_blank">WL1251FE</a> and WL1251PM
1x WY245		- <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=8&amp;url=http%3A%2F%2Ffocus.ti.com%2Flit%2Fds%2Fsymlink%2Fsn74avc32t245.pdf&amp;ei=odkvSeeZKp60QtKfnZ4L&amp;usg=AFQjCNHmh6-Z7HtuqK_ovst6e8ydqYyGAQ&amp;sig2=s7mbJ57hJXkdTmp0add-Xg" target="_blank">TI 32-BIT DUAL-SUPPLY BUS TRANSCEIVE</a></pre>
<p>The ATmega8 sat near the SD cards interests me, it&#8217;d be nice to get a code dump of it to see what it&#8217;s up to.</p>
<p>If you have any more information, can read any chip markings i can&#8217;t, have a pandora devkit and fancy taking some more high res shots for us all, or datasheet links for the above, please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=268</wfw:commentRss>
		</item>
		<item>
		<title>Track bot.</title>
		<link>http://thinkl33t.co.uk/?p=265</link>
		<comments>http://thinkl33t.co.uk/?p=265#comments</comments>
		<pubDate>Sun, 07 Sep 2008 19:34:19 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Robotics]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=265</guid>
		<description><![CDATA[While waiting for the last parts for r2 to arrive, I have been toying with building a bot based on&#8230; well&#8230; a toy!
I bought this remote control tank off ebay last year, and took off the plastic top.  Today I stripped off the other unnecessary bits of plastic, and mounted a breadboard on top.
Next part [...]]]></description>
			<content:encoded><![CDATA[<p>While waiting for the last parts for r2 to arrive, I have been toying with building a bot based on&#8230; well&#8230; a toy!</p>
<p>I bought this remote control tank off ebay last year, and took off the plastic top.  Today I stripped off the other unnecessary bits of plastic, and mounted a breadboard on top.</p>
<p>Next part of the plan is to either modify the existing drive board to allow direct drive from the microcontroller, or build a replacement based on a single-chip h-bridge device.</p>

<a href='http://thinkl33t.co.uk/?attachment_id=258' title='Inside view.'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010325-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=259' title='Inside from front.'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010327-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=260' title='Top view.'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010329-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=261' title='Bottom of chassis.'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010331-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=262' title='Tracks'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010332-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=263' title='Complete bot, as it stands'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010333-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
<a href='http://thinkl33t.co.uk/?attachment_id=264' title='Complete bot, pic 2'><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/09/p1010334-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>

]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=265</wfw:commentRss>
		</item>
		<item>
		<title>R2 Project Log - Motors</title>
		<link>http://thinkl33t.co.uk/?p=252</link>
		<comments>http://thinkl33t.co.uk/?p=252#comments</comments>
		<pubDate>Fri, 08 Aug 2008 22:09:00 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Micromouse]]></category>

		<category><![CDATA[R2]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[avr]]></category>

		<category><![CDATA[MicroMouse]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=252</guid>
		<description><![CDATA[After a minor slip up with a probe killed my primary R2 bot (shorted VBATT to 5VCC, bye bye processor and drive chips) I&#8217;ve tonight soldered up another of my spare R2 boards to take over the mantle.
And the motor drive code i was debugging at the time works!

 
Tomorrow, i add a battery monitor [...]]]></description>
			<content:encoded><![CDATA[<p>After a minor slip up with a probe killed my primary R2 bot (shorted VBATT to 5VCC, bye bye processor and drive chips) I&#8217;ve tonight soldered up another of my spare R2 boards to take over the mantle.</p>
<p>And the motor drive code i was debugging at the time works!</p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2008/08/p1010226.jpg"><img class="alignnone size-medium wp-image-253" title="R2 with motors attached." src="http://thinkl33t.co.uk/wp-content/uploads/2008/08/p1010226-300x190.jpg" alt="" width="300" height="190" /></a></p>
<p><!-- start insertion by YouTube Brackets, robertbuzink.nl --><span class="youtube"><object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/tNQfu4DB9lU"> <param name="movie" value="http://www.youtube.com/v/tNQfu4DB9lU" /><param name="wmode" value="transparent" /></object></span><!-- end Youtube Brackets insertion --></p>
<p>Tomorrow, i add a battery monitor circuit and the sensors, so i&#8217;ll finally have al the major electronic systems tested and good to go ready for the motor mounts.</p>

<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#define F_CPU 1000000UL</span>
<span style="color: #339933;">#include &lt; avr/io.h&gt;</span>
<span style="color: #339933;">#include &lt; util/delay.h&gt;</span>
<span style="color: #339933;">#include &lt; avr/interrupt.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &quot;r2.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Activate all the LEDs, set their pins to output</span>
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_L_DDR<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_R_DDR<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_L_DDR<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_R_DDR<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_FL_DDR<span style="color: #339933;">,</span> LED_YELLOW_FL_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_FR_DDR<span style="color: #339933;">,</span> LED_YELLOW_FR_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_RL_DDR<span style="color: #339933;">,</span> LED_YELLOW_RL_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_RR_DDR<span style="color: #339933;">,</span> LED_YELLOW_RR_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// Activate the motor's control lines</span>
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_R_ENABLE_DDR<span style="color: #339933;">,</span> MOTOR_R_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_R_PHASE_DDR<span style="color: #339933;">,</span> MOTOR_R_PHASE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_L_ENABLE_DDR<span style="color: #339933;">,</span> MOTOR_L_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_L_PHASE_DDR<span style="color: #339933;">,</span> MOTOR_L_PHASE_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// turn on the motors</span>
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_R_ENABLE_PORT<span style="color: #339933;">,</span> MOTOR_R_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_R_PHASE_PORT<span style="color: #339933;">,</span> MOTOR_R_PHASE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_L_ENABLE_PORT<span style="color: #339933;">,</span> MOTOR_L_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>MOTOR_L_PHASE_PORT<span style="color: #339933;">,</span> MOTOR_L_PHASE_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// turn on the white and red LEDs</span>
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_L_PORT<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_R_PORT<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_L_PORT<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_R_PORT<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// enable internal pullup on PD0</span>
	bit_set<span style="color: #009900;">&#40;</span>PORTD<span style="color: #339933;">,</span> BIT<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// enable external interrupts</span>
	EIMSK <span style="color: #339933;">=</span> BIT<span style="color: #009900;">&#40;</span>INT0<span style="color: #009900;">&#41;</span> | BIT<span style="color: #009900;">&#40;</span>INT1<span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// enable global interrupts</span>
	sei<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// loop forever</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		delayms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// delay for up to 65k milliseconds</span>
<span style="color: #993333;">void</span> delayms<span style="color: #009900;">&#40;</span>uint16_t millis<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// loop, delaying 1ms each iteration</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> millis <span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
		millis--;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this catches the Interrupt sent from pin INT0</span>
ISR<span style="color: #009900;">&#40;</span>INT0_vect<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Turn everything off</span>
	bit_clear<span style="color: #009900;">&#40;</span>LED_WHITE_L_PORT<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_WHITE_R_PORT<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_RED_L_PORT<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_RED_R_PORT<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	bit_clear<span style="color: #009900;">&#40;</span>MOTOR_R_ENABLE_PORT<span style="color: #339933;">,</span> MOTOR_R_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>MOTOR_R_PHASE_PORT<span style="color: #339933;">,</span> MOTOR_R_PHASE_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>MOTOR_L_ENABLE_PORT<span style="color: #339933;">,</span> MOTOR_L_ENABLE_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>MOTOR_L_PHASE_PORT<span style="color: #339933;">,</span> MOTOR_L_PHASE_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
&nbsp;
	<span style="color: #666666; font-style: italic;">// loop forever, flashing our indicators.</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_FL_PORT<span style="color: #339933;">,</span> LED_YELLOW_FL_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_FR_PORT<span style="color: #339933;">,</span> LED_YELLOW_FR_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_RL_PORT<span style="color: #339933;">,</span> LED_YELLOW_RL_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_RR_PORT<span style="color: #339933;">,</span> LED_YELLOW_RR_BIT<span style="color: #009900;">&#41;</span>;
		delayms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=252</wfw:commentRss>
		</item>
		<item>
		<title>AVR GCC Bit Manipulation Macros</title>
		<link>http://thinkl33t.co.uk/?p=248</link>
		<comments>http://thinkl33t.co.uk/?p=248#comments</comments>
		<pubDate>Sun, 27 Jul 2008 16:44:47 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Computing]]></category>

		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[atmega]]></category>

		<category><![CDATA[avr]]></category>

		<category><![CDATA[avrfreaks]]></category>

		<category><![CDATA[gcc]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=248</guid>
		<description><![CDATA[These are some macros i originally found on avrfreaks for bit manipulation.  I have posted them here in case they are useful to anyone.

#define bit_get(p,m) ((p) &#38; (m))
#define bit_set(p,m) ((p) &#124;= (m))
#define bit_clear(p,m) ((p) &#38;= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 &#60; &#60; (x))
#define LONGBIT(x) ((unsigned long)0x00000001 [...]]]></description>
			<content:encoded><![CDATA[<p>These are some macros i originally found on <a href="http://avrfreaks.net">avrfreaks</a> for bit manipulation.  I have posted them here in case they are useful to anyone.</p>

<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#define bit_get(p,m) ((p) &amp; (m))</span>
<span style="color: #339933;">#define bit_set(p,m) ((p) |= (m))</span>
<span style="color: #339933;">#define bit_clear(p,m) ((p) &amp;= ~(m))</span>
<span style="color: #339933;">#define bit_flip(p,m) ((p) ^= (m))</span>
<span style="color: #339933;">#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))</span>
<span style="color: #339933;">#define BIT(x) (0x01 &lt; &lt; (x))</span>
<span style="color: #339933;">#define LONGBIT(x) ((unsigned long)0x00000001 &lt;&lt; (x))</span></pre></div></div>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=248</wfw:commentRss>
		</item>
		<item>
		<title>R2 Project Log - External Interrupts</title>
		<link>http://thinkl33t.co.uk/?p=235</link>
		<comments>http://thinkl33t.co.uk/?p=235#comments</comments>
		<pubDate>Sun, 27 Jul 2008 16:10:47 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Micromouse]]></category>

		<category><![CDATA[R2]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[MicroMouse]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=235</guid>
		<description><![CDATA[I&#8217;ve done some playing, and worked out how to turn on the external interrupts on the atmega128 I am using for R2.
Code:

#define F_CPU 1000000UL
#include &#60; avr/io.h&#62;
#include &#60; util/delay.h&#62;
#include &#60; avr/interrupt.h&#62;
&#160;
#include &#34;r2.h&#34;
&#160;
int main&#40;void&#41; &#123;
	// Activate all the LEDs, set their pins to output
	bit_set&#40;LED_WHITE_L_DDR, LED_WHITE_L_BIT&#41;;
	bit_set&#40;LED_WHITE_R_DDR, LED_WHITE_R_BIT&#41;;
	bit_set&#40;LED_RED_L_DDR, LED_RED_L_BIT&#41;;
	bit_set&#40;LED_RED_R_DDR, LED_RED_R_BIT&#41;;
	bit_set&#40;LED_YELLOW_FL_DDR, LED_YELLOW_FL_BIT&#41;;
	bit_set&#40;LED_YELLOW_FR_DDR, LED_YELLOW_FR_BIT&#41;;
	bit_set&#40;LED_YELLOW_RL_DDR, LED_YELLOW_RL_BIT&#41;;
	bit_set&#40;LED_YELLOW_RR_DDR, LED_YELLOW_RR_BIT&#41;;
&#160;
	// enable internal pullup on PD0
	bit_set&#40;PORTD, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done some playing, and worked out how to turn on the external interrupts on the atmega128 I am using for R2.</p>
<p><strong>Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#define F_CPU 1000000UL</span>
<span style="color: #339933;">#include &lt; avr/io.h&gt;</span>
<span style="color: #339933;">#include &lt; util/delay.h&gt;</span>
<span style="color: #339933;">#include &lt; avr/interrupt.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &quot;r2.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Activate all the LEDs, set their pins to output</span>
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_L_DDR<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_R_DDR<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_L_DDR<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_R_DDR<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_FL_DDR<span style="color: #339933;">,</span> LED_YELLOW_FL_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_FR_DDR<span style="color: #339933;">,</span> LED_YELLOW_FR_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_RL_DDR<span style="color: #339933;">,</span> LED_YELLOW_RL_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_YELLOW_RR_DDR<span style="color: #339933;">,</span> LED_YELLOW_RR_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// enable internal pullup on PD0</span>
	bit_set<span style="color: #009900;">&#40;</span>PORTD<span style="color: #339933;">,</span> BIT<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// enable external interrupts</span>
	EIMSK <span style="color: #339933;">=</span> BIT<span style="color: #009900;">&#40;</span>INT0<span style="color: #009900;">&#41;</span> | BIT<span style="color: #009900;">&#40;</span>INT1<span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// enable global interrupts</span>
	sei<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// turn on the white and red LEDs</span>
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_L_PORT<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_WHITE_R_PORT<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_L_PORT<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_set<span style="color: #009900;">&#40;</span>LED_RED_R_PORT<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// loop forever</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		delayms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// delay for up to 65k milliseconds</span>
<span style="color: #993333;">void</span> delayms<span style="color: #009900;">&#40;</span>uint16_t millis<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// loop, delaying 1ms each iteration</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> millis <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
		millis--;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this catches the Interrupt sent from pin INT0</span>
ISR<span style="color: #009900;">&#40;</span>INT0_vect<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Turn everything off</span>
	bit_clear<span style="color: #009900;">&#40;</span>LED_WHITE_L_PORT<span style="color: #339933;">,</span> LED_WHITE_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_WHITE_R_PORT<span style="color: #339933;">,</span> LED_WHITE_R_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_RED_L_PORT<span style="color: #339933;">,</span> LED_RED_L_BIT<span style="color: #009900;">&#41;</span>;
	bit_clear<span style="color: #009900;">&#40;</span>LED_RED_R_PORT<span style="color: #339933;">,</span> LED_RED_R_BIT<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// loop forever, flashing our indicators.</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_FL_PORT<span style="color: #339933;">,</span> LED_YELLOW_FL_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_FR_PORT<span style="color: #339933;">,</span> LED_YELLOW_FR_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_RL_PORT<span style="color: #339933;">,</span> LED_YELLOW_RL_BIT<span style="color: #009900;">&#41;</span>;
		bit_flip<span style="color: #009900;">&#40;</span>LED_YELLOW_RR_PORT<span style="color: #339933;">,</span> LED_YELLOW_RR_BIT<span style="color: #009900;">&#41;</span>;
		delayms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Changing Trigger Mode:</strong></p>
<p>By default, the interrupt triggers when the pin is brought low.  If we want to change this behavior, we need to poke at the External Interrupt Control Registers, EICRA (for INT0 - INT3) and EICRB (for INT4 - INT7).</p>
<p>Each interrupt pin has 2 bits in the EICR Registers, ISCxO and ISCx1.  This Gives 4 possible options for triggering:</p>
<ul>
<li>0 0: Default, Trigger when INTx is held low</li>
<li>0 1: Not Used</li>
<li>1 0: Trigger when INTx changes from 1 to 0</li>
<li>1 1: Trigger when INTx changes from 0 to 1</li>
</ul>
<p>So, to turn on INT1, and set it to trigger on a rising edge, we,d use the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// enable external interrupt</span>
EIMSK <span style="color: #339933;">=</span> BIT<span style="color: #009900;">&#40;</span>INT0<span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//  set the interrupt to trigger on a rising edge</span>
EICRA |= BIT<span style="color: #009900;">&#40;</span>ISC00<span style="color: #009900;">&#41;</span> | BIT<span style="color: #009900;">&#40;</span>ISC01<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p><strong>Video:</strong></p>
<p><!-- start insertion by YouTube Brackets, robertbuzink.nl --><span class="youtube"><object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/pSuCHiK-Xq4"> <param name="movie" value="http://www.youtube.com/v/pSuCHiK-Xq4" /><param name="wmode" value="transparent" /></object></span><!-- end Youtube Brackets insertion --></p>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=235</wfw:commentRss>
		</item>
		<item>
		<title>R2 Project Log - Battery Monitor Circuit</title>
		<link>http://thinkl33t.co.uk/?p=215</link>
		<comments>http://thinkl33t.co.uk/?p=215#comments</comments>
		<pubDate>Sat, 26 Jul 2008 20:58:14 +0000</pubDate>
		<dc:creator>parag0n</dc:creator>
		
		<category><![CDATA[Electronics]]></category>

		<category><![CDATA[Micromouse]]></category>

		<category><![CDATA[R2]]></category>

		<category><![CDATA[Robotics]]></category>

		<category><![CDATA[MicroMouse]]></category>

		<guid isPermaLink="false">http://thinkl33t.co.uk/?p=215</guid>
		<description><![CDATA[After playing with R2&#8217;s circuit, I realized I had left no ADC ports for monitoring my battery!  As it is a LiPo battery, it needs a low-voltage cutoff at 6v, or it will not be chargeable again.  I built a simple circuit with an attiny13 and a potential divider, which will trigger an interrupt on [...]]]></description>
			<content:encoded><![CDATA[<p>After playing with R2&#8217;s circuit, I realized I had left no ADC ports for monitoring my battery!  As it is a LiPo battery, it needs a low-voltage cutoff at 6v, or it will not be chargeable again.  I built a simple circuit with an attiny13 and a potential divider, which will trigger an interrupt on my main processor when the battery voltage gets to 6.2v.</p>
<p><strong>Circuit Diagram:</strong></p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2008/07/schem.png"><img src="http://thinkl33t.co.uk/wp-content/uploads/2008/07/schem.png" alt="R2\&#039;s Cutoff Schematic" title="Schematic" width="346" height="189" class="size-full wp-image-219" /></a></p>
<p><strong>Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#define F_CPU 10000000UL</span>
<span style="color: #339933;">#include &lt;avr /io.h&gt;</span>
<span style="color: #339933;">#include &lt;util /delay.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// delay for up to 65k milliseconds</span>
<span style="color: #993333;">void</span> delayms<span style="color: #009900;">&#40;</span>uint16_t millis<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// loop, delaying 1ms each iteration</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> millis <span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;
		millis--;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// initialise the adc</span>
<span style="color: #993333;">void</span> init_adc <span style="color: #009900;">&#40;</span> <span style="color: #993333;">void</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//select external (VCC) voltage as the reference voltage (x0xx xxxx) </span>
	ADMUX <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span>;
	<span style="color: #666666; font-style: italic;">//enable ADC (1000 0000)</span>
	ADCSRA |= <span style="color: #208080;">0x80</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// read the specified adc</span>
<span style="color: #993333;">int</span> adc_read <span style="color: #009900;">&#40;</span> uint8_t n <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// set the adc to the chosen channel</span>
	ADMUX <span style="color: #339933;">=</span> n;
	<span style="color: #666666; font-style: italic;">// start the ADC conversion, set the ADC clock to cpu clock / 16 (0100 0100)</span>
	ADCSRA |= <span style="color: #208080;">0x44</span>;
	<span style="color: #666666; font-style: italic;">// wait for the adc conversion to be completed</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ADCSRA <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x40</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>;
	<span style="color: #666666; font-style: italic;">// return the adc result</span>
	<span style="color: #b1b100;">return</span> ADC;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// set PB0 to output</span>
	DDRB |= <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>PB3;
	<span style="color: #666666; font-style: italic;">// turn on the ADC</span>
	init_adc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// set up our variables</span>
	<span style="color: #993333;">int</span> reading <span style="color: #339933;">=</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> prev <span style="color: #339933;">=</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> temp <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
	<span style="color: #666666; font-style: italic;">// loop for ever</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// take a new adc reading</span>
		reading <span style="color: #339933;">=</span> adc_read<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #666666; font-style: italic;">// average it with the previous reading</span>
		temp <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>reading <span style="color: #339933;">+</span> prev<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span>;		
		<span style="color: #666666; font-style: italic;">// if the voltage is less than 6</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> temp <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">185</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// turn the output pin on</span>
			PORTB <span style="color: #339933;">&amp;=</span> ~<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>PB3<span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// turn the output pin off</span>
			PORTB |= <span style="color: #0000dd;">1</span><span style="color: #339933;">&lt;&lt;</span>PB3; <span style="color: #808080; font-style: italic;">/* LED off */</span>
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #666666; font-style: italic;">// save the current reading</span>
		prev <span style="color: #339933;">=</span> reading;
		<span style="color: #666666; font-style: italic;">// wait for 20ms</span>
		delayms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Photos:</strong></p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2008/07/p1010212.jpg"><img class="alignnone size-medium wp-image-221" title="Battery Cutout" src="http://thinkl33t.co.uk/wp-content/uploads/2008/07/p1010212-300x232.jpg" alt="" width="300" height="232" /></a></p>
<p><a href="http://thinkl33t.co.uk/wp-content/uploads/2008/07/p1010213.jpg"><img class="alignnone size-medium wp-image-222" title="Battery Cutout" src="http://thinkl33t.co.uk/wp-content/uploads/2008/07/p1010213-300x225.jpg" alt="" width="300" height="225" /></a></util></avr></pre>
]]></content:encoded>
			<wfw:commentRss>http://thinkl33t.co.uk/?feed=rss2&amp;p=215</wfw:commentRss>
		</item>
	</channel>
</rss>
