{"id":242,"date":"2017-02-04T20:22:42","date_gmt":"2017-02-05T00:22:42","guid":{"rendered":"http:\/\/knek-tek.me\/?p=242"},"modified":"2017-02-04T20:22:42","modified_gmt":"2017-02-05T00:22:42","slug":"max1067-library-for-arduino","status":"publish","type":"post","link":"http:\/\/knek-tek.me\/index.php\/2017\/02\/04\/max1067-library-for-arduino\/","title":{"rendered":"MAX1067 library for Arduino"},"content":{"rendered":"<p>For the <a href=\"http:\/\/knek-tek.me\/index.php\/2017\/01\/15\/laser-seismograph\/\" target=\"_blank\">laser seismograph<\/a> project, I had chosen the <a href=\"https:\/\/www.maximintegrated.com\/en\/products\/analog\/data-converters\/analog-to-digital-converters\/MAX1067.html\" target=\"_blank\"> MAX1067<\/a> analog to digital converter (ADC) to convert the analog signals coming out of the photodiodes into a digital form which could be transmitted over SPI to the microcontroller. Although I knew how SPI worked and had studied it in school, I had never actually designed and implemented a system using SPI before so I had a short learning curve. There were no code examples anywhere on the web or at Maxim (the chip manufacturer) for using this chip or its sibling the MAX1068.<\/p>\n<p>To address that lack I took the code I got working and made it in to a library for the Arduino, so that people can refer to this code example in the future. The code is available at <a href=\"https:\/\/github.com\/Erik-k\/MAX1067\" data-saferedirecturl=\"https:\/\/www.google.com\/url?hl=en&amp;q=https:\/\/github.com\/Erik-k\/MAX1067&amp;source=gmail&amp;ust=1486336051716000&amp;usg=AFQjCNH4iF-nOPEgyD-VBcWq6hGqepysWA\">https:\/\/github.com\/Erik-k\/MAX1067<\/a> . The repository includes sample code for the Arduino UNO which will run right out of the box. The only modifications necessary for running this on other devices are changing the SPI pins, most of which is handled by the Arduino libraries but you\u2019ll need to choose a GPIO to use for the EOC (End of Calculation) pin.<\/p>\n<div id=\"attachment_243\" style=\"width: 482px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/MAX1067_hookup_guide.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-243\" class=\"size-full wp-image-243\" src=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/MAX1067_hookup_guide.png\" alt=\"\" width=\"472\" height=\"406\" srcset=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/MAX1067_hookup_guide.png 472w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/MAX1067_hookup_guide-300x258.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/a><p id=\"caption-attachment-243\" class=\"wp-caption-text\">This excerpt from the datasheet shows how to hook up the chip, using the same voltage level for both analog and digital supplies (the chip can handle different voltages for each, either 5V or 3V3 logic).<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_246\" style=\"width: 799px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcode_byte_order.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-246\" class=\"size-full wp-image-246\" src=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcode_byte_order.png\" alt=\"\" width=\"789\" height=\"127\" srcset=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcode_byte_order.png 789w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcode_byte_order-300x48.png 300w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcode_byte_order-768x124.png 768w\" sizes=\"auto, (max-width: 789px) 100vw, 789px\" \/><\/a><p id=\"caption-attachment-246\" class=\"wp-caption-text\">This is the configuration register, showing the position and meaning of each bit in the byte. Gotta send this anytime you want the chip to do anything!<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_247\" style=\"width: 809px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcodes.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-247\" class=\"wp-image-247 size-full\" src=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcodes.png\" width=\"799\" height=\"883\" srcset=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcodes.png 799w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcodes-271x300.png 271w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/opcodes-768x849.png 768w\" sizes=\"auto, (max-width: 799px) 100vw, 799px\" \/><\/a><p id=\"caption-attachment-247\" class=\"wp-caption-text\">And from the next page in the datasheet, this gives an explanation of what each bit in the opcode means and how to choose the opcode to do what you want.<\/p><\/div>\n<p>The speed of the SPI communication can be increased up to a 4.8MHz clock in the SPI setup for higher data rates.<\/p>\n<p>Remember that if you are using an internal clock (the ADC will use its onboard clock), you need to be careful about the timing on the EOC pin. This is handled in the library but I point it out here to make it clear that you will need more than the normal 4 SPI pins (MOSI, MISO, CLK, SS).<\/p>\n<div id=\"attachment_244\" style=\"width: 793px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/EOC_usage.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-244\" class=\"size-full wp-image-244\" src=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/EOC_usage.png\" alt=\"\" width=\"783\" height=\"311\" srcset=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/EOC_usage.png 783w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/EOC_usage-300x119.png 300w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/EOC_usage-768x305.png 768w\" sizes=\"auto, (max-width: 783px) 100vw, 783px\" \/><\/a><p id=\"caption-attachment-244\" class=\"wp-caption-text\">End-Of-Calculation pin behavior<\/p><\/div>\n<p>With an external clock you can drive the ADC and use it without the EOC pin:<\/p>\n<div id=\"attachment_245\" style=\"width: 792px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/no_EOC_usage.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-245\" class=\"size-full wp-image-245\" src=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/no_EOC_usage.png\" alt=\"\" width=\"782\" height=\"369\" srcset=\"http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/no_EOC_usage.png 782w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/no_EOC_usage-300x142.png 300w, http:\/\/knek-tek.me\/wp-content\/uploads\/2017\/02\/no_EOC_usage-768x362.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/a><p id=\"caption-attachment-245\" class=\"wp-caption-text\">Timing with an external clock on the ADC. No EOC pin needed.<\/p><\/div>\n<p>If you use the library please give me some feedback and I welcome all pull requests on github for improvements to it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the laser seismograph project, I had chosen the MAX1067 analog to digital converter (ADC) to convert the analog signals coming out of the photodiodes into a digital form which could be transmitted over SPI to the microcontroller. Although I knew how SPI worked and had studied it in school, I had never actually designed <a class=\"read-more\" href=\"http:\/\/knek-tek.me\/index.php\/2017\/02\/04\/max1067-library-for-arduino\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-242","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":4,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":251,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions\/251"}],"wp:attachment":[{"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/knek-tek.me\/index.php\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}