<?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>Keith&#039;s Electronics Blog &#187; Ideas</title>
	<atom:link href="http://www.neufeld.newton.ks.us/electronics/?cat=15&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.neufeld.newton.ks.us/electronics</link>
	<description></description>
	<lastBuildDate>Fri, 18 Apr 2025 00:10:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Thomas Jefferson on Open-Source</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=1193</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=1193#comments</comments>
		<pubDate>Wed, 08 Dec 2010 18:02:31 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=1193</guid>
		<description><![CDATA[Why have I never before seen this quote, cited (as I find on Google) by a wide variety of highly reputed maker-friendly organizations? He who receives an idea from me, receives instruction himself without lessening mine; as he who lights his taper at mine, receives light without darkening me. Found in an interview with Sanjoy [...]]]></description>
			<content:encoded><![CDATA[<p>Why have I never before seen this quote, cited (as I find on Google) by a wide variety of highly reputed maker-friendly organizations?</p>
<blockquote><p>He who receives an idea from me, receives instruction himself without lessening mine; as he who lights his taper at mine, receives light without darkening me.</p></blockquote>
<p>Found in an <a href="http://freakonomics.blogs.nytimes.com/2010/07/16/surely-you-must-be-joking-mr-mahajan-the-street-fighting-mathematician-answers-your-questions/">interview with Sanjoy Mahajan</a>, author of <a href="http://www.amazon.com/Street-Fighting-Mathematics-Educated-Guessing-Opportunistic/dp/026251429X/">Street-Fighting Mathematics: The Art of Educated Guessing and Opportunistic Problem Solving</a>, on the <a href="http://freakonomics.blogs.nytimes.com/">Freakonomics blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=1193</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MIDI Looper?</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=1085</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=1085#comments</comments>
		<pubDate>Mon, 31 May 2010 23:42:08 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Equipment]]></category>
		<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=1085</guid>
		<description><![CDATA[I&#8217;m starting to think I&#8217;d like a MIDI sequencer that behaves somewhat like a looper, doing the following: Capture a short sample of a MIDI performance, including key velocity data. Quantize to a tempo set by a &#8220;tap tempo&#8221; pedal continually and dynamically throughout the capture, rather than to an LED or click track. Loop [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to think I&#8217;d like a MIDI sequencer that behaves somewhat like a looper, doing the following:</p>
<ul>
<li>Capture a short sample of a MIDI performance, including key velocity data.</li>
<li>Quantize to a tempo set by a &#8220;tap tempo&#8221; pedal continually and dynamically throughout the capture, rather than to an LED or click track.</li>
<li>Loop and play back, by default to the last tempo seen but honoring continuous &#8220;tap tempo&#8221; data from the same pedal.</li>
</ul>
<p>Using a MIDI sequencer with these &#8220;tap tempo&#8221; features should give greater flexibility for capture and playback during a live ensemble performance than using a traditional audio looper, which requires the whole ensemble to play to the tempo recorded in the loop.</p>
<p>But my real motivation is to be able to play a pattern and then make gradual, multi-bar changes to the analog character of the sound without having to continue playing with one hand and turn knobs with the other.</p>
<p>Record a one-bar pattern on a MIDI keyboard driving a x0xb0x (or a real TB-303, if you&#8217;re filthy rich enough to have one and a DIN-sync MIDI adapter to go with it), then play it back and slowly tweak the knobs while everyone else jams on for a bit.</p>
<p>Am I going to find that all of this functionality already exists within the x0xb0x?  (It looks like it might be close &#8212; MIDI ports; internal sequencer; variable tempo, although perhaps not that sophisticated.)  Alternatively, are there MIDI sequencers that do all of this?  Is this de rigeuer for every sequencer under the sun?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=1085</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>(Mostly) Assembling My CupCake Motherboard</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=562</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=562#comments</comments>
		<pubDate>Mon, 25 May 2009 20:58:21 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[CNC]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[LED Clock]]></category>
		<category><![CDATA[MakerBot CupCake]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=562</guid>
		<description><![CDATA[The MakerBot CupCake&#8216;s motherboard (RepRap generation 3 motherboard) is Arduino-compatible, connects to all the other boards in the CupCake / RepRap, and has lots of spare connectors to boot. Ah, spare connectors to prototype, I mean; the spare connectors aren&#8217;t needed in order to get the board to boot. Ha ha. I got mine mostly [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://wiki.makerbot.com/cupcake">MakerBot CupCake</a>&#8216;s <a href="http://www.reprap.org/bin/view/Main/Motherboard_1_1">motherboard</a> (RepRap generation 3 motherboard) is Arduino-compatible, connects to all the other boards in the CupCake / RepRap, and has lots of spare connectors to boot.</p>
<p>Ah, spare connectors to prototype, I mean; the spare connectors aren&#8217;t needed in order to get the board to boot.  Ha ha.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/05/23/DSCN3991.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/05/23/DSCN3991_mid.jpg" alt="Mostly-assembled CupCake motherboard" /></a></p>
<p>I got mine mostly assembled last week.  Like every other piece of electronics in my CupCake kit, my motherboard had missing parts &#8212; I got five extra 4.7K&Omega; resistors instead of the five 1.8K&Omega; resistors.  And unfortunately, that was another part for which I couldn&#8217;t find replacements at hand &#8212; although I did end up sorting and filing a bunch more SMT components while searching.</p>
<p>After waiting a week for the missing resistors as the solder paste was drying out and getting crusty, I gave up and baked the thing without them.  I can hand-solder the 1.8K&Omega; resistors onto the board when they arrive.  And because they&#8217;re voltage dividers for 5V &rarr; 3.3V level conversion to the mini-SD card and pull-ups for the I<sup>2</sup>C bus &#8212; neither of which is needed for basic operation &#8212; I can even run the darn thing without them.  I just need to get them on there eventually.</p>
<p>Crusty solder paste bakes just as nicely as gooey solder paste, by the way.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/05/17/DSCN3941.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/05/17/DSCN3941_mid.jpg" alt="Unlabelled R1 on MakerBot Cupcake motherboard" /></a></p>
<p>I did spend a while searching for the placement of R1 on the PC board.  I eventually found it through a combination of the process of elimination and checking the schematic.  As far as I can tell, the name label didn&#8217;t make it anywhere onto the silkscreen &#8212; can you spot it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=562</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Storage Storage for Samples Storage</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=448</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=448#comments</comments>
		<pubDate>Mon, 09 Feb 2009 17:44:29 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Salvage]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=448</guid>
		<description><![CDATA[In the past, I&#8217;ve tried several techniques for organizing my small quantities of IC samples (and &#8220;purchased samples&#8221;). I have enough different ones and each needs so little space individually that I don&#8217;t really want to dedicate parts bins to them. I&#8217;ve tried putting them in pockets in a three-ring binder, leaving them in the [...]]]></description>
			<content:encoded><![CDATA[<p>In the past, I&#8217;ve tried several techniques for organizing my small quantities of IC samples (and &#8220;purchased samples&#8221;).  I have enough different ones and each needs so little space individually that I don&#8217;t really want to dedicate parts bins to them.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2797.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2797_mid.jpg" alt="IC samples in different containers" /></a></p>
<p>I&#8217;ve tried putting them in pockets in a three-ring binder, leaving them in the open shipping carton, and leaving them lying around on my workbench in their packages.</p>
<p>None of these have worked particularly well for me.</p>
<h4>Mainframe Backup Tapes</h4>
<p>At work, we have a large collection of &#8220;3490&#8243; mainframe backup tapes, and they&#8217;re kept in large racks without the plastic cases the tapes ship in.  In the IT environment, large sets of disks and tapes are referred to as &#8220;storage;&#8221; so the empty plastic cases and the racks the tapes go in are &#8220;storage storage,&#8221; right?</p>
<p>We had a few empty tape cases left, which were of no use to us and which I took home.  We&#8217;ve also retired our mainframe and pruned our backup collection, so we have a number of empty racks and rack cases sitting around.  It looked like an opportunity to salvage discarded materials and improve my electronic parts storage.</p>
<h4>Tape Packages for Electronics Parts</h4>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2810.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2810_mid.jpg" alt="Stacked tape cases with ICs" /></a></p>
<p>Last night I put most of my samples into empty tape cases, and it worked quite well.  At Wal-Mart I found some Avery labels that are compatible with #5366 (2/3&#8243; x 3&nbsp;7/16&#8243;, called &#8220;File Folder &#8212; White&#8221;), are ultra-opaque, are supported by the label feature in OpenOffice, and fit nicely onto the approximately 1&#8243; x 4.25&#8243; case spines.</p>
<h4>Racks (Or Not)</h4>
<p>The cases have ridged edges and stack very nicely, but I was hoping to get them into a rack for easy &#8220;random access&#8221; to individual boxes.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2803.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2803_mid.jpg" alt="Data tape case doesn't fit into tape storage rack" /></a></p>
<p>Unfortunately &lt;grunt&gt;, the racks &lt;grunt shove&gt; weren&#8217;t made to hold the cases &lt;curse shove&gt;, just the tapes &lt;growl&gt;, and the cases don&#8217;t fit &lt;sigh resignation&gt;.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2815.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2009/02/08/DSCN2815_mid.jpg" alt="Boxed tape cases with ICs" /></a></p>
<p>I still have some of the boxes that the tapes originally shipped in, but this isn&#8217;t necessarily an improvement over just stacking the cases.  They&#8217;re still sort of &#8220;latched&#8221; together in the boxes, and it&#8217;s almost more difficult to pry a case out of a full box than to balance a stack of cases whilst removing a lower one.</p>
<p>I&#8217;ll keep looking &#8212; hopefully there&#8217;s a rack out there that fits the cases, that someone doesn&#8217;t need any more, that I can save from the landfill, and that I get for free. <img src='http://www.neufeld.newton.ks.us/electronics/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=448</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Motion Sensors for Occupancy Tracking</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=229</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=229#comments</comments>
		<pubDate>Fri, 30 Jan 2009 21:52:59 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=229</guid>
		<description><![CDATA[This NewScientist article from last spring shows a very cool system of motion sensors for occupancy tracking. The sensors are installed more densely than in typical buildings, so they can detect occupants&#8217; positions fairly precisely within hallways. The most interesting part of the system for me is the video showing playback of motion through a [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://technology.newscientist.com/article/dn13632">NewScientist article from last spring</a> shows a very cool system of motion sensors for occupancy tracking.  The sensors are installed more densely than in typical buildings, so they can detect occupants&#8217; positions fairly precisely within hallways.</p>
<p>The most interesting part of the system for me is the video showing playback of motion through a building &#8212; you can clearly see where people were walking, where they ended up, etc.</p>
<p>This seems like a natural fit for a smart house &#8212; instead of just watching where there&#8217;s motion <em>now</em>, pay attention to where the motion has <em>gone</em> and remember that there must still be someone in that room (even if they&#8217;re not moving much now).</p>
<p>$10 Parallax motion sensors + blinders to narrow the cone of coverage + write open-source software for the capture and playback, anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=229</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Project Idea: LED Puzzle Ball</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=88</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=88#comments</comments>
		<pubDate>Fri, 30 Jan 2009 16:37:54 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=88</guid>
		<description><![CDATA[A long time back, I was over at Lawrence&#8217;s house and Gail had a number puzzle up on the whiteboard that she was using with her homeschool consortium gradeschool math class. For the students, I think Gail drew the circles with pebbles in them and the younglings had to count the pebbles and write the [...]]]></description>
			<content:encoded><![CDATA[<p>A long time back, I was over at Lawrence&#8217;s house and Gail had a number puzzle up on the whiteboard that she was using with her homeschool consortium gradeschool math class.</p>
<p><img src="http://www2.neufeld.newton.ks.us/images/electronics/2006/06/29/100_0646-mid.jpg" alt="Number Puzzle" /></p>
<p>For the students, I think Gail drew the circles with pebbles in them and the younglings had to count the pebbles and write the sums of the nodes into the edges.</p>
<p>For adults, it&#8217;s a lot more interesting to start with the numbered edges and fill in the vertices with numbers that make the edge sums work.  It&#8217;s not <em>hard</em>; it&#8217;s just a little bit of a twisty way of thinking.</p>
<p>And you have to keep your vertices balanced enough that you don&#8217;t &#8220;overflow&#8221; an edge.  For example, if you started with one pebble in the upper left, then you&#8217;d have to have four in the upper right, and then zero in the lower right, and let&#8217;s just say that zero pebbles isn&#8217;t permitted.  Any solvable configuration will have multiple correct answers, but they&#8217;re constrained by overflow and underflow of all the edges of the graph.</p>
<h4>Puzzle Ball</h4>
<p>All of which made me think that this concept could make for an interesting LED puzzle ball.  Make a dodecahedron (or a smaller regular polyhedron, or even a larger geodesic shape) with LEDs along the edges and LEDs and buttons (up/down?) at the vertices.</p>
<p>Start it up, the LEDs flash and wink all over the place as the controller randomizes the configuration.  Use the buttons to adjust the numbers at the vertices (maybe blue LEDs) so that adjacent vertices add up to the number of LEDs on that edge.  As each edge is &#8220;solved,&#8221; its LEDs change from red to green.  Once you have all the edges green, you&#8217;re done.</p>
<h4>Aesthetics</h4>
<p>Seems like it&#8217;d be coolest as a &#8220;wireframe&#8221; polyhedron rather than a solid (or solid surface).</p>
<p>I think I&#8217;d prefer SMT LEDs over through-hole.  3mm through-hole if absolutely necessary.</p>
<p>I think I&#8217;d like the edge LEDs to be strips of nine that light up fairly symmetrically from the middle out, i.e. something like</p>
<pre>
----o----              ----o----
---o-o---              ---oo----
--o-o-o--              ---ooo---
-o-o-o-o-          or  --oooo---
o-o-o-o-o         the  --ooooo--
-ooo-ooo-      boring  -oooooo--
-ooooooo-              -ooooooo-
oooo-oooo              oooooooo-
ooooooooo              ooooooooo
</pre>
<p>I&#8217;d like the whole thing to be constructed from PCBs, no separate case.  There&#8217;ll need to be room for microcontrollers and/or LED drivers.  Maybe instead of having the PCBs on the <em>face</em> of the polyhedron, have them edgewise so the PCBs&#8217; outer edges are the <em>edges</em> of the polyhedron.  Internally, PCBs could be held together by jumper wires soldered together at the board edges and carrying the signaling bus from one board to another.</p>
<h4>Gameplay</h4>
<p>I still haven&#8217;t decided whether solving the puzzle ball would be fun or merely tedious.</p>
<p>I remember a particular game mode in the old <a href="http://en.wikipedia.org/wiki/Merlin_%28game%29">Merlin</a> where you&#8217;d press buttons and all the adjacent squares would invert state, with the goal being to get all the lights on or off.  I always enjoyed that game, and the way local changes impacted neighboring cells, which impacted strategy for dealing with those neighbors.  I would <em>hope</em> that the puzzle ball would be fun in much the same way.</p>
<p>If each edge has nine LEDs (1 &#8211; 9) and the game is played with non-<a href="http://en.wikipedia.org/wiki/Modular_arithmetic">modular</a> addition, then the average number of lit LEDs per edge will be 5.5, making the average number of lit LEDs per vertex only 2.75 &#8212; that is, on average, only a very few numbers that need to be tried at each vertex.  That doesn&#8217;t sound like a very interesting game.  I could increase the number of LEDs per edge to 20ish, making the average edge sum 10ish, making the average vertex 5ish, which seems okay.</p>
<p>Or should there be ten LEDs per edge and operate in modular arithmetic?  Would that make the puzzle too easy, having more correct solutions?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=88</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Idea: Build a Better Looper</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=371</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=371#comments</comments>
		<pubDate>Mon, 26 Jan 2009 18:50:00 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=371</guid>
		<description><![CDATA[Jeremy and I have been playing with my &#8220;new&#8221; Akai Headrush E2 looper pedal, which allows you to record an instrument (or whatever) into it; then it plays your mini-recording back for you over and over and over in a loop, and you can play along. You can also overdub, recording more stuff on top [...]]]></description>
			<content:encoded><![CDATA[<p>Jeremy and I have been playing with my &#8220;new&#8221; <a href="?action=edit&#038;p=314">Akai Headrush E2 looper pedal</a>, which allows you to record an instrument (or whatever) into it; then it plays your mini-recording back for you over and over and over in a loop, and you can play along.  You can also overdub, recording more stuff on top of what&#8217;s already there and building up a more complex mix in the loop &#8212; this is how KT Tunstall does solo performances of <a href="http://www.youtube.com/watch?v=DehtqLVmdcA">&#8220;Black Horse and the Cherry Tree&#8221;</a>, which are just amazing to watch.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/12/30/DSCN2531.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/12/30/DSCN2531_mid.jpg" alt="Akai Headrush E2 Delay/Loop controller, cleaned" /></a></p>
<p>However, Jeremy and I both have some issues with the feature set <em>and</em> the user interface of the Akai, and we&#8217;re thinking about what it would take to build a better looper &#8212; or at least, one more suited to our desires.</p>
<h4>Feature Wishlist</h4>
<p>Here&#8217;s what we want:</p>
<ul>
<li><strong>At least 60 seconds of loop time</strong>, which would be enough to play 12-bar blues at a fairly slow tempo.  The Akai&#8217;s 17.8 seconds in low-fi mode is enough for KT to do two measures of rhythm and backing vocals, but not enough to record a full chord sequence.</li>
<li><strong>Tap a Record footswitch to begin recording, tap again to end the recording</strong> and start looping.  It doesn&#8217;t absolutely have to be the same switch; but some loopers out there use a potentiometer to set loop duration.  We want duration to be determined by the duration of the phrase we played, as it is with the Akai.</li>
<li><strong>Independently-addressable tracks or channels</strong>.  The Akai lets you discard all of your mix except your very first pass and rebuild from there.  We want to have (say) eight tracks/channels in the loop mix, each with a footswitch and red/green LED.  Tap Record and the next unused channel winks green and records.  Tap any channel&#8217;s footswitch to put it in (green LED) or out (red LED) of the mix.  Not-yet-used channels are dark.</li>
<li><strong>Independently rerecordable channels</strong>.  To rerecord a channel, tap it out of the mix and immediately tap the Rerecord footswitch (which is separate from Record and a little further back or off to the side).  That channel winks green and rerecords.  Various loopers have varying levels of undo or redub, but none (that I&#8217;ve found) let you do this.</li>
<li>Ideally have <strong>stereo recording</strong> so I can loop with the full stereo chorus effect of my analog synths.</li>
</ul>
<p>There&#8217;s room to negotiate on the exact UI, but that should convey the feature set we&#8217;re after.</p>
<h4>How to Build It?</h4>
<p><a href="http://alumni.media.mit.edu/~harrison/">John</a> suggested using an <a href="www.audiopint.org">AudioPint</a> and Pd, and I think I may prototype this with an Arduino to run the control panel and Pd on a laptop to do the audio.  But ultimately I&#8217;d like to build at least two of these in nice stage-ready stompable enclosures, and I really don&#8217;t feel like using a general-purpose OS, for a number of reasons.</p>
<p>It seems to me that this might be a good project for a DSP or an FPGA, but I don&#8217;t know enough to make a choice.  Any suggestions?  (I know I don&#8217;t need the full power of a DSP.)</p>
<p>What I&#8217;d love to find in one IC would be:</p>
<ul>
<li>Dual 16-bit ADC and DAC capable of 44.1kHz</li>
<li>Address and data buses capable of addressing enough external RAM for the audio (say about 1G for stereo * 16 bits * 44100 samples/second * 60 seconds * 8 channels) without my having to worry about DRAM refresh circuitry</li>
<li>A processor that I can program for the very simple, core task of summing/averaging samples from the active channels to feed to the DAC</li>
<li>~32 I/O pins to manage the control panel, and/or I<sup>2</sup>C or SPI to use offboard I/O chips</li>
<li>Ideally a USB interface for uploading samples to a computer, but this would be an extremely low priority</li>
</ul>
<p>Does such a thing exist?  Is that necessarily an FPGA?  Can I get a development environment for < $500 and a chip for < $30?</p>
<p><span id="more-371"></span></p>
<hr />
<h4>Survey of the Marketplace</h4>
<p>Here&#8217;s my comparison of all the loopers reviewed at <a href="http://www.loopers-delight.com/tools/tools.html">Looper&#8217;s Delight</a> against my feature wishlist.</p>
<p><a href="http://www.gibson.com/en%2Dus/Divisions/Gibson%20Pro%20Audio/Echoplex/">Gibson Echoplex</a></p>
<p>Very darn close, nice recording time, nice controls, even lets you replace part of an existing track.  But unfortunately only lets you take things out of the mix via an Undo stack &#8212; LIFO.</p>
<p><a href="http://www.loopers-delight.com/tools/boomerang/boomerang.html">Boomerang Phrase Sampler</a></p>
<p>Appears to stack samples and doesn&#8217;t have flexible undo/rerecord capability.</p>
<p><a href="http://www.loopers-delight.com/tools/tc_electronics/tc2290.html">T.C. Electronic TC2290</a></p>
<p>Very pretty rack interface with lots of buttons!  4-second sample time, expandable to 64 (which would be enough if I got one with the expansion already installed; but it was made in 1986 and the expansion RAM is discontinued).  Can&#8217;t find much other detail on how it works.</p>
<p><a href="http://www.loopers-delight.com/tools/MPX-G2/MPX-G2.html">Lexicon MPX G2</a></p>
<p>20 seconds; layers become permanently merged into the sample at the time of recording.</p>
<p><a href="http://www.loopers-delight.com/tools/DJRND3/DJRND3.html">DJRND3</a></p>
<p>More of a &#8220;controllerist&#8221; tool with BPM-matching stuff for doing live mixes of prerecorded tunes.  Looks kinda interesting, though.  Not foot-friendly &#8212; definitely a DJ tabletop piece.  Oh &#8212; and it&#8217;s a prototype only that&#8217;s not manufactured.</p>
<p><a href="http://www.loopers-delight.com/tools/line6/Line6-DL4.html">Line6 DL4 Modeling Delay</a></p>
<p>Apparently no undo feature at all.</p>
<p><a href="http://www.loopers-delight.com/tools/cycloops/cycloops.html">Red Sounds C-Loops</a></p>
<p>Another DJ tool that does tap-tempo for BPM matching; has a maximum of 32-beat sample length.</p>
<p><a href="http://www.loopers-delight.com/tools/eventide/orville.html">Eventide Orville</a></p>
<p>Very, very pretty family of echo/delay/FX machines.  20 seconds of looping.</p>
<p><a href="http://www.loopers-delight.com/tools/RC20XL/Boss-RC20XL.html">Boss RC-20XL</a></p>
<p>16 minutes sampling time!!!  But only one layer of undo.</p>
<p><a href="http://www.loopers-delight.com/tools/greentea/LooperConstructionKit.html">Looper Construction Kit for Kyma</a></p>
<p>Looks like OS X software, so I&#8217;d need to come up with hardware to drive it, and that doesn&#8217;t suit my embedded notions.</p>
<p><a href="http://www.loopers-delight.com/tools/tc_electronics/D2_Delay.htm">TC Electronics D-Two</a></p>
<p>10 seconds.</p>
<p><a href="http://www.loopers-delight.com/tools/maneco/ManecoLoopers.html">Maneco Filter Eko, Nanolooper, ManecoLooper Elite, ManecoLooper, MicroLooper</a></p>
<p>Look like homebrew jobs that I couldn&#8217;t buy.  32 seconds, 16 seconds, 64 seconds, 32 seconds.  Feature set is hard to tell but they definitely don&#8217;t have enough buttons to do the cut in / cut out that I want in realtime.</p>
<p><a href="http://www.loopers-delight.com/tools/akai/headrushE2/HeadrushE2.html">Akai Headrush E2</a></p>
<p>Described above, but I&#8217;ll reiterate for thoroughness: 18 seconds loop time, can only erase everything except first take.</p>
<p><a href="http://www.loopers-delight.com/tools/eh16II/eh16-II.html">Electro-Harmonix 16 Second Delay Reissue</a></p>
<p>Only three footswitches (and not included); loop duration is set with slide pots instead of tap to start recording, tap to stop.</p>
<p><a href="http://www.loopers-delight.com/tools/bossDD20/bossDD20.html">Boss DD-20 Giga Delay</a></p>
<p>23 seconds, doesn&#8217;t have enough footswitches to cut tracks in and out.</p>
<p><a href="http://www.loopers-delight.com/tools/digitech_jamman/digitech_jamman.html">Digitech JamMan</a></p>
<p>Only two footswitches.</p>
<p><a href="http://www.loopers-delight.com/tools/RC50/Boss-RC50.html">Boss RC-50 Loop Station</a></p>
<p>Looks hot!  But only has overdub (add to what&#8217;s already laid down), replace (replace EVERYTHING that&#8217;s laid down), and one layer of undo/redo.</p>
<p>There are a very few other products mentioned without reviews posted<br />
yet, so I&#8217;m not being completely exhaustive.</p>
<p>At John&#8217;s suggestion, I&#8217;ve also submitted a query to <a href="http://www.sweetwater.com/">Sweetwater</a> asking whether they know of anything that does what we want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=371</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>X-Ray Control Panel???</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=271</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=271#comments</comments>
		<pubDate>Mon, 17 Nov 2008 04:32:56 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Inside]]></category>
		<category><![CDATA[Salvage]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=271</guid>
		<description><![CDATA[One of the electricians at work gave me a bunch of circuit boards from decommissioned equipment this week. It&#8217;s usually elevator stuff, so I hadn&#8217;t paid much attention to it other than to note the pretty colored wires. The I was taking it out of my trunk to put into a &#8220;process later&#8221; pile when [...]]]></description>
			<content:encoded><![CDATA[<p>One of the electricians at work gave me a bunch of circuit boards from decommissioned equipment this week.  It&#8217;s usually elevator stuff, so I hadn&#8217;t paid much attention to it other than to note the pretty colored wires.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2315.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2315_mid.jpg" alt="XG controller panel, rear" /></a></p>
<p>The I was taking it out of my trunk to put into a &#8220;process later&#8221; pile when I noticed the front.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2328.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2328_mid.jpg" alt="XG controller panel, front" /></a></p>
<p>&#8220;X-Ray.&#8221;  60kV tube voltage.  &#8220;Fine focus.&#8221;  Whaaaa???</p>
<p>Combined with the way all the front-panel switches and knobs are bent and broken off, I&#8217;m guessing this was in one of the laboratories, some unfortunate researcher accidentally stepped in front of the beam and mutated into a creature with superhuman strength, and in the resulting chaos demolished the equipment.  Since it was destroyed, now I have it.  Cool!</p>
<p>I went ahead and disassembled it tonight.  Here&#8217;s a different view of the meters:</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2332.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2332_mid.jpg" alt="Edge-style panel meters" /></a></p>
<p>And there&#8217;s a big pile of connectors, resistors, and lovely wires on my workbench.</p>
<h4>Cool Rotary Switches</h4>
<p>Here are the two rotary switch assemblies.  Their knobs were broken off and their shafts bent, so they&#8217;re not working terribly well, but I&#8217;ve improved them a little.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2336.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2336_mid.jpg" alt="Rotary multi-position switches" /></a></p>
<p>They have circuit boards that are ganged together, with the inner shaft turning the back set of switches (of course) and the outer shaft turning the front set.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2339.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2339_mid.jpg" alt="Rotary multi-position switches" /></a></p>
<p>The mechanics of the assemblies are fairly intricate.  You can click the picture (as always) for the full-resolution version if you want to follow along.</p>
<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2345.jpg"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/11/16/DSCN2345_mid.jpg" alt="Rotary multi-position switches, partially disassembled" /></a></p>
<p>Clockwise from the bottom:</p>
<p>Every switch position is a separate trace on the PCBs, with 24 positions on the wide assembly, 12 positions on the rear part of the narrow assembly, and two sets of 5 positions on the front part of the narrow assembly.  A wiper on the plastic rotor connects the PCB&#8217;s inner ring trace to each outer pad in turn.</p>
<p>In the upper left, you can see how the limits of rotation are set by two discs with tabs sticking out, which bolt onto the head end of the (sub-)shaft.  The discs&#8217; tabs stop against a rear-pointing tab on the head-end mounting plate, which is on the underside in this picture.</p>
<p>Shown at the top, the rear portion of the narrow assembly is still in good condition.  It was pretty gummed up, but a few sprays of silicone lubricant got it turning nicely.  The PCBs are mounted on a set of multiple threaded rods, threaded spacers, and unthreaded spacers.  The rotor&#8217;s detent action is provided by the wavy disc on the back side of the mounting plate, a ball bearing sitting in a hole in the plate, and a leaf spring on the front side of the plate.</p>
<p>In the upper right, the front portion of the narrow assembly is okay, but the outer shaft that used to rotate it was sheared off at the base (shown immediately below it).</p>
<p>I had to saw the front knob off the narrow assembly&#8217;s shaft to get the assembly apart and make part of it usable.  You can see that the kob appears to have been threaded onto the end of the shaft; but with a vise and a pliers, I was unable to turn it loose.  The shaft had been pretty badly bent anyway, so I have no hard feelings about having to saw it off.</p>
<h4>Idea for Rotary Switches</h4>
<p>So I&#8217;ve actually been looking for rotary switches like this, and thinking of trying to make some myself.  This unfortunately is not the form factor I need, but it shows the idea is sound.</p>
<p>The high school robotics team has strict rules they have to play by, and one of them is that the joysticks used to control the robots in non-autonomous mode must work like PC joysticks (I think the PIC that runs their control panel is charging and timing an RC circuit to determine the joystick position) and cannot have any supplemental power.</p>
<p>This wouldn&#8217;t matter, except that the linearity of the joysticks they have is poor; and with (apparently) only 8-bit sampling, there&#8217;s not as much they can do programmatically to correct the linearity as they&#8217;d like.  So it takes a bit of programming effort to eliminate drift when the stick is physically centered; and then when they start to move the stick, the robot lurches into action with not much fine control over low speeds, and at high speeds is pretty much just maxed out.</p>
<p>Of <em>course</em> I assume if it were my robot, I could correct most of that in programming. <img src='http://www.neufeld.newton.ks.us/electronics/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Still, that&#8217;s a lot to ask of high-school kids who are already making amazing engineering accomplishments on a very tight timeline.</p>
<p>So Ron (of the fundraising concert, and father of the team captain) would like to figure out how to build a new joystick that abides by the letter and spirit of the rules but gives finer control over low speeds and has really significant jumps up to maximum speed only when you floor it.  Obviously he wants pots with an S curve response (log taper in both directions from center), and he hasn&#8217;t been able to find that commercially, at least not that he could retrofit into a joystick.</p>
<p>His idea was to do it discretely &#8212; come up with some sort of switching action, then connect that to a resistor ladder.  He could play with the resistor ladder to his heart&#8217;s content until he got something that &#8220;felt&#8221; right for the application &#8212; make it pluggable and let the kids swap resistors until they got a response curve they liked.  And he wasn&#8217;t too worried about the robot lurching as the joystick went from step to step on the ladder &#8212; he feels that relatively few values would suffice.</p>
<p>If these 24-position rotary switches could fit into a joystick&#8217;s gimbal assembly, they&#8217;d be fantastic for that!  Reserve the middle 3-4 positions for a broad center band to eliminate home-position drift, then have ten more positions in each direction for different speeds.</p>
<p>Except I&#8217;m pretty sure the gimbal assembly has little 3/4&#8243;-diameter pots right there on it, and these big PCB things just wouldn&#8217;t work.  Feh.</p>
<p>I thought about etching my own PCBs to replace the wafers inside a couple of sacrificial pots, but I hadn&#8217;t figured out quite how to route all the wires out.</p>
<p>Open to suggestions here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=271</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Project Idea: Clock with Sliding Hands</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=256</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=256#comments</comments>
		<pubDate>Tue, 23 Sep 2008 13:43:38 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=256</guid>
		<description><![CDATA[I saw this clock in a catalog last night: I like 24-hour clocks; and I&#8217;m a computer geek, so I use 24-hour time for its unambiguity. And I like the visuals of this clock &#8212; but it&#8217;s functionally useless and/or made for idiots, as the 24-hour-ness of it is strictly cosmetic. It gives you no [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this clock in a catalog last night:</p>
<p><a href="http://www.cb2.com/family.aspx?c=591&#038;f=4830"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/09/23/247Clock.jpg"></a></p>
<p>I like 24-hour clocks; and I&#8217;m a computer geek, so I use 24-hour time for its unambiguity.  And I like the visuals of this clock &#8212; but it&#8217;s functionally useless and/or made for idiots, as the 24-hour-ness of it is strictly cosmetic.  It gives you no idea whatsoever whether it&#8217;s currently 07:00 or 19:00; it just has both numbers painted on, and the hour hand will point in the general direction of both.</p>
<p>How &#8217;bout a clock with a face like this &#8212; numbers spiralling inward &#8212; and an hour hand that slides back and forth end to end across its axis as it turns, so that the end of the hour hand is always touching the marking for the correct hour?  At 07:00, the hour hand is still slid most of the way to the outside of the clock and its end touches the 07; at 19:00, the hour hand has withdrawn further across the center of the clock and its end touches the 19.</p>
<p>Of course it&#8217;d need to be done with gears; I&#8217;m not talking about an LED or LCD clock.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=256</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LED Calculator with Rotary Quadrature Encoder for Target System Voltage Selection</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=248</link>
		<comments>http://www.neufeld.newton.ks.us/electronics/?p=248#comments</comments>
		<pubDate>Sun, 06 Jul 2008 18:38:10 +0000</pubDate>
		<dc:creator>Keith Neufeld</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=248</guid>
		<description><![CDATA[I&#8217;m still working on the LED calculator (original idea and most recent work) &#8212; I&#8217;ve finally got &#8217;round to adding a rotary encoder to set the target system voltage. Now you can turn the potentiometer to set the LED brightness, turn the rotary encoder to set what voltage will be used in the ultimate LED [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www2.neufeld.newton.ks.us/images/electronics/2008/07/04/DSCN1536.JPG"><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/07/04/DSCN1536_mid.jpg" alt="LED calculator with rotary encoder for target supply voltage" /></a></p>
<p>I&#8217;m still working on the LED calculator (<a href="?p=216">original idea</a> and <a href="?p=219">most recent work</a>) &#8212; I&#8217;ve finally got &#8217;round to adding a rotary encoder to set the target system voltage.  Now you can turn the potentiometer to set the LED brightness, turn the rotary encoder to set what voltage will be used in the ultimate LED circuit, and read the LED voltage, current, and current-limiting resistor values off the screen.</p>
<p>I also found the &Omega; in my LCD&#8217;s character matrix, so I tidied up the display a little.</p>
<p>And most significantly, I wrote an Arduino library for reading (multiple) quadrature encoders.  The simple approach of <a href="http://www.arduino.cc/playground/Main/RotaryEncoders">polling them inside <code>loop()</code></a> was causing me to lose a lot of steps from the encoders; and the code to read them using hardware external interrupts (lower on the same page) only works on digital pins 2 and 3, so only supports one encoder if both pins are wired to interrupts for the highest resolution, or two if interrupting on a single pin and polling the other.</p>
<p>My Quadrature library uses the TIMER2 overflow interrupt service routine to poll multiple encoders rapidly and track the results, supporting as many encoders as you have room for on the digital pins.  It also encapsulates all the dirty work into the library code, so using it is as simple as</p>
<blockquote><pre>
#include "Quadrature.h"

Quadrature myencoder1(9, 10);  //  Connected to pins 9 and 10

loop() {
  x = myencoder1.position();
}
</pre>
</blockquote>
<p>It still has some rough edges and it&#8217;s by no means perfect (more on that below), but it sure makes it easy to use rotary quadrature encoders.  It&#8217;s available on a new <a href="?page_id=249">Downloads page</a> for anyone interested.</p>
<p><span id="more-248"></span></p>
<h3>How It Works</h3>
<p>I&#8217;ve <a href="?p=234">discussed previously</a> how rotary quadrature encoders translate the rotation of a shaft into two out-of-phase digital signals from which you can derive both the direction and speed (or steps) of rotation.  If you&#8217;re not familiar with quadrature encoding and care to follow along, it might be worth a detour to the earlier post to read up on that first.</p>
<p>Before diving into the code, let me say that although I&#8217;ve been programming in C for about 25 years, this is my first foray into C++; and everything I&#8217;ve figured out about it, I got out of books.  I welcome advice on how to write better C++ code.</p>
<h3>Decoder</h3>
<p>The heart of decoding quadrature is processing transitions.  There are various ways of thinking of the transitions, including &#8220;on a rising (or falling) edge of pin1, check whether pin2 is high or low to determine the direction&#8221; and &#8220;on a transition of pin1, XOR pin1 and pin2 to determine the direction.&#8221;  Some of these don&#8217;t even react to every transition in the state diagram (courtesy <a href="http://en.wikipedia.org/wiki/Rotary_encoder">Wikipedia&#8217;s rotary encoder article</a>):</p>
<p><img src="http://www2.neufeld.newton.ks.us/images/electronics/2008/05/03/Quadrature_Diagram.png" alt="Quadrature encoding diagram from Wikipedia" /></p>
<p>I wanted to be able to detect every transition for the highest possible resolution &#8212; but also have the flexibility to switch between &#8220;half-stepping&#8221; and &#8220;full-stepping&#8221; to change my resolution, depending on the demands of the application and the encoder.  For example, the encoder I&#8217;m using in this project has two half steps per physical detent, so I want to be able to set it to read full steps (matching the physical &#8220;clicks&#8221;) instead of half steps.</p>
<p>It may not be the best way, but I encoded the state change information into a pair of arrays:</p>
<blockquote><pre>
const int _half [4][4] = {
    { 0, -1, 1, 0 },            //  00 -> 10 is CW
    { 1, 0, 0, -1 },            //  01 -> 00 is CW
    { -1, 0, 0, 1 },            //  10 -> 11 is CW
    { 0, 1, -1, 0 }             //  11 -> 01 is CW
};

const int _full [4][4] = {
    { 0, 0, 0, 0 },             //  00 -> 10 is silent CW
    { 1, 0, 0, -1 },            //  01 -> 00 is CW
    { -1, 0, 0, 1 },            //  10 -> 11 is CW
    { 0, 0, 0, 0 }              //  11 -> 01 is silent CW
};
</pre>
</blockquote>
<p>Then inside my service routine, I read the current encoder values into the <code>quadbits</code> variable, compare it to the previous value to see whether there&#8217;s a change [*], look up the &lt;previous, current&gt; pair in the full-step transition table to see what to add to / subtract from the position accumulator, and then save the current encoder values for the next round through the loop.</p>
<blockquote><pre>
            if (quadbits != quad->_previous) {
                int position = quad->_position +
                        _full[quad->_previous][quadbits];
                . . .
                quad->_previous = quadbits;
</pre>
</blockquote>
<p>* &nbsp; [This check isn't absolutely necessary since no-change is already encoded into the transition tables, but it shortcuts doing min/max checking if no changes have occurred.]</p>
<p>Right now, it&#8217;s hard-coded to use the <code>_full[]</code> transition table all the time, since that&#8217;s what I needed for this circuit, but it&#8217;ll be a simple matter to add another class function to select half- or full-stepping mode and choose the appropriate table here.</p>
<h3>Calling the Decoder</h3>
<p>Before moving it to an interrupt service routine, I tested calling the decoder function from inside the Arduino&#8217;s main loop.  As I expected, when I had any other code in <code>loop()</code>, I lost significant numbers of steps when spinning the encoder rapidly by hand.  In order to ensure the decoder was called fast enough to avoid losing steps, I moved its invocation into an interrupt service routine (ISR) for the TIMER2 overflow interrupt, which happens (in the Arduino by default) about 490 times per second.</p>
<p>The ISR is setup up by calling the macro <code>ISR(<em>&lt;interrupt&gt;</em>)</code>:</p>
<blockquote><pre>
ISR(TIMER2_OVF_vect) {
    Quadrature::isr();
}
</pre>
</blockquote>
<p>The trick here is that the ISR isn&#8217;t called on a specific Quadrature object, and so doesn&#8217;t have access to the object&#8217;s private data (which pins to use, saved previous position, etc).  I really didn&#8217;t want to expose all the private data as public for the ISR to access externally; and since the ISR isn&#8217;t (as far as I can tell) implemented as a function I couldn&#8217;t make it a friend function.  Instead, I created a single public <code>Quadrature::isr()</code> function to perform the ISR tasks and called that function from the ISR.</p>
<p>Again, the ISR isn&#8217;t being called on a specific Quadrature object &#8212; it&#8217;s responsible for servicing <em>all</em> quadrature encoders that are connected.  So the <code>Quadrature::isr()</code> function needs to have a registry of all Quadrature objects and loop through them, processing each in turn.  My understanding is that the right C++ data structure for keeping that registry would be a vector; but I couldn&#8217;t find vector support in the Arduino C++ libraries, so I did it with an array.  Blech.</p>
<p>Quadrature.h:</p>
<blockquote><pre>
#define DIGITAL_PINS (13)
. . .
class Quadrature
{
    . . .
    private:
        . . .
        static Quadrature* _registry[DIGITAL_PINS];
        //static vector<Quadrature *> _registry;
};
</pre>
</blockquote>
<p>Quadrature.cpp:</p>
<blockquote><pre>
Quadrature * Quadrature::_registry[DIGITAL_PINS];
//vector<Quadrature *> Quadrature::_registry;
. . .
Quadrature::Quadrature(int pin1, int pin2):
    _pin1(pin1), _pin2(pin2), _position(0),
    _min(0), _max(0), _usingmin(0), _usingmax(0) {
    . . .
    _registry[pin1] = this;
    //_registry.push_back(this);
}
</pre>
</blockquote>
<p>When each Quadrature object is created, I need to add it to the list of objects to be processed in the ISR.  With a proper vector, I could push Quadrature object pointers onto the &#8220;list&#8221; upon creation and traverse the list in the ISR, servicing each encoder object in turn.</p>
<p>With an array, I should perhaps have kept a separate variable for the count of how many objects exist and put the object pointer into the next empty spot each time (much like using a vector), but instead resorted to stuffing the object pointer into the spot in the array defined by which pin is used for this encoder&#8217;s pin 1.  I&#8217;m aware that the array never gets properly initialized the way it&#8217;s written now, and I&#8217;m very open to suggestions on improving this part.</p>
<p>So the remainder of <code>Quadrature::isr()</code> is a loop to iterate through however many Quadrature objects have been created and do the transition processing on each:</p>
<blockquote><pre>
inline void Quadrature::isr(void) {
    int q;

    for (q = 0; q < DIGITAL_PINS; ++ q) {
        Quadrature *quad;

        if (_registry[q]) {
            quad = _registry[q];
            . . .
            //  transition code goes here
        }
    }
}
</pre>
</blockquote>
<h4>ISR Caveat</h4>
<p>One last thing about the ISR:  TIMER2 is used for Arduino PWM output, and my ISR doesn't interfere with that because the PWM is done in hardware and the ISR is done in software.  However, my ISR <em>will</em> overwrite any ISR that may already have been attached to TIMER2, if the program is using multiple timer-driven libraries.</p>
<p>The last time I wrote ISRs was on the Apple ][ and Commodore-64, where the convention was to check the current interrupt vector before installing your ISR, stuff the current contents into your own code, and (if non-zero) jump to that location at the end of your ISR.  That way if an ISR was already installed, you'd chain to it after your ISR code finished, and it would still be executed.</p>
<p>I can't quite see how to do that on the Arduino, though, at least not without rewriting the <code>ISR()</code> macro, and I'm not clear enough how chip-specific that macro is to be ready to tackle it.  Another possibility would be to create an ISR registry system and persuade all ISR authors to use the ISR registry to insert their ISR into the registry-managed chain.  Neither of these is able to force compatibility with non-cooperating code, though; and of course neither addresses the issue of different ISR-using libraries wanting to change the timer speed.  Perhaps <em>caveat library user</em> really is the best that can be done.</p>
<h3>Object Constructor</h3>
<p>Here's the constructor to create a new object:</p>
<blockquote><pre>
Quadrature::Quadrature(int pin1, int pin2):
    _pin1(pin1), _pin2(pin2), _position(0),
    _min(0), _max(0), _usingmin(0), _usingmax(0) {

    pinMode(pin1, INPUT);
    pinMode(pin2, INPUT);
    digitalWrite(pin1, HIGH);           //  activate internal pullups
    digitalWrite(pin2, HIGH);

    _previous = _readpins();            //  read initial position

    TIMSK2 |= (1 << TOIE2);             //  enable timer 2 overflow interrupt

    _registry[pin1] = this;
    //_registry.push_back(this);
}
</pre>
</blockquote>
<p>The <code>Quadrature::Quadrature()</code> constructor uses an initialization list (I think I&#8217;m using the correct terminology) to initialize the values of most of the private variables.  It then sets the two encoder pins as inputs and activates the internal pull-up resistors, reads in the initial encoder pin values, enables the TIMER2 interrupt, and (as seen before) registers this new object onto the list to process in the ISR.</p>
<h3>Remaining Code</h3>
<p>I haven&#8217;t touched on the minimum and maximum capabilities yet &#8212; you can call <code>myencoder.minimum(foo)</code> to set the minimum value of the encoder&#8217;s position to <code>foo</code> and <code>myencoder.maximum(bar)</code> to set the maximum to <code>bar</code>.  You can also call <code>oldmin = myencoder.minimum()</code> to read and save the current minimum setting, with a corresponding function for reading the max; and you can call <code>myencoder.nominimum()</code> to turn off minimum (or maximum) processing if you don&#8217;t want it in a particular section of code.</p>
<p>I&#8217;m trying to facilitate a program using an encoder for multiple functions &#8212; for example, first selecting a mode (&#8220;Audio Function&#8221;), then selecting a parameter (&#8220;Balance&#8221;), then selecting a value for that parameter (-5 to 5).  Each of these may require different minima and maxima for its list, all operating at different times on the same encoder object.</p>
<p>Most of the rest of the code is housekeeping.  It&#8217;s a bit long to paste the whole thing in here; but if you&#8217;re interested in looking it over and offering improvements, <a href="?page_id=249">download a copy</a>, look over <em>Quadrature.h</em> and <em>Quadrature.cpp</em>, and post comments below.</p>
<h3>Using the Quadrature Library</h3>
<p>Encapsulating code into libraries makes using that functionality <em>so</em> much easier; and encapsulating multiple encoders into objects is a really good use for object-oriented programming.  The pertinent sections of my LED calculator code have simplified to this:</p>
<blockquote><pre>
#include "Quadrature.h"
Quadrature supply(8, 10);

. . .

void setup() {
  . . .
  supply.minimum(0);
  supply.maximum(120);
  supply.position(50);
}

void loop() {
  . . .
  resistor = (float) supply.position() / 10 / led_current;
  . . .
}
</pre>
</blockquote>
<p>I&#8217;m dividing the rotary encoder&#8217;s value by 10 to serve .1V increments, and initializing it to run from 0-120 (0-12V) and to start at 50 (5.0V).  I&#8217;m also thinking about creating a setup menu for the LED calculator user to program in their preferred minimum, default, and maximum supply voltages for the target system, and saving those in the Arduino&#8217;s internal EEPROM.</p>
<h3>Future Enhancements</h3>
<p>Enhancements to the Quadrature library:</p>
<ul>
<li>Clean up the <code>_registry[]</code> array code &#8212; make it work more like a vector, as discussed above.</li>
<li>Support changing between half- and full-step modes.</li>
<li>Add an &#8220;acceleration&#8221; mode that works like mouse drivers &#8212; increment/decrement with a larger step size when you&#8217;re turning the encoder fast.  (Right now, it takes me multiple turns to get from 5V to 12V.  It should take a single fast turn to get close, and some slow fine-tuning to dial in the exact desired value.)</li>
<li>Add a function to change the timer speed, hence the frequency of checking the encoder in the ISR.  Right now the code works well for hand-driven rotary encoders, but would drop steps horribly for encoders attached to motor shafts, wheels, etc.</li>
<li>Create a subclass to return speed and direction, rather than position?</li>
</ul>
<p>Enhancements to the voltage-selection code in the LED calculator:</p>
<ul>
<li>Allow the user to change the minimum, default, and maximum target voltages, as mentioned above.</li>
<li>Allow the user to program in a set of favorite voltages (e.g. 3.3V, 5.0V, and 12.0V) and make the rotary encoder select from the list rather than dialing in arbitrary voltages?</li>
</ul>
<h3>LED Calculator Next Steps</h3>
<p>I have an enclosure for the calculator that I&#8217;m not thrilled about (it&#8217;s taller than I like) but which will work, and an LCD that fits the case.  I need to order rotary encoders from Digi-Key so I can build an exact prototype of what I want to offer kits for, and then I&#8217;m ready to lay out the PCB and make one!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=248</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>
