{"id":273,"date":"2021-06-02T19:32:46","date_gmt":"2021-06-02T18:32:46","guid":{"rendered":"https:\/\/fletch.scot\/wp\/?p=273"},"modified":"2021-06-02T19:43:08","modified_gmt":"2021-06-02T18:43:08","slug":"rotary-encoder-test-for-pic","status":"publish","type":"post","link":"https:\/\/fletch.scot\/wp\/?p=273","title":{"rendered":"Rotary Encoder Test for PIC"},"content":{"rendered":"<p>I\u2019ve been playing about making simple direct conversion receivers using an <a href=\"http:\/\/www.vk6fh.com\/vk6fh\/NE602.htm\">NE602<\/a> for the mixer. These receivers have some sort of input network for the signal captured by the aerial, mix that with a VFO and amplify the (possibly low pass filtered) audio output from the mixer.<\/p>\n<p>The \u201cclassic\u201d version uses a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Colpitts_oscillator\">Colpitt\u2019s oscillator<\/a> for the VFO. This is an analogue oscillator that feeds back via a voltage divider made by a pair of capacitors. This works well and tunes nicely and is magical in its own way. However, the tuning is quite coarse with the variable capacitors I have, and the cost of replacement variable capacitors is getting eye-watering. They can also be quite large.<\/p>\n<p>So I\u2019m trying a replacement VFO made from an <a href=\"https:\/\/www.silabs.com\/documents\/public\/data-sheets\/Si5351-B.pdf\">Si5351a clock generator<\/a>. The Si5351a will be controlled by a PIC, being my microcontroller of choice (and available in my junk box). The tuning will be done by turning a rotary encoder.\u00a0<\/p>\n<p>I had a rotary encoder of the right size in my junk box and but had no way to find out how it performs. So I wrote a small test program for a <a href=\"https:\/\/www.microchip.com\/wwwproducts\/en\/en026561\">PIC16F887<\/a> which drives the rotary encoder and shows on LEDs which way the encoder was turned, whether it was turned recently and whether the button on the encoder was pressed or not. I often use a PIC16F887 for tests like this as it has many i\/o pins that can be digital or analogue and can be pulled up at will. I don\u2019t think I\u2019ll be using it for the VFO as it is quite big (40 pins!) but I\u2019ll be able to re-use the code amended for whichever PIC is choose.<\/p>\n<p>The schematic is simple: pins on the PIC PORTB are weakly pulled-up and are used for input from the encoder. Four LEDs are connected to PORTD each with a current-limiting resistor. One is the power on LED, the others show what is happening (or what the PC thinks is happening) when you play with the encoder. All the pins are digital.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Encoder Test Schematic.png\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2021\/06\/Encoder-Test-Schematic.png\" alt=\"Encoder Test Schematic\" width=\"600\" height=\"379\" border=\"0\" \/><\/p>\n<p>The built test is shown below. The wires you can see that are not shown in the schematic are connections to allow the programming of the PIC using a <a href=\"https:\/\/www.microchip.com\/DevelopmentTools\/ProductDetails\/pg164120\">PICkit2<\/a>. Ignore the LED on the bottom left as it shouldn\u2019t be there.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Encoder Test on Breadboard.jpg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2021\/06\/Encoder-Test-on-Breadboard.jpg\" alt=\"Encoder Test on Breadboard\" width=\"600\" height=\"398\" border=\"0\" \/><\/p>\n<p>The code and make file is in this<a href=\"http:\/\/fletch.scot\/code\/encoder-test.zip\"> zip file<\/a>. Changes made at the encoder by turning the knob are seen via interrupt. The button changes are polled. The LEDs are lit (or not) in the same polling loop.<\/p>\n<p>Tune in later for the VFO itself.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been playing about making simple direct conversion receivers using an NE602 for the mixer. These receivers have some sort of input network for the signal captured by the aerial, mix that with a VFO and amplify the (possibly low pass filtered) audio output from the mixer. The \u201cclassic\u201d version uses a Colpitt\u2019s oscillator for &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/fletch.scot\/wp\/?p=273\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rotary Encoder Test for PIC&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,12],"tags":[5,34],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-programming","category-radio","tag-programming","tag-radio"],"_links":{"self":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273"}],"version-history":[{"count":4,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}