{"id":259,"date":"2010-03-06T17:40:13","date_gmt":"2010-03-06T21:40:13","guid":{"rendered":"http:\/\/www.braindeadprojects.com\/blog\/?p=259"},"modified":"2010-03-28T13:48:15","modified_gmt":"2010-03-28T17:48:15","slug":"pic-simulation-using-gpsim","status":"publish","type":"post","link":"http:\/\/www.braindeadprojects.com\/blog\/rf\/pic-simulation-using-gpsim\/","title":{"rendered":"PIC simulation using GPSIM"},"content":{"rendered":"<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>\n<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.\u00a0 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>\n<p>A lot has changed in 5 years.\u00a0 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>\n<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.\u00a0 <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>\n<figure id=\"attachment_260\" aria-describedby=\"caption-attachment-260\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.braindeadprojects.com\/blog\/wp-content\/gpsim-desktop.png\"><img loading=\"lazy\" decoding=\"async\" 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\" srcset=\"http:\/\/www.braindeadprojects.com\/blog\/wp-content\/gpsim-desktop-300x240.png 300w, http:\/\/www.braindeadprojects.com\/blog\/wp-content\/gpsim-desktop-1024x819.png 1024w, http:\/\/www.braindeadprojects.com\/blog\/wp-content\/gpsim-desktop.png 1280w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-260\" class=\"wp-caption-text\">My Desktop running GPSim and some test code<\/figcaption><\/figure>\n<p style=\"text-align: center;\">\n<p>SDCC is simply a Small Device targetted C compiler, so I&#8217;m not going to go into in depth\u00a0 here (see Micah&#8217;s great article above).\u00a0 <strong><em>BUT<\/em><\/strong> I did have a major issue getting it set up initially:<\/p>\n<p>The problem I experienced with SDCC was that the Gentoo Portage distributed version is 2.5.6 (as of March 2010).\u00a0 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>\n<p>My second issue getting set up\u00a0 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>\n<blockquote><p><strong>gpsim -p16f627 -c testcode.stc<\/strong><\/p>\n<p>gpsim &#8211; the GNUPIC simulator<br \/>\nversion: Release 0.23.0<\/p>\n<p>type help for help<br \/>\n**gpsim&gt; SimulationMode:51<br \/>\nFIXME gui_breadboard.cc Build<br \/>\nWARNING: command line processor named &#8220;16f627&#8221; is being ignored<br \/>\nsince the .cod file specifies the processor<br \/>\nWARNING: Ignoring the hex file &#8220;testcode.asm&#8221;<br \/>\nsince the .cod file specifies the hex code<br \/>\nRRR gui_breadboard.cc:createLabel p16f627 11 42<br \/>\nDisabling WDT<br \/>\nFIXME:  HLL files are not supported at the moment<br \/>\n**gpsim&gt; running&#8230;<br \/>\n<strong>attempt write to invalid file register<\/strong><br \/>\naddress 0x10a,   value 0x1<br \/>\ncould not decode trace type: 0x0<br \/>\n0x0000000000000066 p16f627 0x00FC 0x008A movwf  pclath<br \/>\nRead: 0x0001 from W<br \/>\nInvalid Trace entry: 0x0<\/p><\/blockquote>\n<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>\n<p>GPSIM has some nice features &#8211; stopwatch, available breakpoints,\u00a0 simulated oscilloscope probes, the ability to lay out basic logic circuits, simulated LEDs and pushbuttons, etc<\/p>\n<figure id=\"attachment_266\" aria-describedby=\"caption-attachment-266\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.braindeadprojects.com\/blog\/wp-content\/scope.png\"><img loading=\"lazy\" decoding=\"async\" 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\" srcset=\"http:\/\/www.braindeadprojects.com\/blog\/wp-content\/scope-300x234.png 300w, http:\/\/www.braindeadprojects.com\/blog\/wp-content\/scope.png 743w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-266\" class=\"wp-caption-text\">Simulated Scope Probes<\/figcaption><\/figure>\n<p style=\"text-align: center;\">\n<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>\n<p style=\"text-align: left;\"><strong>Update: 3\/28\/2010:<\/strong><\/p>\n<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.\u00a0 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>\n<p style=\"text-align: left;\">In any event, this article is meant to point out an excellent tool. Have a look at it.<\/p>\n","protected":false},"excerpt":{"rendered":"<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 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), &hellip; <a href=\"http:\/\/www.braindeadprojects.com\/blog\/rf\/pic-simulation-using-gpsim\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PIC simulation using GPSIM<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,11],"tags":[],"class_list":["post-259","post","type-post","status-publish","format-standard","hentry","category-pic-microcontrollers","category-rf"],"_links":{"self":[{"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/posts\/259"}],"collection":[{"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/comments?post=259"}],"version-history":[{"count":17,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":274,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions\/274"}],"wp:attachment":[{"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/media?parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/categories?post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.braindeadprojects.com\/blog\/wp-json\/wp\/v2\/tags?post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}