Skip to content

Instantly share code, notes, and snippets.

@newhouseb
newhouseb / index.ts
Created July 29, 2021 14:13
Rust + AWS Lambda + Pulumi
/*
* Lambda/Web configuration
*/
const robocontrollerRole = new aws.iam.Role("robocontrollerRole", {
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "lambda.amazonaws.com" }),
});
const lambdaRole = new aws.iam.RolePolicyAttachment("executeLambdaRoleAttach", {
role: robocontrollerRole,
@newhouseb
newhouseb / make_callable.py
Last active March 18, 2021 19:57
make_callable example for nmigen
class Doubler(Elaboratable):
def __init__(self):
self.input = Signal(8)
self.output = Signal(8)
self.sync_output = Signal(8)
def inputs(self):
return [self.input]
def outputs(self):
@newhouseb
newhouseb / gray_code_5bit.py
Created March 18, 2021 02:03
1.8GHz Gray Code Oscillator/Counter
# This is a 5bit wide gray code counter using the additional parts of the CLBs in Lattice Devices to build out LUT5s.
# We can go even bigger at the cost of oscillation speed (I think this is around 1.8GHz rather than 2GHz for the 4bit version)
class AsynchronousGrayCodeCounter(Elaboratable):
def __init__(self, sync=False, domain='sync'):
self.async_gray_count = Signal(5)
self.latched_gray_count = Signal(5)
self.sync = sync
self.domain = domain
@newhouseb
newhouseb / gray_code.py
Last active August 7, 2021 23:16
2GHz Gray Code Oscillator/Counter
# This is Gray Code oscillator that can be used on Lattice ECP5 devices to measure time down to around 500ps of
# precision (with no manual placement!) using only two (!) slices.
#
# In essence how this works is that we create a self-clocking counter that runs as fast as the FPGA fabric will
# allow. If we were to do this with a traditional counter, we would have to worry about propagation delay because
# multiple bits change at a time. If you use gray-codes, however, only one bit is changing at any given time so
# there are no issues with racing signals.
#
# If you drop this in a design and wire out the highest bit of the async_gray_count signal into a spectrum
# analyzer, you will see a dominant frequency of about 125Mhz. In other words, we cycle through all 16 gray codes
@newhouseb
newhouseb / delay_line.py
Created February 21, 2021 22:46
ECP5 Delay Line with ~50ps precision
# This is an nmigen delay line for ECP5 FPGAs using the open source toolchain. It strings together a series of
# manually placed carry chains into a "thermometer." It returns a signal that's (length) long that represents
# the chain "snapshotted" at the primary clock domain (using the flip flops colocated in the slice).
#
# This can be used in a Time to Digital Converter (i.e. to measure the time between to events) or in
# an ADC by comparing (with LVDS) a signal to a reference signal.
#
# Note that the bit precision (read: delay per carry element) varies as a function of temperature. On
# a LFE5U-25F-8MG285C, I've measure delay times of approximately 43ps on average. Due to assorted reasons,
# the delay time will vary between bits and due to variations in routing (even when manually places), you might
@newhouseb
newhouseb / pll.py
Created February 3, 2021 16:26
ECP5 PLL w/ nmigen
from nmigen import *
from pprint import pprint
PFD_MIN = 3.125
PFD_MAX = 400
VCO_MIN = 400
VCO_MAX = 800
def find_pll_params(input, output):
freqs = []
@newhouseb
newhouseb / serdesio.py
Created December 16, 2020 23:19
Minimal nMigen SERDES passthrough
# Minimal nMigen code on a LFE5UM5G-25F-8BG381C (ECP5-5G Evaluation Kit) to get
# output on the TX of Channel 0 in Bank 0 straight from the FPGA fabric. The SERDES
# DCUA instance has a bajillion parameters/inputs but these are the ones you actually
# need for things to "work." Note that the output driver configuration is funky and
# I see a way weaker output drive than I expect here.
#
# Original inspiration thanks to: https://lab.ktemkin.com/post/serdes-lfps/, but wanted
# to get things working absent a larger USB3/PCIe picture.
m.submodules.dcu0 = Instance("DCUA",
@newhouseb
newhouseb / chrome_no_x.md
Last active September 19, 2019 05:05
Running Chrome[OS] without X11 on Desktop Linux

Set your build args to the following

use_ozone=true
ozone_platform_gbm=true
target_os="chromeos" # Ideally we wouldn't need this, but I think it compiles in a whole bunch of random things that otherwise are included that we need (like the compositor)

On machines with intel graphics cards, add:

@newhouseb
newhouseb / index.html
Last active October 19, 2018 20:24
Github Menus #pocketbook
<div class="metadata" style="display: none;"></div>
<div data-lang="md" data-visibility="output" data-autorun="false" class="block hide-source" data-source-visibility="hidden">
<pre class="source hljs coffeescript" contenteditable="true"><span class="hljs-comment"># Github UI</span>
</pre>
<div class="result"><h1 id="githubui">Github UI</h1></div>
</div><div data-lang="js" data-source-visibility="visible" data-result-visibility="visible" data-autorun="true" class="block"><pre class="source hljs javascript" contenteditable="true"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createOrUpdateWithId</span>(<span class="hljs-params">id, tag</span>) </span>{
<span class="hljs-keyword">return</span> <span class="hljs-built_in">document</span>.getElementById(id) || (<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">var</span> div = <span class="hljs-built_i
@newhouseb
newhouseb / index.html
Last active October 18, 2018 21:33
Editor Exploration #pocketbook
<div class="metadata" style="display: none;"></div>
<div data-lang="deps" data-source-visibility="visible" data-result-visibility="visible" data-autorun="true" class="block"><pre class="source hljs ruby" contenteditable="true"><span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/cdnjs.cloudflare.com/ajax</span><span class="hljs-regexp">/libs/ace</span><span class="hljs-regexp">/1.4.1/ace</span>.js</pre><div class="result">[object Event]</div></div><div data-lang="js" data-visibility="source" data-autorun="true" class="block">
<pre class="source hljs cs" contenteditable="true"><span class="hljs-keyword">var</span> div = document.createElement(<span class="hljs-string">'div'</span>);
div.style.width = <span class="hljs-string">"300px"</span>;
div.style.height = <span class="hljs-string">"400px"</span>;
div.innerHTML = <span class="hljs-string">"Hello"</span>
<span class="hljs-keyword">var</span> editor = ace.edit(div);
editor.setTheme(<span class="hljs-string">"ace/theme/monokai"</span>);