<?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>BrainDeadProjects.com &#187; PIC Microcontrollers</title>
	<atom:link href="http://www.braindeadprojects.com/blog/category/pic-microcontrollers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.braindeadprojects.com/blog</link>
	<description>A place for low-grade evil.</description>
	<lastBuildDate>Tue, 10 Aug 2010 23:56:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PIC simulation using GPSIM</title>
		<link>http://www.braindeadprojects.com/blog/rf/pic-simulation-using-gpsim/</link>
		<comments>http://www.braindeadprojects.com/blog/rf/pic-simulation-using-gpsim/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 21:40:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PIC Microcontrollers]]></category>
		<category><![CDATA[RF]]></category>

		<guid isPermaLink="false">http://www.braindeadprojects.com/blog/?p=259</guid>
		<description><![CDATA[As if I don&#8217;t have enough going on already (school, lab, work, numerous hobby projects, cigars and Tom Waits), I&#8217;ve begun modifications of one of those small radio-controlled helicopters using a PIC16f628A microcontroller. I&#8217;ve done something similar with an radio-controlled car in the past (very basic &#8220;go forward, turn, go forward, back up&#8221; stuff though), [...]]]></description>
			<content:encoded><![CDATA[<p>As if I don&#8217;t have enough going on already (school, lab, work, numerous hobby projects, cigars and Tom Waits), I&#8217;ve begun modifications of one of those small radio-controlled helicopters using a <a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010210" target="_blank">PIC16f628A</a> microcontroller.</p>
<p>I&#8217;ve done something similar with an radio-controlled car in the past (very basic &#8220;go forward, turn, go forward, back up&#8221; stuff though), but that was 5+ years ago.  My goal this time is to code a program allowing the helicopter to lift-off, turn in search of the brightest source of light, and follow it. (Have you ever seen <a href="http://www.sea-monkeys.com/" target="_blank">Sea-Monkeys</a> go crazy over a flashlight? That&#8217;s my goal here, but with a helicopter)</p>
<p>A lot has changed in 5 years.  The last time I worked on a project like this (as basic as it really is), I was using a PIC IDE on Windows 2000 (something I&#8217;ve since misplaced). I was also using the <a href="http://www.microchip.com/wwwproducts/devices.aspx?ddocname=en010230" target="_blank">PIC16f84A</a> then, a chip that&#8217;s since become less than favorable (less memory, needs an external oscillator)</p>
<p>Having migrated entirely to the <a href="http://gentoo.org" target="_blank">Linux</a> operating system (aside from a dual-boot laptop for school), I went in search of a decent C compiler and simulator &#8211; and I really lucked out.  <a href="http://sdcc.sourceforge.net/" target="_blank">SDCC</a> and <a href="http://gpsim.sourceforge.net/gpsim.html" target="_blank">GPSIM</a> were <strong>exactly</strong> what I needed. (I have to give Micah Carrick a big thanks for his <a href="http://www.micahcarrick.com/04-25-2005/pic-c-programming-linux.html" target="_blank">article</a> that steered me in this direction)</p>
<div id="attachment_260" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.braindeadprojects.com/blog/wp-content/gpsim-desktop.png"><img class="size-medium wp-image-260" title="Desktop running gpsim" src="http://www.braindeadprojects.com/blog/wp-content/gpsim-desktop-300x240.png" alt="" width="300" height="240" /></a><p class="wp-caption-text">My Desktop running GPSim and some test code</p></div>
<p style="text-align: center;">
<p>SDCC is simply a Small Device targetted C compiler, so I&#8217;m not going to go into in depth  here (see Micah&#8217;s great article above).  <strong><em>BUT</em></strong> I did have a major issue getting it set up initially:</p>
<p>The problem I experienced with SDCC was that the Gentoo Portage distributed version is 2.5.6 (as of March 2010).  Unfortunately, memory locations for individual pins on PORTA and PORTB on the PIC16f628A aren&#8217;t defined in the header files in 2.5.6. Usually, one can access them via RB[0-7], etc&#8230; So my advice is this &#8211; use the subversion distributed version of SDCC (which is presently 2.9.7)</p>
<p>My second issue getting set up  was with GPSIM. I&#8217;ve not had a chance to delve into the reasons, but for some unknown reason the version 0.23.0 and 0.24.0 wouldn&#8217;t play nice with any controller I tried:</p>
<blockquote><p><strong>gpsim -p16f627 -c testcode.stc</strong></p>
<p>gpsim &#8211; the GNUPIC simulator<br />
version: Release 0.23.0</p>
<p>type help for help<br />
**gpsim&gt; SimulationMode:51<br />
FIXME gui_breadboard.cc Build<br />
WARNING: command line processor named &#8220;16f627&#8243; is being ignored<br />
since the .cod file specifies the processor<br />
WARNING: Ignoring the hex file &#8220;testcode.asm&#8221;<br />
since the .cod file specifies the hex code<br />
RRR gui_breadboard.cc:createLabel p16f627 11 42<br />
Disabling WDT<br />
FIXME:  HLL files are not supported at the moment<br />
**gpsim&gt; running&#8230;<br />
<strong>attempt write to invalid file register</strong><br />
address 0x10a,   value 0&#215;1<br />
could not decode trace type: 0&#215;0<br />
0&#215;0000000000000066 p16f627 0x00FC 0x008A movwf  pclath<br />
Read: 0&#215;0001 from W<br />
Invalid Trace entry: 0&#215;0</p></blockquote>
<p>After flailing around trying to make gpsim happy, I finally downgraded to 0.22.0, finding that I had no issues with it.</p>
<p>GPSIM has some nice features &#8211; stopwatch, available breakpoints,  simulated oscilloscope probes, the ability to lay out basic logic circuits, simulated LEDs and pushbuttons, etc</p>
<div id="attachment_266" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.braindeadprojects.com/blog/wp-content/scope.png"><img class="size-medium wp-image-266" title="Simulated Scope probes" src="http://www.braindeadprojects.com/blog/wp-content/scope-300x234.png" alt="" width="300" height="234" /></a><p class="wp-caption-text">Simulated Scope Probes</p></div>
<p style="text-align: center;">
<p style="text-align: left;">Ok, so now I&#8217;m all set to develop. I&#8217;ll post videos of the helicopter before and after modifications, as well as a before and after test-flight shortly.</p>
<p style="text-align: left;"><strong>Update: 3/28/2010:</strong></p>
<p style="text-align: left;">Rob Pearce has infomed me that the issue above (regarding 0.2[34].0) has been now been fixed in subversion.  While writing this article on the road, perusing the bugtracker (or reporting the bug) somehow slipped my mind &#8211; my bad. Kudos for the <em>quick</em> response time (once someone actually bothered to report it).</p>
<p style="text-align: left;">In any event, this article is meant to point out an excellent tool. Have a look at it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.braindeadprojects.com/blog/rf/pic-simulation-using-gpsim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
