<?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>John Roach &#187; Coding for fun</title>
	<atom:link href="http://johnroach.info/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnroach.info</link>
	<description>Coding for life</description>
	<lastBuildDate>Wed, 18 Jan 2012 19:30:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to add images to DataGridView cell using C# and Windows Forms</title>
		<link>http://johnroach.info/2012/01/13/how-to-add-images-to-datagridview-cell-using-c-and-windows-forms/</link>
		<comments>http://johnroach.info/2012/01/13/how-to-add-images-to-datagridview-cell-using-c-and-windows-forms/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 14:14:02 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[.net framework 4]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[datagridview]]></category>
		<category><![CDATA[datatable]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows forms]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=663</guid>
		<description><![CDATA[There are many ways to skin this old cat. When choosing the way, you must first decide when should the adding of images take place. I chose to add images during sorting. Let us assume you already added some data &#8230; <a href="http://johnroach.info/2012/01/13/how-to-add-images-to-datagridview-cell-using-c-and-windows-forms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are many ways to skin this old cat. When choosing the way, you must first decide when should the adding of images take place. I chose to add images during sorting.</p>
<p>Let us assume you already added some data to gridview via datatable using ;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> dataGridView1.DataSource = siparis_tablo_guncel;</pre>
<p><!--CRLF--></div>
</div>
<p>So now you know we have a filled up dataGridView.</p>
<p>Now let us assume in the dataGridView1 we want to add images according to the data within the 6th column. So what we first need to do is to create an image column by writing;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> DataGridViewImageColumn img = <span style="color: #0000ff">new</span> DataGridViewImageColumn();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> img.Name = <span style="color: #006080">"img"</span>;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> img.HeaderText = <span style="color: #006080">"Image Column"</span>;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> img.ValuesAreIcons = <span style="color: #0000ff">true</span>;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>&nbsp; </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> dataGridView1.Columns.Add(img);</pre>
<p><!--CRLF--></div>
</div>
<p>Now we have a image column. With the name “img” with the header “Image Column” As you can see in the 5th line I have stated that my images are actually icons. The reason I did this was that I found out that icons take up less space and flickers less. You can if you want change this option as you see fit.</p>
<p>Now let us get cracking and add those images according to the columns;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">int</span> number_of_rows = dataGridView1.RowCount;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; number_of_rows; i++)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #0000ff">if</span> (dataGridView1.Rows[i].Cells[6].Value.ToString() == <span style="color: #006080">"true"</span>)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>         Icon image = SUT.Properties.Resources.succcess_icon;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         dataGridView1.Rows[i].Cells[<span style="color: #006080">"img"</span>].Value = image;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     <span style="color: #0000ff">else</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>         Icon image = SUT.Properties.Resources.cancel_icon;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>         dataGridView1.Rows[i].Cells[<span style="color: #006080">"img"</span>].Value = image;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>     }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&nbsp;</p>
<p>I hope this has been informative. Please do tell if you see any mistakes and wish to make suggestions.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2012/01/13/how-to-add-images-to-datagridview-cell-using-c-and-windows-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing node.js 0.6.2 on Fedora 16</title>
		<link>http://johnroach.info/2011/11/20/installing-node-js-0-6-2-on-fedora-16/</link>
		<comments>http://johnroach.info/2011/11/20/installing-node-js-0-6-2-on-fedora-16/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 12:07:28 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=615</guid>
		<description><![CDATA[&#160; This one was a little hard. I got lots of help so I decided to post it online since it doesn&#8217;t exist on the internet yet&#8230; I wonder why&#8230;. The simple step by step instruction: sudo yum install git &#8230; <a href="http://johnroach.info/2011/11/20/installing-node-js-0-6-2-on-fedora-16/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:NodeJS.png"><img class="zemanta-img-inserted zemanta-img-configured" title="The logo of the Node.js Project from the offic..." src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/67/NodeJS.png/300px-NodeJS.png" alt="The logo of the Node.js Project from the offic..." width="300" height="79" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
<p>This one was a little hard. I got lots of help so I decided to post it online since it doesn&#8217;t exist on the internet yet&#8230; I wonder why&#8230;.</p>
<p>The simple step by step instruction:</p>
<ol>
<li><a class="zem_slink" title="Sudo" href="http://en.wikipedia.org/wiki/Sudo" rel="wikipedia">sudo</a> <a class="zem_slink" title="Yellowdog Updater, Modified" href="http://en.wikipedia.org/wiki/Yellowdog_Updater%2C_Modified" rel="wikipedia">yum</a> install git</li>
<li><br/>
<pre name="code" class="js">
git clone --depth 1 git://github.com/joyent/node.git
</pre>
</li>
<li>cd node</li>
<li>git checkout v0.6.2</li>
<li>sudo yum install openssl-devel</li>
<li>sudo yum install <a class="zem_slink" title="GNU Compiler Collection" href="http://en.wikipedia.org/wiki/GNU_Compiler_Collection" rel="wikipedia">gcc</a> # you can skip this if you already have gcc</li>
<li>sudo yum install gcc-c++ # you can skip this if you already have gcc-c++</li>
<li>./configure       [ thank you Ed for the heads up! ]</li>
<li>make -j2</li>
<li>make install</li>
<li>export PATH=$PATH:/usr/local/bin:/usr/local #this is to add usr local to your path wher <a class="zem_slink" title="Node.js" href="http://en.wikipedia.org/wiki/Node.js" rel="wikipedia">nodejs</a> was installed</li>
<li>sudo <a class="zem_slink" title="Visudo" href="http://en.wikipedia.org/wiki/Visudo" rel="wikipedia">visudo</a></li>
<li>Find Defaults secure_path=/sbin:/bin:/usr/sbin:/usr/bin<br />
go to the end &#8220;a&#8221; for append, type &#8220;:/usr/local/bin&#8221;, ESC, &#8220;:wq&#8221;</li>
<li>curl http://npmjs.org/install.sh |sudo sh #installing npm a very good too to install nodejs packages</li>
<li>sudo yum install <a class="zem_slink" title="MongoDB" href="http://en.wikipedia.org/wiki/MongoDB" rel="wikipedia">mongodb</a> #installing mongodb</li>
<li>#go to the dir where you wish to code and use npm!!</li>
<li>npm install mongodb</li>
<li>npm install mongoose</li>
<li>npm install express</li>
<li>npm install coffee-script</li>
<li>npm install stylus</li>
<li>npm install underscore</li>
<li>npm list<br />
/home/john/someproject<br />
├── coffee-script@1.1.3<br />
├─┬ express@2.5.1<br />
│ ├─┬ connect@1.8.0<br />
│ │ └── formidable@1.0.7<br />
│ ├── mime@1.2.4<br />
│ ├── mkdirp@0.0.7<br />
│ └── qs@0.3.2<br />
├── mongodb@0.9.7-0<br />
├─┬ mongoose@2.3.13<br />
│ ├── colors@0.5.1<br />
│ ├── hooks@0.1.9<br />
│ └── mongodb@0.9.6-23<br />
├─┬ stylus@0.19.3<br />
│ ├── cssom@0.2.0<br />
│ ├── growl@1.1.0<br />
│ └── mkdirp@0.0.7<br />
└── underscore@1.2.2</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/11/20/installing-node-js-0-6-2-on-fedora-16/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Blinking lights MSP430 FG461x</title>
		<link>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/</link>
		<comments>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/#comments</comments>
		<pubDate>Sat, 14 May 2011 15:16:23 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[john roach]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[texas instruments]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=576</guid>
		<description><![CDATA[I have been working on MSP430 for sometime now. It is an TI (Texas Instruments ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles &#8230; <a href="http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:MSP430-experimenter_boards.jpg"><img title="Photo of two experimenter boards for the MSP43..." src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/71/MSP430-experimenter_boards.jpg/300px-MSP430-experimenter_boards.jpg" alt="Photo of two experimenter boards for the MSP43..." width="300" height="377" /></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>I have been working on <a class="zem_slink" title="TI MSP430" rel="wikipedia" href="http://en.wikipedia.org/wiki/TI_MSP430">MSP430</a> for sometime now. It is an TI (<a class="zem_slink" title="Texas Instruments" rel="geolocation" href="http://maps.google.com/maps?ll=32.909256,-96.751054&amp;spn=0.01,0.01&amp;q=32.909256,-96.751054 (Texas%20Instruments)&amp;t=h">Texas Instruments</a> ) chip. Very fun to play with. We are using a MSP430FG461x series experimental board. This little experimental board has all the bells and whistles one may need to create any application from a <a class="zem_slink" title="Home automation" rel="wikipedia" href="http://en.wikipedia.org/wiki/Home_automation">home automation</a> controller to a simple step-motor driver. TI provides very good documentation for this grown up toy.</p>
<p>Our first lab homework for this baby was :</p>
<blockquote><p>By using the MSP430 FG4618 Microcontroller, write a program that controls the LED #1, #2,#4.When we perpetually push the two buttons at the right bottom corner of the board, all ofthe LEDs turn on.When we push perpetually one of the buttons, only the LED #4 blinks, the others turn off.When we push no buttons, the LED #1 and #2 blinks complementarily and the LED#4 turnsoff.</p></blockquote>
<p>My biggest problem with this exercise was to find what led was connected to what port. However in the end I figured it all out.</p>
<p>Below you will find the program :</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre name="code" class="c++">#include &lt;msp430xG46x.h&gt;

void initPortPins(void);

void main(void)
{
	 WDTCTL=WDTPW + WDTHOLD;
	 initPortPins();
	 while(1) {
	 	if (P1IN == (0x00))
	 	{
			P2OUT |= 0x06;
			P5OUT |= 0x02;
		}
		else if (P1IN == 0x03)
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			P2OUT |= 0x02;
			__delay_cycles (40000);
			P2OUT &amp;= 0x00;
			P2OUT |= 0x04;
			__delay_cycles (40000);
		}
		else
		{
			P2OUT &amp;= 0x00;
			P5OUT &amp;= 0x00;
			__delay_cycles (40000);
			P5OUT |= 0x02;
			__delay_cycles (40000);
		}
	 }
};

void initPortPins(void)
{
  P1DIR = 0x00;	// Set P2.2,1 as outputs
  P5DIR = 0x02; // Set P5.1 as output
  P2DIR = 0x06; // Set P2.1 to 1
};</pre>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/05/14/blinking-lights-msp430-fg461x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing node.js and npm to a Fedora 14 PC</title>
		<link>http://johnroach.info/2011/03/16/installing-node-js-and-npm-to-a-fedora-14-pc/</link>
		<comments>http://johnroach.info/2011/03/16/installing-node-js-and-npm-to-a-fedora-14-pc/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 18:02:05 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[fedora 14]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[npm]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=558</guid>
		<description><![CDATA[Hi! Below is the step by step instructions to install the following in a Fedora 14 PC; ( no sudo yum install shortcut ) + nodejs + npm + mongo database node components + mongoose + express + coffeescript + &#8230; <a href="http://johnroach.info/2011/03/16/installing-node-js-and-npm-to-a-fedora-14-pc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi! Below is the step by step instructions to install the following in a Fedora 14 PC; ( no sudo yum install shortcut <img src='http://johnroach.info/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  )</p>
<div>+ <a class="zem_slink" title="Node.js" rel="homepage" href="http://nodejs.org/">nodejs</a></div>
<div>+ npm</div>
<div>+ mongo database</div>
<div>node components</div>
<div>+ mongoose</div>
<div>+ express</div>
<div>+ coffeescript</div>
<div>+ stylus</div>
<div>+ underscore</div>
<div><strong>Step1. </strong>Install nodejs : First download the latest nodejs and un-tar it. Than;</div>
<pre name="code">export JOBS=2 # optional, sets number of parallel commands.
./configure
make
make install</pre>
<p><strong>Step 2. </strong>Install npm :</p>
<pre name="code">sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
git clone http://github.com/isaacs/npm.git
cd npm
sudo make install</pre>
<p><strong>Step 3. </strong>So now you have npm and nodejs. The next step is to install components;</p>
<pre name="code">sudo npm install mongoose
sudo npm install express
sudo npm install coffee-script
sudo npm install stylus
sudo npm install underscore</pre>
<p>And thats all folks!! Now I have Nodejs and its components installed.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/03/16/installing-node-js-and-npm-to-a-fedora-14-pc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Image Capturing from WebCAM using OpenCV and Pygame in Python</title>
		<link>http://johnroach.info/2011/03/02/image-capturing-from-webcam-using-opencv-and-pygame-in-python/</link>
		<comments>http://johnroach.info/2011/03/02/image-capturing-from-webcam-using-opencv-and-pygame-in-python/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 16:03:29 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=545</guid>
		<description><![CDATA[I know there a lot of examples of WebCAM image capturing on the net. Mine is one of that but the main difference is that this little script here simply captures frames in a certain fps and simply saves those &#8230; <a href="http://johnroach.info/2011/03/02/image-capturing-from-webcam-using-opencv-and-pygame-in-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I know there a lot of examples of WebCAM image capturing on the net. Mine is one of that but the main difference is that this little script here simply captures frames in a certain fps and simply saves those images. There a numerous usages fro such a thing. One usage could be a script that uploads this image to a certain ftp site so you can display it in your web page. I needed this little script to follow a moving object. I did not write the whole script. You may think this as a little upgrade from <a href="http://www.jperla.com/blog/post/capturing-frames-from-a-webcam-on-linux" target="_blank">the one on the internet</a>. The script uses OpenCV and Pygame libs. Without further ado the script :</p>
<pre name="code" class="python">import pygame
import Image
from pygame.locals import *
import sys

import opencv
import cv

#this is important for capturing/displaying images
from opencv import highgui

camera = highgui.cvCreateCameraCapture(0)
i=0
def get_image():
    im = highgui.cvQueryFrame(camera)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    #convert Ipl image to PIL image
    return opencv.adaptors.Ipl2PIL(im)

fps = 25.0
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("WebCAM Demo")
screen = pygame.display.get_surface()

while True:
    events = pygame.event.get()
    for event in events:
        if event.type == QUIT or event.type == KEYDOWN:
            sys.exit(0)
    im = get_image()
    if i&gt;100:
	#allowing the camera to focus
	#auto focus is really annoying
        im.save("image_"+str(i)+"", "JPEG")
    i=i+1
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)

    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))</pre>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/03/02/image-capturing-from-webcam-using-opencv-and-pygame-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why mysql_real_escape_string() isn&#8217;t enough to stop SQL injection attacks!</title>
		<link>http://johnroach.info/2011/02/17/why-mysql_real_escape_string-isnt-enough-to-stop-sql-injection-attacks/</link>
		<comments>http://johnroach.info/2011/02/17/why-mysql_real_escape_string-isnt-enough-to-stop-sql-injection-attacks/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 11:56:11 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=536</guid>
		<description><![CDATA[We have all been there writing PHP code and trusting mysql_real_escape_string(). Alas it seems it is not enough, let us look at the example below ; $id = “0; DELETE FROM users”; $id = mysql_real_escape_string($id); // 0; DELETE FROM users &#8230; <a href="http://johnroach.info/2011/02/17/why-mysql_real_escape_string-isnt-enough-to-stop-sql-injection-attacks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have all been there writing PHP code and trusting mysql_real_escape_string(). Alas it seems it is not enough, let us look at the example below ;</p>
<pre name="code" class="php">
$id = “0; DELETE FROM users”;
$id = mysql_real_escape_string($id); // 0; DELETE FROM users
mysql_query(“SELECT * FROM users WHERE id={$id}”);
</pre>
<p>As you can see above simply using mysql_real_escape_string is not enough because the new output is in the end &#8220;0; Delete from users&#8221;.</p>
<p>However don&#8217;t fret dear reader because there is a solution! Make sure the $id is indeed only a number! This can be done by simply using the code below;</p>
<pre name="code" class="php">
$id = “123; DELETE FROM users”;
$id = (int) $id; // 123
</pre>
<div>This way any string elements will simply won&#8217;t be added the system. Now a question may arise on how to make sure you don&#8217;t get injected with attack if the parameter is in fact a string. My answer is simply : USE THE FRICKEN SQL QUOTES! Like below;</div>
<div></div>
<pre name="code" class="php">
$username = "DELETE FROM users";
$username = mysql_real_escape_string($username);
mysql_query(“SELECT * FROM users WHERE username='{$username}' ”);
</pre>
<div>The quotes will allow some protection.</div>
<div></div>
<div>I hope this helps you all! And please don&#8217;t tell newbies that mysql_real_escape_string() is enough! IT IS NOT!</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/02/17/why-mysql_real_escape_string-isnt-enough-to-stop-sql-injection-attacks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting raw data from a USB mouse in Linux using Python</title>
		<link>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/</link>
		<comments>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 07:15:32 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mice]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[raw data]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=534</guid>
		<description><![CDATA[If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got &#8230; <a href="http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got me started. Once I beautify my multiple-mouse code I will be posting it here as well. Without further ado :</p>
<pre name="code" class="py">
mouse = file('/dev/input/mouse0')
while True:
    status, dx, dy = tuple(ord(c) for c in mouse.read(3))

    def to_signed(n):
        return n - ((0x80 &#038; n) << 1)

    dx = to_signed(dx)
    dy = to_signed(dy)
    print "%#02x %d %d" % (status, dx, dy)
</pre>
<p>I hope this just made your day!</p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/02/16/getting-raw-data-from-a-usb-mouse-in-linux-using-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting VGA output using VHDL and a Spartan-3AN board</title>
		<link>http://johnroach.info/2011/01/15/getting-vga-output-using-vga-and-a-spartan-3an-board/</link>
		<comments>http://johnroach.info/2011/01/15/getting-vga-output-using-vga-and-a-spartan-3an-board/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 14:19:39 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[ele 491 end of term homework]]></category>
		<category><![CDATA[simon says]]></category>
		<category><![CDATA[spartan-3an]]></category>
		<category><![CDATA[vga]]></category>
		<category><![CDATA[vhdl]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=505</guid>
		<description><![CDATA[Hi there! Have been busy busy and busy! And you know what that means! New Code! We were given a homework to write a game for the Spartan-3AN board. Our team decided to write a Simon Says game.(http://en.wikipedia.org/wiki/Simon_(game)) I was &#8230; <a href="http://johnroach.info/2011/01/15/getting-vga-output-using-vga-and-a-spartan-3an-board/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi there! Have been busy busy and busy! And you know what that means! New Code!</p>
<p>We were given a homework to write a game for the Spartan-3AN board. Our team decided to write a Simon Says game.(<a href="http://en.wikipedia.org/wiki/Simon_(game)">http://en.wikipedia.org/wiki/Simon_(game)</a>) I was responsible for writing the <a class="zem_slink" title="Video Graphics Array" rel="wikipedia" href="http://en.wikipedia.org/wiki/Video_Graphics_Array">VGA</a> output of the program. I must say it was fun!  ( I split the post as there a lot of images in this post )</p>
<p><span id="more-505"></span></p>
<p>So there are a few things you must know first about the Spartan-3AN board. The VGA output actually looks like as below;</p>
<p><a rel="lightbox" href="http://johnroach.info/wp-content/uploads/2011/01/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="image" src="http://johnroach.info/wp-content/uploads/2011/01/image_thumb.png" border="0" alt="image" width="573" height="444" /></a></p>
<p>The top 510 Ohms is where you want your connections. You must also follow the standard connection guidelines for your UCF file. Your VGA connections must be as below;</p>
<p><a rel="lightbox" href="http://johnroach.info/wp-content/uploads/2011/01/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="image" src="http://johnroach.info/wp-content/uploads/2011/01/image_thumb1.png" border="0" alt="image" width="577" height="223" /></a></p>
<p>The other thing you must know is that the output does not has to be a <strong>std_logic_vector</strong> type unless you want lots of colors. Since the Simon Says game uses only a few colors ( 4 main colors ) I decided to go easy on the board and instead of std_logic_vector for color outputs I simply used std_logic.</p>
<p>You must always keep in mind that the <a class="zem_slink" title="Cathode ray tube" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cathode_ray_tube">CRT screen</a> acts like as below;</p>
<p><span style="color: #b91313;"> </span></p>
<p><a rel="lightbox" href="http://johnroach.info/wp-content/uploads/2011/01/image2.png"><span style="color: #e81e1e;"> </span><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="image" src="http://johnroach.info/wp-content/uploads/2011/01/image_thumb2.png" border="0" alt="image" width="577" height="893" /></a></p>
<p>Below you will find a sample code that simply paints the screen… red! Why red you may ask? Because it’s my girlfriends favorite color! <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://johnroach.info/wp-content/uploads/2011/01/wlEmoticon-smile1.png" alt="Smile" /></p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.78%; font-family: 'Courier New', courier, monospace; direction: ltr; height: 283px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> library IEEE;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> use IEEE.STD_LOGIC_1164.ALL;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span> use IEEE.STD_LOGIC_ARITH.ALL;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span> use IEEE.STD_LOGIC_UNSIGNED.ALL;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span> entity clockmodule <span style="color: #0000ff;">is</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span>   port(clk50_in  : <span style="color: #0000ff;">in</span> std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>        red_out   : <span style="color: #0000ff;">out</span> std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span>        green_out : <span style="color: #0000ff;">out</span> std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>        blue_out  : <span style="color: #0000ff;">out</span> std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>        hs_out    : <span style="color: #0000ff;">out</span> std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>        vs_out    : <span style="color: #0000ff;">out</span> std_logic);</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span> end clockmodule;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span> architecture Behavioral of clockmodule <span style="color: #0000ff;">is</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span> signal clk25              : std_logic;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span> signal horizontal_counter : std_logic_vector (9 downto 0);</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span> signal vertical_counter   : std_logic_vector (9 downto 0);</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span> begin</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span> -- generate a 25Mhz clock</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span> process (clk50_in)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span> begin</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span>   <span style="color: #0000ff;">if</span> clk50_in<span style="color: #006080;">'event and clk50_in='</span>1<span style="color: #006080;">' then</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span>     if (clk25 = '0<span style="color: #006080;">') then</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span>       clk25 &lt;= '1<span style="color: #006080;">';</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span>     else</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>       clk25 &lt;= '0<span style="color: #006080;">';</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span>     end if;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>   end if;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span> end process;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span> process (clk25)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum36" style="color: #606060;">  36:</span> begin</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum37" style="color: #606060;">  37:</span>   if clk25'<span style="color: #0000ff;">event</span> and clk25 = <span style="color: #006080;">'1'</span> then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum38" style="color: #606060;">  38:</span>     <span style="color: #0000ff;">if</span> (horizontal_counter &gt;= <span style="color: #006080;">"0010010000"</span> ) -- 144</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum39" style="color: #606060;">  39:</span>     and (horizontal_counter &lt; <span style="color: #006080;">"1100010000"</span> ) -- 784</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum40" style="color: #606060;">  40:</span>     and (vertical_counter &gt;= <span style="color: #006080;">"0000100111"</span> ) -- 39</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum41" style="color: #606060;">  41:</span>     and (vertical_counter &lt; <span style="color: #006080;">"1000000111"</span> ) -- 519</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum42" style="color: #606060;">  42:</span>     then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum43" style="color: #606060;">  43:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum44" style="color: #606060;">  44:</span>      --here you paint!!</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum45" style="color: #606060;">  45:</span>        red_out &lt;= <span style="color: #006080;">'1'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum46" style="color: #606060;">  46:</span>       green_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum47" style="color: #606060;">  47:</span>       blue_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum48" style="color: #606060;">  48:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum49" style="color: #606060;">  49:</span>     <span style="color: #0000ff;">else</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum50" style="color: #606060;">  50:</span>       red_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum51" style="color: #606060;">  51:</span>       green_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum52" style="color: #606060;">  52:</span>       blue_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum53" style="color: #606060;">  53:</span>     end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum54" style="color: #606060;">  54:</span>     <span style="color: #0000ff;">if</span> (horizontal_counter &gt; <span style="color: #006080;">"0000000000"</span> )</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum55" style="color: #606060;">  55:</span>       and (horizontal_counter &lt; <span style="color: #006080;">"0001100001"</span> ) -- 96+1</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum56" style="color: #606060;">  56:</span>     then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum57" style="color: #606060;">  57:</span>       hs_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum58" style="color: #606060;">  58:</span>     <span style="color: #0000ff;">else</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum59" style="color: #606060;">  59:</span>       hs_out &lt;= <span style="color: #006080;">'1'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum60" style="color: #606060;">  60:</span>     end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum61" style="color: #606060;">  61:</span>     <span style="color: #0000ff;">if</span> (vertical_counter &gt; <span style="color: #006080;">"0000000000"</span> )</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum62" style="color: #606060;">  62:</span>       and (vertical_counter &lt; <span style="color: #006080;">"0000000011"</span> ) -- 2+1</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum63" style="color: #606060;">  63:</span>     then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum64" style="color: #606060;">  64:</span>       vs_out &lt;= <span style="color: #006080;">'0'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum65" style="color: #606060;">  65:</span>     <span style="color: #0000ff;">else</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum66" style="color: #606060;">  66:</span>       vs_out &lt;= <span style="color: #006080;">'1'</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum67" style="color: #606060;">  67:</span>     end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum68" style="color: #606060;">  68:</span>     horizontal_counter &lt;= horizontal_counter+<span style="color: #006080;">"0000000001"</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum69" style="color: #606060;">  69:</span>     <span style="color: #0000ff;">if</span> (horizontal_counter=<span style="color: #006080;">"1100100000"</span>) then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum70" style="color: #606060;">  70:</span>       vertical_counter &lt;= vertical_counter+<span style="color: #006080;">"0000000001"</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum71" style="color: #606060;">  71:</span>       horizontal_counter &lt;= <span style="color: #006080;">"0000000000"</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum72" style="color: #606060;">  72:</span>     end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum73" style="color: #606060;">  73:</span>     <span style="color: #0000ff;">if</span> (vertical_counter=<span style="color: #006080;">"1000001001"</span>) then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum74" style="color: #606060;">  74:</span>       vertical_counter &lt;= <span style="color: #006080;">"0000000000"</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum75" style="color: #606060;">  75:</span>     end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum76" style="color: #606060;">  76:</span>   end <span style="color: #0000ff;">if</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum77" style="color: #606060;">  77:</span> end process;</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum78" style="color: #606060;">  78:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum79" style="color: #606060;">  79:</span> end Behavioral;</pre>
<p><!--CRLF--></p>
</div>
</div>
<p>Everything else is straight forward after this actually. All you have to do is to follow which point you are on. If you are good enough you can draw a simple Simon Says interface like below;</p>
<p><a rel="lightbox" href="http://johnroach.info/wp-content/uploads/2011/01/IMG_0883.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="IMG_0883" src="http://johnroach.info/wp-content/uploads/2011/01/IMG_0883_thumb.jpg" border="0" alt="IMG_0883" width="495" height="372" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2011/01/15/getting-vga-output-using-vga-and-a-spartan-3an-board/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Mid-rise type quantizer</title>
		<link>http://johnroach.info/2010/11/26/mid-rise-type-quantizer/</link>
		<comments>http://johnroach.info/2010/11/26/mid-rise-type-quantizer/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 22:45:35 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[just fun]]></category>
		<category><![CDATA[dsp]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[quantization]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=458</guid>
		<description><![CDATA[A mid-rise type quantizer for my DSP lab course. The question is as below. Generate a discrete-time sinusoidal signal x[n] with the SinSamples() function implemented in preliminary work of experiment 1, with the parameters: A=3, w=2*pi, ws=2*pi*50, .θ=0, d=2sec. Implement 3-bit &#8230; <a href="http://johnroach.info/2010/11/26/mid-rise-type-quantizer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">A mid-rise type quantizer for my DSP lab course. The question is as below.</div>
<div>Generate a discrete-time sinusoidal signal x[n] with the SinSamples() function implemented in preliminary work of experiment 1, with the parameters: A=3, w=2*pi, ws=2*pi*50, .θ=0, d=2sec. Implement 3-bit midrise type <a class="zem_slink" title="Quantization (signal processing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Quantization_%28signal_processing%29">quantizer</a>. Make the reconstruction levels be spaced so as to span the entire amplitude range of the signal. You may use the maximum amplitude of the signal in designing reconstruction levels. Plot original signal, quantized version, and <a class="zem_slink" title="Quantization error" rel="wikipedia" href="http://en.wikipedia.org/wiki/Quantization_error">quantization error</a>. Calculate output signal to noise ratio in dB (all signal to noise ratios must be calculated in dB).</div>
<p>Generate a discrete-time sinusoidal signal x[n] with the SinSamples() function implemented in preliminary work of experiment 1, with the parameters: A=3, w=2*pi, ws=2*pi*50, .θ=0, d=2seca) Implement 3-bit midrise type quantizer. Make the reconstruction levels be spaced so as to span the entire amplitude range of the signal. You may use the maximum amplitude of the signal in designing reconstruction levels. Plot original signal, quantized version, and quantization error. Calculate output signal to noise ratio in dB (all signal to noise ratios must be calculated in dB).</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">A=<span style="color: #33f;">3</span>;
w=<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>
w_s=<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span>*<span style="color: #33f;">50</span>;
d=<span style="color: #33f;">2</span>;
teta=<span style="color: #33f;">0</span>;
&nbsp;
f = w/<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span>;
T = <span style="color: #33f;">1</span>/f;
tmin = <span style="color: #33f;">0</span>;
dt = T/<span style="color: #33f;">100</span>;
dt1 = <span style="color: #33f;">1</span>/<span style="color: #080;">&#40;</span>w_s/<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
t = tmin:dt:d;
t1 = tmin:dt1:d;
x = A*<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>w*t+teta<span style="color: #080;">&#41;</span>;
x1 = A*<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>w*t1+teta<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>t,x,<span style="color:#A020F0;">'r'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">hold</span> on
<span style="color: #0000FF;">stem</span><span style="color: #080;">&#40;</span>t1,x1<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'The sampled and original signal'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'amplitude'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">hold</span> on
&nbsp;
<span style="color: #228B22;">% Quatization part (midrise)</span>
bit=<span style="color: #33f;">3</span>; <span style="color: #228B22;">%number of bits that will be used</span>
signal=x1; <span style="color: #228B22;">%get the signal</span>
m_max=<span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%find the highest magnitude used</span>
delta=<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>*m_max<span style="color: #080;">&#41;</span>/<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>^bit<span style="color: #080;">&#41;</span> ;  <span style="color: #228B22;">%our step size</span>
k_max=<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>^bit<span style="color: #080;">&#41;</span>/<span style="color: #33f;">2</span>; <span style="color: #228B22;">%how many levels we have in one side of the quatization graph</span>
<span style="color: #0000FF;">for</span> <span style="color: #0000FF;"><span style="color: #33f;">i</span></span>=<span style="color: #33f;">1</span>:<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">for</span> k=<span style="color: #33f;">0</span>:<span style="color: #33f;">1</span>:<span style="color: #080;">&#40;</span>k_max-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>
        <span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span>k*delta<span style="color: #080;">&#41;</span>&lt;=<span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&amp;&amp;<span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&lt;=<span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span>k+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>*delta<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
            <span style="color: #0000FF;">if</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>&gt;<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
                new_signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>=<span style="color: #080;">&#40;</span><span style="color: #33f;">0.5</span>+k<span style="color: #080;">&#41;</span>*delta;
            <span style="color: #0000FF;">elseif</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>&lt;<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
                new_signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>=<span style="color: #080;">&#40;</span>-<span style="color: #33f;">0.5</span>-k<span style="color: #080;">&#41;</span>*delta;
            <span style="color: #0000FF;">elseif</span><span style="color: #080;">&#40;</span>signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>==<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>    
                new_signal<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>=<span style="color: #33f;">0</span>;
            <span style="color: #0000FF;">end</span> 
        <span style="color: #0000FF;">end</span>
&nbsp;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">stem</span><span style="color: #080;">&#40;</span>t1,new_signal<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'amplitude'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">hold</span> on
&nbsp;
<span style="color: #0000FF;">error</span>=signal-new_signal;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">stem</span><span style="color: #080;">&#40;</span>t1,<span style="color: #0000FF;">error</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'amplitude'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">hold</span> on</pre></div></div>

<p>And the output is as below;</p>
<p><a href="http://johnroach.info/wp-content/uploads/2010/11/outputfordsp.png"><img class="aligncenter size-full wp-image-459" title="Output" src="http://johnroach.info/wp-content/uploads/2010/11/outputfordsp.png" alt="" width="632" height="581" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2010/11/26/mid-rise-type-quantizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plotting and finding the magnitude of a wav file in MATLAB[edited]</title>
		<link>http://johnroach.info/2010/10/20/sampling-plotting-and-finding-the-magnitude-of-a-wav-file-in-matlab/</link>
		<comments>http://johnroach.info/2010/10/20/sampling-plotting-and-finding-the-magnitude-of-a-wav-file-in-matlab/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 19:14:00 +0000</pubDate>
		<dc:creator>John Roach</dc:creator>
				<category><![CDATA[Coding for fun]]></category>
		<category><![CDATA[409]]></category>
		<category><![CDATA[ele 409]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://johnroach.info/?p=412</guid>
		<description><![CDATA[Edited: Changed code to a more correct version! The question was; Load the file sound1.wav(Download from here => ) (You would use MATLAB command ‘wavread’ to loadthis file. Use MATLAB help to learn the usage of ‘wavread’). This file contains &#8230; <a href="http://johnroach.info/2010/10/20/sampling-plotting-and-finding-the-magnitude-of-a-wav-file-in-matlab/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Edited:</strong> Changed code to a more correct version!<br />
<strong>The question was;</strong></p>
<p>Load the file sound1.wav(Download from here => <a class="downloadlink" href="http://johnroach.info/wp-content/plugins/download-monitor/download.php?id=2" title=" downloaded 125 times" >SoundWav (125)</a> ) (You would use MATLAB command ‘wavread’ to loadthis file. Use MATLAB help to learn the usage of ‘wavread’). This file contains a portion of speech waveform. Take the first 512 point the signal, plot the waveformand its magnitude spectrum.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%call it like question_8('sound1.wav')</span>
<span style="color: #0000FF;">function</span> question_8<span style="color: #080;">&#40;</span>url<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#91;</span>x,fs<span style="color: #080;">&#93;</span>=<span style="color: #0000FF;">wavread</span><span style="color: #080;">&#40;</span>url<span style="color: #080;">&#41;</span>;
new_x=x<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">512</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">stem</span><span style="color: #080;">&#40;</span>new_x<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'The sampled sound signal'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'time'</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'amplitude'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">hold</span> on
&nbsp;
&nbsp;
<span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>
N=<span style="color: #080;">&#40;</span>fs/<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>*<span style="color: #0000FF;">linspace</span><span style="color: #080;">&#40;</span>-<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">stem</span><span style="color: #080;">&#40;</span>N,<span style="color: #0000FF;">fftshift</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">fft</span><span style="color: #080;">&#40;</span>new_x<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Sampled signal at frequency-domain'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'frequency'</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'amplitude'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">end</span></pre></td></tr></table></div>

<p><a href="http://johnroach.info/wp-content/uploads/2010/10/output_edited.png"><img src="http://johnroach.info/wp-content/uploads/2010/10/output_edited.png" alt="" title="output_edited" width="617" height="655" class="aligncenter size-full wp-image-420" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://johnroach.info/2010/10/20/sampling-plotting-and-finding-the-magnitude-of-a-wav-file-in-matlab/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

