<?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>disputedip.com</title>
	<atom:link href="http://www.disputedip.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.disputedip.com</link>
	<description>this one i like, it squeks</description>
	<lastBuildDate>Sun, 22 Apr 2012 08:28:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Opps, another year of excuses&#8230;</title>
		<link>http://www.disputedip.com/272/opps-another-year-of-excuses/</link>
		<comments>http://www.disputedip.com/272/opps-another-year-of-excuses/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 08:28:49 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Robots]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=272</guid>
		<description><![CDATA[Right then, I am going to try and do this properly this time. I just got back from another brilliant MINOS conference at Royal Holloway University London (http://www.micromouseonline.com is the main contact point), I presented my latest work on rapid prototyped parts for my mouse, a bit more on that a bit later! Plenty learnt [...]]]></description>
			<content:encoded><![CDATA[<p>Right then, I am going to try and do this properly this time.</p>
<p>I just got back from another brilliant MINOS conference at Royal Holloway University London (<a href="http://www.micromouseonline.com">http://www.micromouseonline.com</a> is the main contact point), I presented my latest work on rapid prototyped parts for my mouse, a bit more on that a bit later!</p>
<p>Plenty learnt and much to do &#8211; so hopefully I will do it this year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/272/opps-another-year-of-excuses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Questions!</title>
		<link>http://www.disputedip.com/262/questions/</link>
		<comments>http://www.disputedip.com/262/questions/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 08:23:45 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[voltage regulator]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=262</guid>
		<description><![CDATA[Wow &#8211; its only been a couple of days since I posted the schematic and already a question. Basically its asking what voltage regulators am I using. My input power comes from a 7.4V pack of lipo batteries, usually about 300mAh capacity, I need 5V for my motor encoders, and 3.3V for the rest of [...]]]></description>
			<content:encoded><![CDATA[<p>Wow &#8211; its only been a couple of days since I posted the schematic and already a question. Basically its asking what voltage regulators am I using.</p>
<p>My input power comes from a 7.4V pack of lipo batteries, usually about 300mAh capacity, I need 5V for my motor encoders, and 3.3V for the rest of the circuit.</p>
<p>The current load is fairly high, it bursts up towards 1A when the sensors are going (roughly 1/10 duty something is on). So fairly high current requirements.  I also need something with a reasonable dropout , as I can run the batteries down to 6V &#8211; so a 1V dropout for the 5V line.</p>
<p>Putting my &#8216;It would be nice to get something for free&#8217; hat on I turned to samples! I use TI for most of my sampling needs, and the REG104 series looked pretty good. Cheap linear low drop out regulators that can take some throwing around and come in fairly accessible packages.</p>
<p>http://focus.ti.com/docs/prod/folders/print/reg104-a.html</p>
<p>They don&#8217;t get too hot when running, and only require a few external parts. So meet all my requirements, so much so I always have a pile of then on standby for random project usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/262/questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Micromouse Sensors &#8211; Lasers?</title>
		<link>http://www.disputedip.com/265/micromouse-sensors-lasers/</link>
		<comments>http://www.disputedip.com/265/micromouse-sensors-lasers/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 16:06:28 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[distance]]></category>
		<category><![CDATA[laser]]></category>
		<category><![CDATA[micromouse sensors]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[sensor]]></category>
		<category><![CDATA[tsl250]]></category>
		<category><![CDATA[wall sensor]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=265</guid>
		<description><![CDATA[One of the biggest problems I have had when developing my micromouse robots is creating sensors which work over the range of distances required and to a reasonable resolution. I have seen a couple of mice using red lasers so thought I would have a go. I got a pile of 20mm long, about 5mm [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest problems I have had when developing my micromouse robots is creating sensors which work over the range of distances required and to a reasonable resolution. I have seen a couple of mice using red lasers so thought I would have a go.</p>
<p>I got a pile of 20mm long, about 5mm diameter red lasers from a random seller on ebay and plugged it into a microcontroller development board with a few additions; a potentiometer to adjust intensity and a red colour sensor (TSL250R). The colour sensor is a pretty basic affair &#8211; very similar to the IR photodiodes, just sensitive to visible red light. You can get this device in 3 different sensitivities, I got all three but only tried the highest sensitivity one.</p>
<p><a href="http://www.disputedip.com/wp-content/plugins/mainimage_medium.jpg" rel="lightbox[265]"><img class="aligncenter size-medium wp-image-267" title="Lasers" src="http://www.disputedip.com/wp-content/plugins/mainimage_medium-300x225.jpg" alt="Laser Sensor Prototype" width="300" height="225" /></a></p>
<p>Now the main motivation to use a laser is that the beam does not expand much over distance, so instead of having some messy interplay between the cone a normal LED creates and the reflected intensity of light, there is just reflected intensity. The dot it creates does change size over distance, so its about 2mm diameter at 10mm from the lens and maybe 4mm at 100mm. But it works! I got a few volts difference on the receiver output over a 160mm range.</p>
<p>BUT there is a problem, not a huge one mind; Under normal circumstances when an LED sensor is looking perpendicuar at a wall the receiver is nearly always covered in the reflected light. Problem with the small focused dot is that is does not form a cone which covers the sensor. Due to the configuration shown in the photo above you can see the reflected dot on the receiver, this saturates the sensor and makes the readings nearly useless. This is overcome by mounting the receiver vertical to the laser, but a wobbly wall or ultra reflective walls could still potentially cause a lot of problems.</p>
<p>The other problem is the lasers&#8217; size &#8211; they are huge and fairly heavy. I am sure there are smaller ones somewhere, I&#8217;ve just not found them anywhere. But watch this space!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/265/micromouse-sensors-lasers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Schematic Time!</title>
		<link>http://www.disputedip.com/251/schematic-time/</link>
		<comments>http://www.disputedip.com/251/schematic-time/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 03:00:47 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[circuit diagram]]></category>
		<category><![CDATA[infrared]]></category>
		<category><![CDATA[schematic]]></category>
		<category><![CDATA[sensors]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=251</guid>
		<description><![CDATA[Right then, a micromouse schematic. A word of warning &#8211; this schematic is for me and not for you. That means its not pretty, values are missing and circuit notes are missing. So important parts to mention are that the Bluetooth module was from sparkfun.com and is not currently available (although there are many similar [...]]]></description>
			<content:encoded><![CDATA[<p>Right then, a micromouse schematic. A word of warning &#8211; this schematic is for me and not for you. That means its not pretty, values are missing and circuit notes are missing.</p>
<p><img class="aligncenter size-full wp-image-258" title="Micromouse Circuit Schematic" src="http://www.disputedip.com/wp-content/plugins/sche1.jpg" alt="" width="600" height="450" /></p>
<p>So important parts to mention are that the Bluetooth module was from sparkfun.com and is not currently available (although there are many similar alternatives, and the schematic / pcb footprints are avaliable from opencircuits.com). The crystal value is set to some random value (around 4.2Mhz), it allows me to run at a really random clock speed (73Mhz after PLL), but gets me perfect for 921600 baud uart &#8211; which how fast I run the bluetooth module. I run both PIC&#8217;s at that speed so the intercon can be easily set up to the same speed &#8211; any arbitary setting value will work. By the way I the net I named as spi on the schematic nets are just &#8216;interconnects&#8217; as they are on the retargetable pins.</p>
<p>Here is the pdf, you might want to use the rotate functions &#8211; or adopt a weird pose&#8230;</p>
<p><a href="http://www.disputedip.com/wp-content/plugins/micromouse-processor-board.pdf"></a><a href="http://www.disputedip.com/wp-content/plugins/micromouse-processor-board.pdf">Public Release Jan 2011 &#8211; Micromouse Schematic</a></p>
<p>Questions in the comments area!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/251/schematic-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mouse Problems</title>
		<link>http://www.disputedip.com/249/mouse-problems/</link>
		<comments>http://www.disputedip.com/249/mouse-problems/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 03:00:54 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[Robots]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=249</guid>
		<description><![CDATA[The mouse I have been working on up until now has been quite a complicated design as it was the technical part of my MEng Cybernetics degree. So now that&#8217;s all over its time to make things a bit simpler and aim a little lower &#8211; this is after all a hobby and I can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>The mouse I have been working on up until now has been quite a complicated design as it was the technical part of my MEng Cybernetics degree. So now that&#8217;s all over its time to make things a bit simpler and aim a little lower &#8211; this is after all a hobby and I can&#8217;t devote all my time to it as I once did.</p>
<p>So new electronics time I think, I am going to keep the chassis and just work on my ESD and layout. I think I will keep with the two processor design as I have a couple of DSP related things I want to try with the sensors and it requires quite a lot of processor grunt to get that going. The drive electronics will stay the same, no switched mode power supplies this time, and only sensors on the front. Oh and I will keep the bluetooth &#8211; why not!</p>
<p>I need to design new skids as the current ones require the lower sensor pcb of the old design, so its back to Solidworks and another order to shapeways for parts. And finally &#8211; need to find some nice batteries; the ones I am using are too big and a little under capacity.</p>
<p>Back soon with schematic&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/249/mouse-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Well 2010 just ended!</title>
		<link>http://www.disputedip.com/247/well-2010-just-ended/</link>
		<comments>http://www.disputedip.com/247/well-2010-just-ended/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 20:56:14 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=247</guid>
		<description><![CDATA[Not too surprising but I managed to nearly ignore my micromouse obligations for a whole year. Then again I graduated, have a job, moved house a couple of times and am only now able to say I&#8217;m settled! So, new years resolution is to get this mouse going again, I have new designs that I [...]]]></description>
			<content:encoded><![CDATA[<p>Not too surprising but I managed to nearly ignore my micromouse obligations for a whole year. Then again I graduated, have a job, moved house a couple of times and am only now able to say I&#8217;m settled!</p>
<p>So, new years resolution is to get this mouse going again, I have new designs that I have been working on and have reworked the old mouse to be less of a final year undergrad masters project and more of a weekend hobby. More to come (And a site new logo has been commissioned, watch this space).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/247/well-2010-just-ended/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A first corner &#8211; ahhh</title>
		<link>http://www.disputedip.com/239/a-first-corner-ahhh/</link>
		<comments>http://www.disputedip.com/239/a-first-corner-ahhh/#comments</comments>
		<pubDate>Fri, 15 May 2009 21:32:13 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=239</guid>
		<description><![CDATA[Well it made its first corner, video: Go to http://www.youtube.com/watch?v=5a4zVuxzEdg for the HD version. And here is the data from that run: The todo list is as follows: Retune controller (there is some nasty overshoot and the control signal itself is oscillating) Calibrate the speeds &#8211; left and right wheel have different speeds (:() so [...]]]></description>
			<content:encoded><![CDATA[<p>Well it made its first corner, video:</p>
<p><a href="http://www.disputedip.com/239/a-first-corner-ahhh/"><em>Click here to view the embedded video.</em></a></p>
<p>Go to <a title="HD Version" href="http://www.youtube.com/watch?v=5a4zVuxzEdg">http://www.youtube.com/watch?v=5a4zVuxzEdg</a> for the HD version.</p>
<p>And here is the data from that run:</p>
<p><a rel="lightbox" href="http://www.disputedip.com/wp-content/uploads/2009/05/graphy.jpg"><img class="aligncenter size-medium wp-image-240" title="Turn Graph" src="http://www.disputedip.com/wp-content/uploads/2009/05/graphy-300x219.jpg" alt="Turn Graph" width="300" height="219" /></a></p>
<p>The todo list is as follows:</p>
<ul>
<li>Retune controller (there is some nasty overshoot and the control signal itself is oscillating)</li>
<li>Calibrate the speeds &#8211; left and right wheel have different speeds (:() so need to go an work out the difference</li>
<li>Automate this, cause it took all day to get to this point</li>
</ul>
<p>Please note that this is a &#8216;jigged&#8217; callibration &#8211; the long straight allows me to guestimate the required speed differences and ticks per meter, so not too precise at this point in time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/239/a-first-corner-ahhh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Micromouse Update</title>
		<link>http://www.disputedip.com/229/micromouse-update/</link>
		<comments>http://www.disputedip.com/229/micromouse-update/#comments</comments>
		<pubDate>Sun, 10 May 2009 17:18:36 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=229</guid>
		<description><![CDATA[As its exam time I have been carefully avoiding revision with a mix of counterstrike and micromouse work. New PCBs are 95% ready to be ordered and so my focus has turned to the controllers. After implementing a fixed point maths system for the controller (10.5bits signed for those who care) and ziegler-nichols tuning the [...]]]></description>
			<content:encoded><![CDATA[<p>As its exam time I have been carefully avoiding revision with a mix of counterstrike and micromouse work. New PCBs are 95% ready to be ordered and so my focus has turned to the controllers.</p>
<p>After implementing a fixed point maths system for the controller (10.5bits signed for those who care) and ziegler-nichols tuning the PI controller I had a one wheel mouse &#8211; putting a bit more effort in I got it to two wheels &#8211; yay.</p>
<p>Tuning it was a bit of a chore &#8211; so automation is king and I was able to produce this graph (yes, no axis labels, minus 2 marks for me, x is the time, y (going back into the scene) is as the gain increases and z (going up) is the velocity for said gain:</p>
<p><a rel="lightbox" href="http://www.disputedip.com/wp-content/uploads/2009/05/unfitered.jpg"><img class="aligncenter size-medium wp-image-232" title="Unfiltered Results" src="http://www.disputedip.com/wp-content/uploads/2009/05/unfitered-300x224.jpg" alt="Unfiltered Results" width="300" height="224" /></a></p>
<p>The idea is to find the point where oscillations occur, the above plot was far too noisy so a 16 point moving average was applied:</p>
<p><a rel="lightbox" href="http://www.disputedip.com/wp-content/uploads/2009/05/filtered.jpg"><img class="aligncenter size-medium wp-image-230" title="Readable results" src="http://www.disputedip.com/wp-content/uploads/2009/05/filtered-300x224.jpg" alt="Readable results" width="300" height="224" /></a></p>
<p>I got a value of about 1.2, but it is questionable, will compare against some simulated controllers to see if it seems a likely value &#8211; it does however work well enough to control the motors!</p>
<p>Now the results:</p>
<p><a rel="lightbox" href="http://www.disputedip.com/wp-content/uploads/2009/05/graph.jpg"><img class="aligncenter size-medium wp-image-233" title="Data output" src="http://www.disputedip.com/wp-content/uploads/2009/05/graph-300x166.jpg" alt="Data output" width="300" height="166" /></a></p>
<p>It is nice having onboard bluetooth for this sort of debugging, anyhow, things look nice &#8211; the integral term does push things out of whack when going from zero or getting down to zero &#8211; but possibly an artefact of the controller being ill tuned &#8211; there is still a large overshoot to a step input which is not what you would expect from a z-n tuned controller&#8230;</p>
<p>Video, go to <a title="Youtube video" href="http://www.youtube.com/watch?v=AYmkJvthVJw" target="_self">http://www.youtube.com/watch?v=AYmkJvthVJw</a> and click on view in HD at the bottom! or watch it in small size bellow:</p>
<p><a href="http://www.disputedip.com/229/micromouse-update/"><em>Click here to view the embedded video.</em></a></p>
<p>Next time it will be slower and have a straight line controller built in, after that its onto cornering!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/229/micromouse-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Mouse Movements</title>
		<link>http://www.disputedip.com/226/first-mouse-movements/</link>
		<comments>http://www.disputedip.com/226/first-mouse-movements/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 22:43:40 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=226</guid>
		<description><![CDATA[Very bad video quality &#8211; but the mouse moves: Will get a better camera in on Monday, but yay it moves. This is a very basic movement &#8211; accelerate to ~20% maximum speed, stay there and start to decelerate after 1s. It moved very roughly, 0.5m in 1sec, making its theoretical (ish) top speed about [...]]]></description>
			<content:encoded><![CDATA[<p>Very bad video quality &#8211; but the mouse moves:</p>
<p><a href="http://www.disputedip.com/226/first-mouse-movements/"><em>Click here to view the embedded video.</em></a></p>
<p>Will get a better camera in on Monday, but yay it moves. This is a very basic movement &#8211; accelerate to ~20% maximum speed, stay there and start to decelerate after 1s.</p>
<p>It moved very roughly, 0.5m in 1sec, making its theoretical (ish) top speed about 2.5m/s (when loaded). Although that metric does not take into account anything, so could be higher or lower :p.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/226/first-mouse-movements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buttons &#8211; and LEDs :D</title>
		<link>http://www.disputedip.com/211/buttons-and-leds-d/</link>
		<comments>http://www.disputedip.com/211/buttons-and-leds-d/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 16:45:02 +0000</pubDate>
		<dc:creator>Martyn</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Micromouse]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Robots]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[dspic]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://www.disputedip.com/?p=211</guid>
		<description><![CDATA[Buttons are cool, so are menu&#8217;s. So with the help of a button, a few leds and a dspic I have a menu system (also note that this is blocking, the idea is that its used to start / stop the robot, so the robot does not move while the menu is active), first lets [...]]]></description>
			<content:encoded><![CDATA[<p>Buttons are cool, so are menu&#8217;s. So with the help of a button, a few leds and a dspic I have a menu system (also note that this is blocking, the idea is that its used to start / stop the robot, so the robot does not move while the menu is active), first lets look at the switch circuit and then at the dspic set up (c30 compiler, using a dspic33fj128gp804):</p>
<div id="attachment_218" class="wp-caption aligncenter" style="width: 342px"><a href="http://www.disputedip.com/wp-content/uploads/2009/04/sw.jpg" rel="lightbox[211]"><img src="http://www.disputedip.com/wp-content/uploads/2009/04/sw.jpg" alt="Schematic for a switch for a dspic" title="Switch Schematic" width="332" height="281" class="size-full wp-image-218" /></a><p class="wp-caption-text">Schematic for a switch for a dspic</p></div>
<pre name="code" class="c:html:nocontrols">
/* Setup the IO Pin Assignment */
__builtin_write_OSCCONL(OSCCON &#038; ~(1<<6));

	RPINR7bits.IC1R = 5;	// Switch Input Capture

__builtin_write_OSCCONL(OSCCON | (1<<6));

/* Switch Input Capture Setup */
IC1CONbits.ICM = 0x02;	// Capture on falling edge
_IC1IF = 0;
_IC1IE = 1;

/* CPU Time Clock */
T1CONbits.TCKPS = 0x02;	// 40.5504Mhz / 64
TMR1 = 0x00;
PR1 = 634*4;			// Int at 1.000631313ms*4
_T1IF = 0;
_T1IE = 1;
T1CONbits.TON = 1;
</pre>
<p>The code is fairly simple: first attach the switch input to the input capture (ic1) peripheral, set up ic1 to trigger an interrupt on the falling edge and then there is the set up for my main timer loop, this occurs at ~250Hz, and yes I am using a weird value crystal.</p>
<p>Next lets look at the global variables (well global to the scope of the interrupts)</p>
<pre name="code" class="c:html:nocontrols">

// Switch input vars
int sw_counter = 0;
int sw_on = 0;

// Menu vars
int menu_counter = 0;
int menu_on = 0;
int menu_value = 0;
</pre>
<p>Next the interrupt for the input capture routine</p>
<pre name="code" class="c:html:nocontrols">void __attribute__((__interrupt__)) _NOPSV _IC1Interrupt(void)
{
	_IC1IF = 0; 		// Clear the interrupt
	_IC1IE = 0;			// Disable the interrupt
	_RED = 1;   		// Show the user the button pressed
	sw_on = 1; 		// Enable the debounce counter

	// If the menu is on already, increment the menu value
	// Otherwise turn the menu on and set the menu value to
	//default
	if (menu_on)
	{
		menu_val ++;
		menu_counter = 0;
	}
	else
	{
		menu_on = 1;
		menu_val = 0;
	}
}
</pre>
<p>And then the interrupt for the timer:</p>
<pre name="code" class="c:html:nocontrols">void __attribute__((__interrupt__)) _NOPSV _T1Interrupt(void)
{
	// Handle switch
	if (sw_on)				// If a switch 'event' is ongoing
	{
		sw_counter ++;
		if (sw_counter > 50)  	// 50x 1/250 = 200ms debounce
		{
			sw_on = 0;		// Switch no longer on
			sw_counter = 0;	// Counter to zero
			_IC1IF = 0;		// Clear the bounces
			_IC1IE = 1;		// Enable more switches
			_RED = 0;		// Led off
		}
	}

	// Menu
	if (menu_on)			// If menu is on
	{
		menu_counter ++;	// Increment counter

		// Leave menu active for 1s after last click
		if (menu_counter > 250)
		{
			menu_on = 0;	// Menu off
			menu_counter = 0; // Reset

			// Menu complete - do stuff
			switch (menu_val)
			{
				case 0:
					_RED = 0;
					Nop();	// Required if RED and GREEN
							// On same port
					_GREEN = 1;
					break;
				case 1:
					_RED = 1;
					Nop();	// Required if RED and GREEN
							// On same port
					_GREEN = 0;
					break;
				default:
					break;
			}
		}
	}
}
</pre>
<p>And thats it, google _NOPSV to find the macro for that (sometimes required to compile using c30). Also _RED and _GREEN are port bits, so something like #define _RED _RB1 to make _RED = 1 turn Port B pin 1 on. All quite useful, maybe...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.disputedip.com/211/buttons-and-leds-d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

