<?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>NatureTM</title>
	<atom:link href="http://naturetm.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://naturetm.com</link>
	<description></description>
	<lastBuildDate>Mon, 01 Apr 2013 03:41:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>My New ADM-3A Dumb Terminal</title>
		<link>http://naturetm.com/?p=228</link>
		<comments>http://naturetm.com/?p=228#comments</comments>
		<pubDate>Mon, 01 Apr 2013 03:41:50 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=228</guid>
		<description><![CDATA[My good friend Robie has some connections in the salvage industry. We have a running deal where I do some general IT work for him, and he finds me cool geeky stuff in exchange. So far, he&#8217;s gotten me a nice handheld FLIR, a couple of old portable computers, and a cold-war era radiation detector. ]]></description>
				<content:encoded><![CDATA[<p>My good friend Robie has some connections in the salvage industry.  We have a running deal where I do some general IT work for him, and he finds me cool geeky stuff in exchange.  So far, he&#8217;s gotten me a nice handheld FLIR, a couple of  old portable computers, and a cold-war era radiation detector.  Yesterday he called my and said he had something really nice.  I stopped by today and wasn&#8217;t let down.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/03/20130331_202031.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/03/20130331_202031-225x300.jpg" alt="20130331_202031" width="225" height="300" class="alignnone size-medium wp-image-229" /></a></p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/03/20130331_201608.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/03/20130331_201608-225x300.jpg" alt="20130331_201608" width="225" height="300" class="alignnone size-medium wp-image-230" /></a></p>
<p>That&#8217;s all TTL logic, save a few specialized IC&#8217;s.  No microprocessors.  Awesome.</p>
<p>It&#8217;s an <a href="https://www.google.com/url?sa=t&#038;rct=j&#038;q=&#038;esrc=s&#038;source=web&#038;cd=1&#038;cad=rja&#038;ved=0CDIQFjAA&#038;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FADM-3A&#038;ei=nvFYUevJNMfF4APfqICoCQ&#038;usg=AFQjCNGKj0g42BRSk4axB4euXuj3hk8qxg&#038;sig2=_AdyoV2iGisMOb565vYEHA&#038;bvm=bv.44442042,d.dmQ">ADM-3A</a> terminal.  This thing is really a piece of computing history.  With Linux, &#8216;~&#8217; means home in many shells.  That&#8217;s because on the ADM-3A, the word &#8220;home&#8221; and &#8216;~&#8217; are printed on the same key.  Also, the text editor &#8220;vi&#8221; uses the HJKL keys as arrows.  That&#8217;s because the corresponding arrows are printed on the ADM-3A&#8217;s keys.  This standard has found its way into many programs beyond vi, including <a href="https://www.google.com/url?sa=t&#038;rct=j&#038;q=&#038;esrc=s&#038;source=web&#038;cd=2&#038;cad=rja&#038;sqi=2&#038;ved=0CD0QFjAB&#038;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FNetHack&#038;ei=J_dYUbqFKLWh4AO1oYGABA&#038;usg=AFQjCNHOWqS10XXT1XjrhtQb8hdTCo-Nrw&#038;sig2=OEnC_jDywFFsjgNtY41jAQ&#038;bvm=bv.44442042,d.dmg">NetHack</a> and even a Google Labs feature of Gmail.  It&#8217;s quite satisfying to own such an item, and I can&#8217;t wait to use it with one of my boxen, as soon as my USB->RS232 cable arrives.</p>
<p>Finally, I have a question for the audience.  In the research I&#8217;ve been doing, I haven&#8217;t been able to find pictures or any information about the ADM-3A in orange.  It doesn&#8217;t appear that it was painted.  Since I can&#8217;t find anything about the color, I&#8217;m wondering if my new little box is somehow special.  If you happen to know anything about it, please do reply.</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=228</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Numitron Tube Alarm Clock</title>
		<link>http://naturetm.com/?p=205</link>
		<comments>http://naturetm.com/?p=205#comments</comments>
		<pubDate>Tue, 08 Jan 2013 01:33:45 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=205</guid>
		<description><![CDATA[This is a clock I made for my dad&#8217;s Christmas present. He&#8217;s been an incredible help to me while I&#8217;ve been returning to school for a degree in computer engineering. I wanted to make him a gift that would show thanks for all he has done for me. I thought it would be appropriate to ]]></description>
				<content:encoded><![CDATA[<p><iframe width="500" height="281" src="http://www.youtube.com/embed/oM22JPlCByk?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>This is a clock I made for my dad&#8217;s Christmas present.  He&#8217;s been an incredible help to me while I&#8217;ve been returning to school for a degree in computer engineering.  I wanted to make him a gift that would show thanks for all he has done for me.  I thought it would be appropriate to make him something using what I have learned in school.  Thanks, dad!</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/01/20130107_121002.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/01/20130107_121002-300x225.jpg" alt="20130107_121002" width="300" height="225" class="alignnone size-medium wp-image-208" /></a><br />
The clock&#8217;s display is built from Soviet-era IV-9 Numitron tubes I picked up off of eBay.  They&#8217;re really easy to work with compared to nixie tubes, and look (arguably) just as cool.  Each segment draws about as much current as an LED, and they can work with either common anode or common cathode drivers. This allowed me to use some HEF4794B LED drivers I had on hand.  These chips are chainable shift registers, so the display only required 3 microcontroller pins.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/01/20130107_152825.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/01/20130107_152825-300x225.jpg" alt="20130107_152825" width="300" height="225" class="alignnone size-medium wp-image-211" /></a><br />
I also wanted the clock to have an audible alarm.  In a previous post, a reader named lasershark tipped me off about about a really interesting way of generating music with minimal code, called <a href="http://canonical.org/~kragen/bytebeat/" title="Bytebeat" target="_blank">Bytebeat</a>.  This method generates 8-bit audio at 8000 samples per second using only one line of code.  I have Bytebeat implemented in the file &#8220;sound.c&#8221; in the source code zip below.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/01/20130107_120926.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/01/20130107_120926-300x225.jpg" alt="20130107_120926" width="300" height="225" class="alignnone size-medium wp-image-213" /></a><br />
For timekeeping and battery backup I used a <a href="http://macetech.com/store/index.php?main_page=product_info&#038;cPath=5&#038;products_id=8" target="_blank">Chronodot RTC module</a> from Macetech.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/01/20121229_123922.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/01/20121229_123922-300x224.jpg" alt="20121229_123922" width="300" height="224" class="alignnone size-medium wp-image-214" /></a><br />
I tried to keep the build as clean as possible since the clock is intended mostly for display.  Extra effort was made on the jumpers to the Numitrons.  I didn&#8217;t want things to turn into a rat&#8217;s nest while running 9 wires to every tube.  I also chose Christmas colors for the protoboard and wires.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2013/01/20130107_120814.jpg"><img src="http://naturetm.com/wp-content/uploads/2013/01/20130107_120814-300x225.jpg" alt="20130107_120814" width="300" height="225" class="alignnone size-medium wp-image-219" /></a></p>
<p>Here&#8217;s the source as a CCS project:<br />
<a href="http://naturetm.com/wp-content/uploads/2013/01/Numitron.zip">Numitron</a></p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=205</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hey, HDD Clock people!</title>
		<link>http://naturetm.com/?p=202</link>
		<comments>http://naturetm.com/?p=202#comments</comments>
		<pubDate>Wed, 28 Dec 2011 20:15:05 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=202</guid>
		<description><![CDATA[I haven&#8217;t forgotten about you! I&#8217;ve been working the last couple of days on rewriting the clock code for the TI-Launchpad. I plan to release the source and build instructions sometime in January. I&#8217;ll update you on my progress soon]]></description>
				<content:encoded><![CDATA[<p>I haven&#8217;t forgotten about you!  I&#8217;ve been working the last couple of days on rewriting the clock code for the TI-Launchpad.  I plan to release the source and build instructions sometime in January.  I&#8217;ll update you on my progress soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=202</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>My First FPGA Project &#8212; Larson Scanner</title>
		<link>http://naturetm.com/?p=197</link>
		<comments>http://naturetm.com/?p=197#comments</comments>
		<pubDate>Wed, 15 Jun 2011 18:03:56 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[FPGA]]></category>
		<category><![CDATA[LEDs]]></category>
		<category><![CDATA[Cylon Eye]]></category>
		<category><![CDATA[example code]]></category>
		<category><![CDATA[Larson Scanner]]></category>
		<category><![CDATA[Xilinx]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=197</guid>
		<description><![CDATA[I&#8217;ve decided to take a little break from MSP430 and learn something new. FPGA&#8217;s have always intrigued me, so I picked up a Nexys 2 from Digilent and started reading a book called FPGA Prototyping by Verilog Examples by Pong P. Chu. (That reminds me, I still need to finish Pong for the MSP430.) I ]]></description>
				<content:encoded><![CDATA[<p><iframe width="500" height="281" src="http://www.youtube.com/embed/mcHdRpgep28?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>I&#8217;ve decided to take a little break from MSP430 and learn something new.  FPGA&#8217;s have always intrigued me, so I picked up a <a href="http://www.amazon.com/gp/product/B001D9EN6E/ref=as_li_qf_sp_asin_tl?ie=UTF8&#038;tag=natucom08-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399373&#038;creativeASIN=B001D9EN6E">Nexys 2 from Digilent</a> and started reading a book called <a href="http://www.amazon.com/gp/product/0470185325/ref=as_li_qf_sp_asin_tl?ie=UTF8&#038;tag=natucom08-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0470185325">FPGA Prototyping by Verilog Examples</a> by Pong P. Chu.  (That reminds me, I still need to finish Pong for the MSP430.)</p>
<p>I read several chapters to familiarize myself with the hardware and language, but nothing beats learning by doing.  My summer construction job was rained out today, so I decided to grab a Rockstar energy drink and write my first Verilog project.  I figured a Kitt light/Larson Scanner/Cylon eye would be something I could figure out in a few hours.  I&#8217;m not too sure how &#8220;correct&#8221; my code is, so I&#8217;d love to hear some suggestions.</p>
<p><pre><code>module main
&nbsp;&nbsp;(
&nbsp;&nbsp;input wire clk,
&nbsp;&nbsp;output wire [2:0] position,
&nbsp;&nbsp;output wire direction,
&nbsp;&nbsp;output wire [7:0] Led
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp; 
&nbsp;&nbsp; 
&nbsp;&nbsp; // symbolic state declaration
&nbsp;&nbsp;localparam&nbsp;&nbsp; rising = 1&#039;b1,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;falling = 1&#039;b0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;reg [24:0] position_state_count, brightness_state_count;
&nbsp;&nbsp;reg dir_state_reg, dir_state_next;
&nbsp;&nbsp;reg [2:0] position_state_reg, position_state_next;
&nbsp;&nbsp;reg [3:0] brightnesses [7:0];
//&nbsp;&nbsp;reg [2:0] brightnesses_next [7:0];
&nbsp;&nbsp;
&nbsp;&nbsp;// state register
&nbsp;&nbsp;always @(posedge clk)
&nbsp;&nbsp;&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dir_state_reg &lt;= dir_state_next;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position_state_reg &lt;= position_state_next;
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;
&nbsp;&nbsp;// next position state logic
&nbsp;&nbsp;always @(posedge clk)
&nbsp;&nbsp;&nbsp;&nbsp;if(position_state_count == 7500000)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position_state_count = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(dir_state_reg)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position_state_next = position_state_reg + 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position_state_next = position_state_reg - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position_state_count = position_state_count + 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;// next direction state logic
&nbsp;&nbsp;always @(posedge clk)
&nbsp;&nbsp;&nbsp;&nbsp;if(position_state_reg == 7)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dir_state_next = falling;
&nbsp;&nbsp;&nbsp;&nbsp;else if(position_state_reg == 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dir_state_next = rising;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp;&nbsp;assign position = position_state_reg;
//&nbsp;&nbsp;assign direction = dir_state_reg;

&nbsp;&nbsp;// brightness state logic
&nbsp;&nbsp;always @(posedge clk)
&nbsp;&nbsp;&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightness_state_count == 1500000)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightness_state_count = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[0] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[0] = brightnesses[0] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[1] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[1] = brightnesses[1] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[2] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[2] = brightnesses[2] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[3] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[3] = brightnesses[3] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[4] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[4] = brightnesses[4] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[5] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[5] = brightnesses[5] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[6] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[6] = brightnesses[6] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(brightnesses[7] &gt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[7] = brightnesses[7] - 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightness_state_count = brightness_state_count + 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightnesses[position_state_reg] = 15;
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;
&nbsp;&nbsp;// instantiate led pwm logic
&nbsp;&nbsp;pwm led_ctl0 (.brightness(brightnesses[0]), .out(Led[0]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl1 (.brightness(brightnesses[1]), .out(Led[1]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl2 (.brightness(brightnesses[2]), .out(Led[2]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl3 (.brightness(brightnesses[3]), .out(Led[3]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl4 (.brightness(brightnesses[4]), .out(Led[4]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl5 (.brightness(brightnesses[5]), .out(Led[5]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl6 (.brightness(brightnesses[6]), .out(Led[6]), .clk(clk));
&nbsp;&nbsp;pwm led_ctl7 (.brightness(brightnesses[7]), .out(Led[7]), .clk(clk));

endmodule</code></pre></p>
<p><pre><code>module pwm
&nbsp;&nbsp;(
&nbsp;&nbsp;&nbsp;&nbsp;input wire clk,
&nbsp;&nbsp;&nbsp;&nbsp;// 16 levels of brightness
&nbsp;&nbsp;&nbsp;&nbsp;input wire [3:0] brightness,
&nbsp;&nbsp;&nbsp;&nbsp;output wire out
&nbsp;&nbsp; );
&nbsp;&nbsp;
&nbsp;&nbsp;reg [2:0] counter_reg;
&nbsp;&nbsp;wire [2:0] counter_next;
&nbsp;&nbsp;
&nbsp;&nbsp;always @(posedge clk)
&nbsp;&nbsp;&nbsp;&nbsp;counter_reg &lt;= counter_next;
&nbsp;&nbsp;
&nbsp;&nbsp;assign counter_next = counter_reg + 1;
&nbsp;&nbsp;assign out =&nbsp;&nbsp; (brightness == 4&#039;b1111) ? 1&#039;b1 :
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(brightness &gt; counter_reg) ? 1&#039;b1 : 1&#039;b0;

endmodule</code></pre></p>
<p>Constraints for Nexys 2:<br />
<pre><code># clock pin for Nexys 2 Board
NET &quot;clk&quot;&nbsp;&nbsp; LOC = &quot;B8&quot;; # Bank = 0, Pin name = IP_L13P_0/GCLK8, Type = GCLK, Sch name = GCLK0

# Leds
NET &quot;Led&lt;0&gt;&quot;&nbsp;&nbsp;LOC = &quot;J14&quot;; # Bank = 1, Pin name = IO_L14N_1/A3/RHCLK7, Type = RHCLK/DUAL, Sch name = JD10/LD0
NET &quot;Led&lt;1&gt;&quot;&nbsp;&nbsp;LOC = &quot;J15&quot;; # Bank = 1, Pin name = IO_L14P_1/A4/RHCLK6, Type = RHCLK/DUAL, Sch name = JD9/LD1
NET &quot;Led&lt;2&gt;&quot;&nbsp;&nbsp;LOC = &quot;K15&quot;; # Bank = 1, Pin name = IO_L12P_1/A8/RHCLK2, Type = RHCLK/DUAL, Sch name = JD8/LD2
NET &quot;Led&lt;3&gt;&quot;&nbsp;&nbsp;LOC = &quot;K14&quot;; # Bank = 1, Pin name = IO_L12N_1/A7/RHCLK3/TRDY1, Type = RHCLK/DUAL, Sch name = JD7/LD3
NET &quot;Led&lt;4&gt;&quot;&nbsp;&nbsp;LOC = &quot;E17&quot;; # Bank = 1, Pin name = IO, Type = I/O, Sch name = LD4? s3e500 only
NET &quot;Led&lt;5&gt;&quot;&nbsp;&nbsp;LOC = &quot;P15&quot;; # Bank = 1, Pin name = IO, Type = I/O, Sch name = LD5? s3e500 only
NET &quot;Led&lt;6&gt;&quot;&nbsp;&nbsp;LOC = &quot;F4&quot;;&nbsp;&nbsp;# Bank = 3, Pin name = IO, Type = I/O, Sch name = LD6? s3e500 only
NET &quot;Led&lt;7&gt;&quot;&nbsp;&nbsp;LOC = &quot;R4&quot;;&nbsp;&nbsp;# Bank = 3, Pin name = IO/VREF_3, Type = VREF, Sch name = LD7? s3e500 only</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=197</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Generating Random Numbers</title>
		<link>http://naturetm.com/?p=174</link>
		<comments>http://naturetm.com/?p=174#comments</comments>
		<pubDate>Thu, 12 May 2011 16:49:39 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[example code]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=174</guid>
		<description><![CDATA[I was looking for example code for RF2500 last night and came across some TI code for using the ADC as a random number generator. The function was in assembly, so I rewrote it in C: bool getRandomBit(){ &#160;&#160;ADC10CTL1 &#124;= INCH_5; &#160;&#160;ADC10CTL0 &#124;= SREF_1 + ADC10SHT_1 + REFON + ADC10ON; &#160;&#160;ADC10CTL0 &#124;= ENC + ADC10SC; ]]></description>
				<content:encoded><![CDATA[<p>I was looking for example code for RF2500 last night and came across some TI code for using the ADC as a random number generator.  The function was in assembly, so I rewrote it in C:</p>
<p><pre><code>bool getRandomBit(){
&nbsp;&nbsp;ADC10CTL1 |= INCH_5;
&nbsp;&nbsp;ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON;
&nbsp;&nbsp;ADC10CTL0 |= ENC + ADC10SC;
&nbsp;&nbsp;while(ADC10CTL1 &amp; ADC10BUSY);
&nbsp;&nbsp;return ADC10MEM &amp; 0x01;
}</code></pre></p>
<p>Pin 1.5 is floating unconnected, and is measured by the adc.  The LSB is used as the random bit.  There&#8217;s a twist though.  Pin 1.4 is also floating unconnected, and is used as Vref+, so the top end of the range is floating as well.  I thought that was pretty clever.  Nice, TI!</p>
<p>I wrote a few console programs to help me visualize the randomness.  It turned out the generator was biased toward producing 0&#8242;s.  This function used with the previous function seemed to remove the bias:</p>
<p>EDIT: it was just dumb luck that the following function removed the bias.  I did the math afterward, and this 0&#8242;s the bias when getRandomBit() returns a 1 30% of the time.  I guess that means the &#8217;0&#8242; to &#8217;1&#8242; ratio of getRandomBit() is close to 7 to 3.  Not great.  I&#8217;m mulling over the idea of using laser speckle as a cheap way to generate the randomness.</p>
<p><pre><code>bool get0BiasRandomBit(){
&nbsp;&nbsp;if(getRandomBit()){
&nbsp;&nbsp;&nbsp;&nbsp;if(getRandomBit())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1;
&nbsp;&nbsp;}
&nbsp;&nbsp;else{
&nbsp;&nbsp;&nbsp;&nbsp;if(getRandomBit())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;}
}</code></pre></p>
<p>The following examples require the <a href="http://www.43oh.com/forum/viewtopic.php?f=10&#038;t=761">Full-duplex software UART for launchpad</a> library, which was assembled by Rickta59.</p>
<p>To test for bias, I displayed a meandering line in a serial console.  If I get more 0&#8242;s than 1&#8242;s, the line should slowly skew to the left or right:</p>
<p><pre><code>#include &quot;msp430g2231.h&quot;
#include &quot;config.h&quot;
#include &quot;softserial.h&quot;
#include &lt;stdbool.h&gt;

#define CONSOLE_WIDTH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80

bool getRandomBit();
bool get0BiasRandomBit();

void main(){
&nbsp;&nbsp;int linePositon = CONSOLE_WIDTH / 2;
&nbsp;&nbsp;char cursorPosition;
&nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;DCOCTL = CALDCO_16MHZ;
&nbsp;&nbsp;BCSCTL1 = CALBC1_16MHZ;
&nbsp;&nbsp;
&nbsp;&nbsp;WDTCTL = WDTPW + WDTHOLD;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Stop WDT
&nbsp;&nbsp;
&nbsp;&nbsp;SoftSerial_init();
&nbsp;&nbsp;_enable_interrupts();
&nbsp;&nbsp;
&nbsp;&nbsp;while(1){
&nbsp;&nbsp;&nbsp;&nbsp;for(cursorPosition = 0; cursorPosition &lt; linePositon; cursorPosition++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SoftSerial_xmit(&#039;8&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;SoftSerial_xmit(&#039; &#039;);
&nbsp;&nbsp;&nbsp;&nbsp;cursorPosition++;
&nbsp;&nbsp;&nbsp;&nbsp;while(cursorPosition &lt; CONSOLE_WIDTH){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SoftSerial_xmit(&#039;8&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursorPosition++;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(get0BiasRandomBit())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;linePositon++;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;linePositon--;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(linePositon &lt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;linePositon = CONSOLE_WIDTH + linePositon;
&nbsp;&nbsp;&nbsp;&nbsp;else if(linePositon &gt;= CONSOLE_WIDTH - 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;linePositon = linePositon - CONSOLE_WIDTH;
&nbsp;&nbsp;}
}

bool get0BiasRandomBit(){
&nbsp;&nbsp;if(getRandomBit()){
&nbsp;&nbsp;&nbsp;&nbsp;if(getRandomBit())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1;
&nbsp;&nbsp;}
&nbsp;&nbsp;else{
&nbsp;&nbsp;&nbsp;&nbsp;if(getRandomBit())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1;
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;
&nbsp;&nbsp;}
}

bool getRandomBit(){
&nbsp;&nbsp;ADC10CTL1 |= INCH_5;
&nbsp;&nbsp;ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON;
&nbsp;&nbsp;ADC10CTL0 |= ENC + ADC10SC;
&nbsp;&nbsp;while(ADC10CTL1 &amp; ADC10BUSY);
&nbsp;&nbsp;return ADC10MEM &amp; 0x01;
}</code></pre></p>
<p>and some example output from this code:<br />
<img src="http://naturetm.com/files/meander.gif" alt="" /></p>
<p>This sends a comma-separated list of random ints to the console:<br />
<pre><code>#include &quot;msp430g2231.h&quot;
#include &quot;config.h&quot;
#include &quot;softserial.h&quot;
#include &lt;string.h&gt;

int adcGenRand16();
void reverse(char s[]);
void itoa(int n, char s[]);
void txString(char string[]);

void main(){
&nbsp;&nbsp;int random;
&nbsp;&nbsp;char string[7];
&nbsp;&nbsp;
&nbsp;&nbsp;DCOCTL = CALDCO_16MHZ;
&nbsp;&nbsp;BCSCTL1 = CALBC1_16MHZ;
&nbsp;&nbsp;
&nbsp;&nbsp;WDTCTL = WDTPW + WDTHOLD;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Stop WDT
&nbsp;&nbsp;
&nbsp;&nbsp;SoftSerial_init();
&nbsp;&nbsp;_enable_interrupts();
&nbsp;&nbsp;
&nbsp;&nbsp;while(1){
&nbsp;&nbsp;&nbsp;&nbsp;random = adcGenRand16();
&nbsp;&nbsp;&nbsp;&nbsp;itoa(random, string);
&nbsp;&nbsp;&nbsp;&nbsp;txString(string);
&nbsp;&nbsp;}
}

void txString(char string[]){
&nbsp;&nbsp;int iString = 0;
&nbsp;&nbsp;while(string[iString] != 0){
&nbsp;&nbsp;&nbsp;&nbsp;SoftSerial_xmit(string[iString]);
&nbsp;&nbsp;&nbsp;&nbsp;iString++;
&nbsp;&nbsp;}
&nbsp;&nbsp;SoftSerial_xmit(&#039;,&#039;);
&nbsp;&nbsp;SoftSerial_xmit(&#039; &#039;);
}

int adcGenRand16(){
&nbsp;&nbsp;char bit;
&nbsp;&nbsp;unsigned int random;
&nbsp;&nbsp;
&nbsp;&nbsp;for(bit = 0; bit &lt; 16; bit++){
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL1 |= INCH_5;
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL0 |= SREF_1 + ADC10SHT_1 + REFON + ADC10ON;
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL0 |= ENC + ADC10SC;
&nbsp;&nbsp;&nbsp;&nbsp;while(ADC10CTL1 &amp; ADC10BUSY);
&nbsp;&nbsp;&nbsp;&nbsp;random &lt;&lt;= 1;
&nbsp;&nbsp;&nbsp;&nbsp;random |= (ADC10MEM &amp; 0x01);
&nbsp;&nbsp;}
&nbsp;&nbsp;return random;
}

 /* itoa:&nbsp;&nbsp;convert n to characters in s */
 void itoa(int n, char s[])
 {
&nbsp;&nbsp;&nbsp;&nbsp; int i, sign;
 
&nbsp;&nbsp;&nbsp;&nbsp; if ((sign = n) &lt; 0)&nbsp;&nbsp;/* record sign */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n = -n;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* make n positive */
&nbsp;&nbsp;&nbsp;&nbsp; i = 0;
&nbsp;&nbsp;&nbsp;&nbsp; do {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* generate digits in reverse order */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s[i++] = n % 10 + &#039;0&#039;;&nbsp;&nbsp; /* get next digit */
&nbsp;&nbsp;&nbsp;&nbsp; } while ((n /= 10) &gt; 0);&nbsp;&nbsp;&nbsp;&nbsp; /* delete it */
&nbsp;&nbsp;&nbsp;&nbsp; if (sign &lt; 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s[i++] = &#039;-&#039;;
&nbsp;&nbsp;&nbsp;&nbsp; s[i] = &#039;\0&#039;;
&nbsp;&nbsp;&nbsp;&nbsp; reverse(s);
 }
 
 /* reverse:&nbsp;&nbsp;reverse string s in place */
 void reverse(char s[])
 {
&nbsp;&nbsp;&nbsp;&nbsp; int i, j;
&nbsp;&nbsp;&nbsp;&nbsp; char c;
 
&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0, j = strlen(s)-1; i&lt;j; i++, j--) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = s[i];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s[i] = s[j];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s[j] = c;
&nbsp;&nbsp;&nbsp;&nbsp; }
 }</code></pre></p>
<p><img src="http://naturetm.com/files/randomCSL.gif" alt="" /></p>
<p>I guess I got a little sidetracked from my original purpose of getting started with the RF2500, but I had fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=174</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MIDI Synth is polyphonic</title>
		<link>http://naturetm.com/?p=158</link>
		<comments>http://naturetm.com/?p=158#comments</comments>
		<pubDate>Sun, 01 May 2011 17:28:24 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[example code]]></category>
		<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MIDI]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=158</guid>
		<description><![CDATA[I did some work on the MIDI synth to make it polyphonic. With the help of George Lucas and John Williams, I was able to win the 43oh.com April 2011 Project of the Month Contest. Check out my thread on the 43oh forums for the details and to find out what this has to do ]]></description>
				<content:encoded><![CDATA[<p>I did some work on the MIDI synth to make it polyphonic.  With the help of George Lucas and John Williams, I was able to win the <a href="http://www.43oh.com">43oh.com</a> April 2011 Project of the Month Contest.  Check out <a href="http://www.43oh.com/forum/viewtopic.php?f=9&#038;t=513&#038;start=10#p5281">my thread on the 43oh forums</a> for the details and to find out what this has to do with George Lucas.</p>
<p>It uses a <a href="http://www.sparkfun.com/products/8736">cheap DAC breakout from Sparkfun</a> and an LM386.<br />
<img alt="" src="http://naturetm.com/files/dac.jpg" title="DAC + amp schematic" class="alignnone" width="500" height="191" /></p>
<p>If you use MSP430 for fun or profit, the <a href="http://www.43oh.com/forum/">43oh forums</a> are a great resource with helpful people, so check them out!</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=158</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSP430 TV output update</title>
		<link>http://naturetm.com/?p=147</link>
		<comments>http://naturetm.com/?p=147#comments</comments>
		<pubDate>Sun, 01 May 2011 17:08:46 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[composite video]]></category>
		<category><![CDATA[example code]]></category>
		<category><![CDATA[NTSC]]></category>
		<category><![CDATA[pretty girl]]></category>
		<category><![CDATA[TV]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=147</guid>
		<description><![CDATA[Just a quick update. With the new MSP430G&#8217;s and their bigger flash space, I was able to increase the resolution of my TV output program. The resolution is now 192&#215;240. When the new 16K MSP430G&#8217;s arrive, I plan on increasing this to 384&#215;240, which will finally approach the native aspect ratio. I just had to ]]></description>
				<content:encoded><![CDATA[<p>Just a quick update.  With the new MSP430G&#8217;s and their bigger flash space, I was able to increase the resolution of <a href="http://naturetm.com/?p=47">my TV output program</a>.  The resolution is now 192&#215;240.  When the new 16K MSP430G&#8217;s arrive, I plan on increasing this to 384&#215;240, which will finally approach the native aspect ratio.</p>
<p>I just had to change a couple lines of code to get this going, and include the larger image file.  I used an MSP430G2452 with 8K flash.</p>
<p>NOTE: This should be compiled in CCS under debug mode.  Using release mode or different compilers will likely require adjustment of the software delay toward the bottom of the code.</p>
<p><a href="http://naturetm.com/files/tv_192x240.c">Here&#8217;s the code.</a></p>
<p>The example images seen below:<br />
<a href="http://naturetm.com/files/miss_nature_close.h">miss_nature_close.h</a><br />
<a href="http://naturetm.com/files/miss_nature_wide.h">miss_nature_wide.h</a><br />
<a href="http://naturetm.com/wp-content/uploads/2011/05/miss_naturetm1.jpg"><img src="http://naturetm.com/wp-content/uploads/2011/05/miss_naturetm1-300x225.jpg" alt="" title="miss_naturetm1" width="300" height="225" class="alignnone size-medium wp-image-149" /></a><br />
<a href="http://naturetm.com/wp-content/uploads/2011/05/miss_naturetm.jpg"><img src="http://naturetm.com/wp-content/uploads/2011/05/miss_naturetm-300x225.jpg" alt="" title="miss_naturetm" width="300" height="225" class="alignnone size-medium wp-image-148" /></a></p>
<p>If you want to make your own images to use, first create a 192&#215;240 monochrome bitmap.  To convert the bitmap into a header.h file, I used a program called <a href="https://forum.crystalfontz.com/showthread.php?5854-Image2Code-bitmap-to-source-code-converter">Image2Code from CrystalFontz</a>.  Use this setting to get the proper image format:<br />
<a href="http://naturetm.com/wp-content/uploads/2011/05/Image2Code_example.gif"><img src="http://naturetm.com/wp-content/uploads/2011/05/Image2Code_example-300x281.gif" alt="" title="Image2Code_example" width="300" height="281" class="alignnone size-medium wp-image-168" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=147</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Arduino-like analogRead() and timing functions for the MSP430</title>
		<link>http://naturetm.com/?p=128</link>
		<comments>http://naturetm.com/?p=128#comments</comments>
		<pubDate>Thu, 10 Mar 2011 02:58:33 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[example code]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=128</guid>
		<description><![CDATA[I saw this article on Hack a Day today for a library that supports some Arduino-like functions. I thought I&#8217;d share a couple of code snippets I have for analogRead(), millis(), and delayMillis(). The delay function on the HaD article used a software delay loop. My millis() and delayMillis() use the WDT. Here&#8217;s my take ]]></description>
				<content:encoded><![CDATA[<p>I saw <a href="http://hackaday.com/2011/03/09/header-file-brings-arduino-sketches-to-the-ti-launchpad/#comments">this article</a> on Hack a Day today for a library that supports some Arduino-like functions.  I thought I&#8217;d share a couple of code snippets I have for analogRead(), millis(), and delayMillis().  The delay function on the HaD article used a software delay loop.  My millis() and delayMillis() use the WDT.</p>
<p>Here&#8217;s my take on the time functions:</p>
<p><pre><code>
#include &quot;msp430g2231.h&quot;

#define MCLK_FREQUENCY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1000000
#define WDT_DIVIDER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;512

const unsigned long WDT_FREQUENCY = MCLK_FREQUENCY / WDT_DIVIDER;
volatile unsigned long wdtCounter = 0;

unsigned long millis(){
&nbsp;&nbsp;return wdtCounter / ((float)WDT_FREQUENCY / 1000);
}

void delayMillis(unsigned long milliseconds){
&nbsp;&nbsp;unsigned long wakeTime = wdtCounter + (milliseconds * WDT_FREQUENCY / 1000);
&nbsp;&nbsp;while(wdtCounter &lt; wakeTime);
}

void main(void){
&nbsp;&nbsp;DCOCTL = CALDCO_1MHZ;
&nbsp;&nbsp;BCSCTL1 = CALBC1_1MHZ;
&nbsp;&nbsp;WDTCTL = WDTPW + WDTTMSEL + WDTIS1;
&nbsp;&nbsp;IE1 |= WDTIE;
&nbsp;&nbsp;_BIS_SR(GIE);
&nbsp;&nbsp;
&nbsp;&nbsp;// toggle pin every second
&nbsp;&nbsp;P1DIR |= BIT0;
&nbsp;&nbsp;while(1){
&nbsp;&nbsp;&nbsp;&nbsp;P1OUT ^= BIT0;
&nbsp;&nbsp;&nbsp;&nbsp;delayMillis(1000);
&nbsp;&nbsp;}
}
&nbsp;&nbsp;&nbsp;&nbsp;
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void){
&nbsp;&nbsp;wdtCounter++;
}
</code></pre></p>
<p>And here&#8217;s the analog functions:<br />
<pre><code>
#include &quot;msp430g2231.h&quot;

#define ANALOG_PIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4

unsigned int analogRead(){
&nbsp;&nbsp;ADC10CTL0 |= ADC10SC;
&nbsp;&nbsp;while(ADC10CTL1 &amp; ADC10BUSY);
&nbsp;&nbsp;return ADC10MEM;
}

void analogPinSelect(unsigned int pin){
&nbsp;&nbsp;if(pin &lt; 8){
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL0 &amp;= ~ENC;
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL1 = pin &lt;&lt; 12;
&nbsp;&nbsp;&nbsp;&nbsp;ADC10CTL0 = ADC10ON + ENC + ADC10SHT_0;
&nbsp;&nbsp;}
}

void main(void){
&nbsp;&nbsp;unsigned int analogValue;
&nbsp;&nbsp;
&nbsp;&nbsp;DCOCTL = CALDCO_1MHZ;
&nbsp;&nbsp;BCSCTL1 = CALBC1_1MHZ;
&nbsp;&nbsp;WDTCTL = WDTPW + WDTHOLD;
&nbsp;&nbsp;
&nbsp;&nbsp;// read adc repeatedly
&nbsp;&nbsp;analogPinSelect(ANALOG_PIN);
&nbsp;&nbsp;while(1){
&nbsp;&nbsp;&nbsp;&nbsp;analogValue = analogRead();
&nbsp;&nbsp;}
}
</code></pre></p>
<p>They&#8217;re not pure Arduino, but close.</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=128</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MSP430 Launchpad Simple MIDI Synth</title>
		<link>http://naturetm.com/?p=111</link>
		<comments>http://naturetm.com/?p=111#comments</comments>
		<pubDate>Fri, 11 Feb 2011 21:55:53 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MIDI]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[example code]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=111</guid>
		<description><![CDATA[It&#8217;s been awhile since I&#8217;ve posted anything, but I&#8217;ve been working on several projects. I&#8217;ve just been feeling lazy about writing them up. I thought this one might be the most enjoyable and useful to people. I&#8217;m going to keep it short and sweet, so please comment if you have any questions. This is a ]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been awhile since I&#8217;ve posted anything, but I&#8217;ve been working on several projects.  I&#8217;ve just been feeling lazy about writing them up.  I thought this one might be the most enjoyable and useful to people.  I&#8217;m going to keep it short and sweet, so please comment if you have any questions.</p>
<p>This is a simple square wave synthesizer.  It has a standard midi interface, so it could be used with a midi keyboard or another midi controller.</p>
<p>Here&#8217;s the BOM:<br />
1x TI Launchpad or another MSP430<br />
1x 280 ohm resistor (can use internal pull-up instead)<br />
1x 220 ohm resistor<br />
1x Sharp PC900V optoisolator<br />
1x Speaker (I just bought one from RadioShack)<br />
1x MIDI female jack<br />
1X diode<br />
A midi cable and some kind of midi controller</p>
<p>You could probably get away with not using the optoisolator, but I felt like adhering to spec with the hardware.  If you want to use another MSP430, be sure it has a USI and not a USCI, or you&#8217;ll have to rewrite some of the code.  <strong>Also, the code expects to have the <a href="http://naturetm.com/?p=91">DCO calibrated</a> for 16MHz.</strong>  I think an approximation would work too, but if you&#8217;re too far off the midi clock will skew and the notes could be detuned as well.</p>
<p>The speaker gets hooked up to Launchpad ground and P1.2.</p>
<p><a href="http://naturetm.com/wp-content/uploads/2011/02/Midi-Optoisolator-schematic1.jpg"><img src="http://naturetm.com/wp-content/uploads/2011/02/Midi-Optoisolator-schematic1-300x131.jpg" alt="" title="Midi Optoisolator schematic" width="300" height="131" class="alignleft size-medium wp-image-113" /></a></p>
<p>On the software side, the USI runs constantly and oversamples the midi data from the optoisolator.  The oversampling is resolved with something like a state machine(?).  I tried to use the USI properly, but I always seem to run into issues in using it with clockless serial.  There&#8217;s probably a cleaner way to read the midi data, but it works, so I don&#8217;t mind.  It&#8217;s all yours to fix!</p>
<p>Once we&#8217;re able to read the MIDI, it&#8217;s just a matter of properly adjusting the period of TimerA, the square wave sound generator, to get the proper note.  The synth is monophonic, so some care is also taken to handle and store simultaneous on-notes.</p>
<p>Here&#8217;s the <a href='http://naturetm.com/wp-content/uploads/2011/02/main.c'>MIDI Synth main.c</a>.  This compiles on CCS.</p>
<p>By the way, you can use one optoisolator circuit to send data to multiple launchpads.  Just assign each LP a different MIDI channel by changing this line of code:<br />
#define MIDI_CHANNEL			0</p>
<p>So I hooked it up to my midi keyboard.  That was OK.  Then I downloaded some midi files and routed them through a USB &#8211; MIDI converter with Ableton Live.  Now that gave me a warm, nerdy feeling inside.<br />
Check it out:<br />
Get Back</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/HYqZNmr8zfo?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Zelda</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/0KzKj_vKYCU?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Tainted Love</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/woZjZSx0WJw?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Try Again</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/XoAJnn6tujw?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=111</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>TV Output Prototype</title>
		<link>http://naturetm.com/?p=105</link>
		<comments>http://naturetm.com/?p=105#comments</comments>
		<pubDate>Sat, 04 Dec 2010 20:44:58 +0000</pubDate>
		<dc:creator>NatureTM</dc:creator>
				<category><![CDATA[MSP430]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[composite video]]></category>
		<category><![CDATA[NTSC]]></category>
		<category><![CDATA[TV]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://naturetm.com/?p=105</guid>
		<description><![CDATA[It still needs a battery holder. I might just buy one]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://naturetm.com/wp-content/uploads/2010/12/PocketPanic.jpg"><img class="size-medium wp-image-106 aligncenter" title="TV Out Prototype" src="http://naturetm.com/wp-content/uploads/2010/12/PocketPanic-300x225.jpg" alt="" width="300" height="225" /></a><br />
It still needs a battery holder.  I might just buy one.</p>
]]></content:encoded>
			<wfw:commentRss>http://naturetm.com/?feed=rss2&#038;p=105</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
