{"id":412,"date":"2011-01-29T16:44:14","date_gmt":"2011-01-29T15:44:14","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/?p=412"},"modified":"2011-01-29T16:44:14","modified_gmt":"2011-01-29T15:44:14","slug":"hardware-hacking","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2011\/01\/29\/hardware-hacking\/","title":{"rendered":"Hardware hacking"},"content":{"rendered":"<p><img decoding=\"async\" style=\"float: right; margin-left: 15px\" src=\"http:\/\/www.nobugs.org\/engineer\/pic\/misc-circuits.jpg\" alt=\"PIC circuits\" \/><br \/>\nI&#8217;ve been hardware hacking recently, back using PIC microcontrollers.  I have a few specific things I&#8217;d like to build &#8211; temperature sensor network, and metal lathe tachometer.  But so far, I&#8217;ve just been getting back up to speed with all my bits &#038; bobs.  Hardware is brutually binary.  It either works or it doesn&#8217;t.  Typically, each circuit spends an evening in &#8220;doesn&#8217;t work&#8221; and then the next evening I immediately realise my mistake and it springs into &#8220;working&#8221; mode.<\/p>\n<p>So far, I&#8217;ve built working circuits for:<\/p>\n<ul>\n<li>555 timer clocking a manual switch into a 74HC164 shift register; net result: 8 LEDs go on and off.<\/li>\n<li>16F84 PIC microcontroller with LEDs on the output pins: net result: 8 LEDs go on and off<\/li>\n<li>16F84 PIC talking to DS1820 1-wire digital temperature sensor: net result, 8 LEDs go on and off, but tell you how warm it is<\/li>\n<li>USB cable from laptop to FTDI245BM breakout board (in bitbang mode): net result, 8 LEDs go on and off.<\/li>\n<li>FTDI245 connected to L293 H-Bridge controlling a bipolar stepper motor: net result, motor spins back and forth very precisely<\/li>\n<li>Finally, 16F84 PIC talking to a <a href=\"http:\/\/www.unusualelectronics.co.uk\/shop\/index.php\">16&#215;2 LCD screen<\/a>: net result, LCD says &#8220;hello world&#8221;<\/li>\n<\/ul>\n<p>So, a reasonable wander around the world of digital electronics.  Fortunately, I still had my &#8220;no part&#8221; PIC programmer from a few years back, although it took a while to find a PC which still has a parallel port, and took even longer to remember that it had to be set to SPP mode in the bios.  Oh, and I don&#8217;t own a separate keyboard anymore, so changing BIOS settings was tricky.<\/p>\n<p>Electronics is so unforgiving compared to software.  Here&#8217;s a list of mistakes I&#8217;ve made &#8211; several times, usually:<\/p>\n<ul>\n<li>On my bench power supply, the &#8216;ground&#8217; for the 0-30v range isn&#8217;t connected to the &#8216;ground&#8217; for the 5v supply.  That stopped the programmer working for a while, since it needs ~12.6v to program the PIC.<\/li>\n<li>You must compile\/assemble PIC programs for precisely the right model of PIC that you have.  There are many variants, and HEX files produced for one don&#8217;t always work for the other<\/li>\n<li>Ensure that the configuration word on the PIC is set up right.  If you&#8217;re using a crystal oscillator, but the config word says you&#8217;re using an RC oscillator, it just won&#8217;t work.<\/li>\n<li>Ensure that the chip is the RIGHT WAY UP.  Especially when you drop it on the floor.  It appears that PICs are rather tolerant of this noobish mistake .. fortunately.<\/li>\n<li>Run your programs under gpsim first.  Several times, I added an &#8216;include&#8217; to the top of my main source file and accidentally ended up with the microcontroller executing the library functions as it&#8217;s main program.  On a simulator, this is easy to see.  IRL, it just dies silently.<\/li>\n<li>Be wary of CBLOCK sections in third-party code.  By default, they assign addresses starting at 0 to symbols.  But, the free registers on a 16F84 PIC start at 0xc, so you&#8217;ll end up trouncing system registers.<\/li>\n<li>In every circuit, have a status LED.  Set up your code to blink it twice before it tries anything complicated, and use it as an &#8220;I&#8217;m alive&#8221; indicator throughout execution.\n<\/li>\n<\/ul>\n<p> Anyhow, I now have an LCD screen working so I can get pretty output from my PIC rather than interpreting LEDs.  Plus, I&#8217;m replacing my aging 16F84&#8217;s with newer 16F88&#8217;s.  These have UARTs for serial comms, plus you can run a bootloader on them which simplifies programming greatly.  In order to retire my parallel port, I&#8217;ve ordered an FTDI232 USB< ->serial breakout board.  <\/p>\n<p>My next project is to make a tachometer to measure the spindle speed on my lathe by using a metal disc with holes drilled round the edge.  An LED shines through the hole onto a photo-transistor, and the PIC can measure the period of these pulses and hence the rotation speed.  Then, with a few input buttons to allow me to set the material diameter, the PIC can also calculate the surface speed of the rotating material.  This falls into the &#8220;kinda interesting, but not really necessary&#8221; category of projects.  In other words, perfect hobby material.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been hardware hacking recently, back using PIC microcontrollers. I have a few specific things I&#8217;d like to build &#8211; temperature sensor network, and metal lathe tachometer. But so far, I&#8217;ve just been getting back up to speed with all my bits &#038; bobs. Hardware is brutually binary. It either works or it doesn&#8217;t. Typically, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-412","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":5,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}