{"id":2648,"date":"2012-07-10T20:00:35","date_gmt":"2012-07-11T00:00:35","guid":{"rendered":"http:\/\/www.paleotechnologist.net\/?p=2648"},"modified":"2012-07-10T12:41:01","modified_gmt":"2012-07-10T16:41:01","slug":"pic-startup-debugging-techniques","status":"publish","type":"post","link":"https:\/\/www.paleotechnologist.net\/?p=2648","title":{"rendered":"PIC startup debugging techniques"},"content":{"rendered":"<p><a href=\"http:\/\/www.microchip.com\/stellent\/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=2551\" target=\"_blank\">PIC microcontrollers<\/a> are great little devices &#8212; reliable, fairly powerful, reasonably easy to use, generally available in DIP form factor, and very inexpensive. Sometimes, though, an overlooked configuration setting or a missed connection can cause a PIC-powered project to refuse to execute code.<\/p>\n<p>Here is a generic version of the troubleshooting process that I usually go through (more or less in this order) if a PIC-based project doesn&#8217;t start up after having been programmed. Going through this checklist should cover most of the common problems that will keep a PIC from running. Double-check everything &#8212; even the &#8220;obvious&#8221; things like making sure power and ground are connected.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>First, make a visual inspection of the  circuit:<\/strong><\/p>\n<ul>\n<li>Is power connected to all Vcc pins?<\/li>\n<li>Is Ground connected to all Vss pins?<\/li>\n<li>Is this the correct type of PIC for your code?<\/li>\n<li>Is the PIC seated correctly, especially if  breadboarded?<\/li>\n<li>Is the PIC in the correct orientation in the PCB or  breadboard?<\/li>\n<li>Are any of the PIC\u2019s pins bent or otherwise not making  contact?<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Next, inspect the chip configuration in MPLab:<\/strong><\/p>\n<ul>\n<li>Is the correct type of PIC selected in MPLab?<\/li>\n<li>Is the oscillator configuration set  correctly?<\/li>\n<li>Is the watchdog timer either disabled (or handled in  code)?<\/li>\n<li>Is the PWRON timer set? (This isn\u2019t strictly necessary, but  this helps ensure reliable startup)<\/li>\n<li>Is the brownout reset configuration correctly set? (This  may not be strictly necessary)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Check for correct programming procedure:<\/strong><\/p>\n<ul>\n<li>If connected to the programmer\/debugger, is ~MCLR  high?<\/li>\n<li>Was the chip successfully programmed? (Check the output messages.)<\/li>\n<li>Was it the correct program?<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Next, look over the code for common mistakes:<\/strong><\/p>\n<ul>\n<li>Is the PIC actually executing code, but all TRIS registers  are set to input?<\/li>\n<li>Did you disable all unused peripherals which share the  ports you\u2019re using?<\/li>\n<li>Did you enable all peripherals which you are  using?<\/li>\n<li>Are you using the correct definition file for this  PIC?<\/li>\n<li>Is your code going off into the weeds?<\/li>\n<li style=\"padding-left: 30px;\">If your program reaches the end of the code, is this  handled with a loop or a SLEEP instruction?<\/li>\n<li style=\"padding-left: 30px;\">Is PCLATH set correctly when executing CALLs and GOTOs to  other program pages?<\/li>\n<li style=\"padding-left: 30px;\">Is PCLATH set correctly when returning from routines in  other program pages?<\/li>\n<li style=\"padding-left: 30px;\">Does your code execute a RETURN without a corresponding  CALL?<\/li>\n<li style=\"padding-left: 30px;\">Does your code execute too many (&gt; 7) nested CALLs  (including an infinite series of them)?<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\">&nbsp;<\/p>\n<p><strong>Next, inspect the signals and voltages at the chip  pins:<\/strong><\/p>\n<ul>\n<li>Is the power at the correct voltage wrt  Ground, on all power pins?<\/li>\n<li>Is ~MCLR at Vcc (not floating, grounded, or at  Vpp)?<\/li>\n<li>Is the power clean? (try a decoupling cap or two near the  PIC power inputs)<\/li>\n<li>Using a \u2018scope or at least a logic probe, check all inputs  to the PIC (right where the pins enter the chip body). Are these signals what  you would expect to see going into the chip?<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Finally, try active debugging techniques:<\/strong><\/p>\n<ul>\n<li>Try another PIC (and remember to program  it).<\/li>\n<li>Try executing simpler code on the PIC.<\/li>\n<li>Try disconnecting as many outputs as you can (shorted  outputs could be causing a failure).<\/li>\n<li>Try running a simple, known-good piece of code written for  that same processor.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If your PIC won&#8217;t execute code, here is a list of things to check&#8230; <a href=\"https:\/\/www.paleotechnologist.net\/?p=2648\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"footnotes":""},"categories":[263,216,210,238,226,211],"tags":[412,411,321,314],"class_list":["post-2648","post","type-post","status-publish","format-standard","hentry","category-assembly","category-coding","category-digital","category-electronics","category-how-to","category-pic","tag-assembly-2","tag-debugging","tag-pic-2","tag-prototyping"],"_links":{"self":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/2648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2648"}],"version-history":[{"count":13,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/2648\/revisions"}],"predecessor-version":[{"id":3356,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/2648\/revisions\/3356"}],"wp:attachment":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}