{"id":5623,"date":"2020-01-10T15:49:05","date_gmt":"2020-01-10T15:49:05","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=5623"},"modified":"2020-01-10T15:49:10","modified_gmt":"2020-01-10T15:49:10","slug":"ice40hx8k-ad9225-adc-with-nmigen","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2020\/01\/ice40hx8k-ad9225-adc-with-nmigen\/","title":{"rendered":"ICE40HX8K AD9225 ADC with Nmigen"},"content":{"rendered":"\n<p>This is a first stab at getting the AD9225 ADC working with the ICE48HX8K. I don&#8217;t really know my way around python or Nmigen, so these notes most likely do not represent the right way of doing things. But it somewhat works&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1507\" height=\"1458\" src=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2020\/01\/IMG_9142.jpg\" alt=\"\" class=\"wp-image-5624\"\/><\/figure>\n\n\n\n<p>The AD9225 is a part pulled from an old CCD camera. It&#8217;s a 25MSPS 12bit ADC. I&#8217;m not driving it this fast in this test, nor is the UART currently dumping all 12bits. Most likely the Resource can be better refactored so that the clock and data pins are part of the same Resource&#8230; Anyway, here&#8217;s the code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#!\/usr\/bin\/python3\n\nfrom nmigen import *\nfrom uart import *\nfrom nmigen_boards.ice40_hx8k_b_evn import *\nfrom nmigen.build import *\n\nfrom pll import PLL\n\n\nclass Top(Elaboratable):\n\n    def elaborate(self, platform):\n        # B1 is clock\n        adcclk = &#x5B; Resource(&quot;ad9225clk&quot;, 0, Pins(&quot;B1&quot;, dir=&quot;o&quot;), Attrs(IO_STANDARD=&quot;SB_LVCMOS&quot;)) ]\n\n        adc = &#x5B; Resource(&quot;ad9225&quot;, 0, Pins(&quot;B2 C1 C2 D1 D2 E2 F1 F2 G1 G2 H1&quot;, dir=&quot;i&quot;),  Attrs(IO_STANDARD=&quot;SB_LVCMOS&quot;)) ]\n        platform.add_resources(adc)\n        platform.add_resources(adcclk)\n\n        # PLL Stuff\n\n        # If you don't specify dir='-', you will experience a world\n        # of debugging pain.\n        clk_pin = platform.request(platform.default_clk, dir='-')\n\n        m = Module()\n        pll = PLL(freq_in_mhz=12, freq_out_mhz=96)\n\n        m.domains += pll.domain     # override the default 'sync' domain\n\n        timer = Signal(28)\n\n        #Connect TX to B12\n        led0 = platform.request('led', 0)\n        muart = platform.request('uart')\n        data  = platform.request('ad9225',0)\n        dataclk  = platform.request('ad9225clk',0)\n        dataA = Signal(8)\n        rdy   = Signal(1)\n\n        with m.If(timer&#x5B;25]):\n            m.d.sync += &#x5B;\n              rdy.eq(1),\n              timer.eq(0)\n            ]\n        with m.Else():\n            m.d.sync += &#x5B;\n                timer.eq(timer + 1)\n            ]\n\n        with m.If(rdy == 1):\n            m.d.sync += &#x5B;\n                rdy.eq(0)\n            ]\n\n\n        m.d.sync += &#x5B;\n            dataA.eq(data.i&#x5B;0:8] + 0x60),\n        ]\n\n        m.d.comb += &#x5B;\n            pll.clk_pin.eq(clk_pin),\n            dataclk.eq(timer&#x5B;20])\n        ]\n\n        # UART\n\n        uart = UART(divisor=10000)\n        uart.tx_o = muart.tx\n\n\n        m.d.comb += &#x5B;\n            uart.tx_data.eq(dataA),\n            uart.tx_rdy.eq(rdy)\n        ]\n\n        m.submodules += &#x5B;pll, uart]\n\n        return m\n\n\nif __name__ == '__main__':\n    platform = ICE40HX8KBEVNPlatform()\n    platform.build(Top(), do_program=True)\n\n<\/pre><\/div>\n\n\n<p>The above code should output ADC values via the FT2232. This is what I get when driving the ADC with a 0.1Hz 3v square wave. The AD9225 is running at 3.3v (analog and digital):<\/p>\n\n\n\n<p>jbnb_______________bm<code>jalaocbkbka______________ck<\/code>klbmbmam<code>oc_______________clakbobnbm<\/code>ldh______________<code>nbmblajboblald______________akbk<\/code>m<code>obmn_ka_______________cncmal]h_lelk<\/code>______________kbm_<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a first stab at getting the AD9225 ADC working with the ICE48HX8K. I don&#8217;t really know my way around python or Nmigen, so these notes most likely do not represent the right way of doing things. But it somewhat works&#8230; The AD9225 is a part pulled from an old CCD camera. It&#8217;s a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-5623","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-1sH","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=5623"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5623\/revisions"}],"predecessor-version":[{"id":5625,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5623\/revisions\/5625"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=5623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=5623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=5623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}