Skip to content

Instantly share code, notes, and snippets.

@cr1901
Last active July 9, 2020 19:50
Show Gist options
  • Save cr1901/afc0442405fa4727802182ff9eac0e84 to your computer and use it in GitHub Desktop.
Save cr1901/afc0442405fa4727802182ff9eac0e84 to your computer and use it in GitHub Desktop.
Migen IceStorm Code Sample
#!/usr/bin/env python3
from migen import *
from migen.build.platforms import icestick
class Rot(Module):
def __init__(self):
self.clk_freq = 12000000
self.ready = Signal()
self.rot = Signal(4)
self.divider = Signal(max=self.clk_freq)
self.d1 = Signal()
self.d2 = Signal()
self.d3 = Signal()
self.d4 = Signal()
self.d5 = Signal()
###
self.comb += [j.eq(self.rot[i]) for i, j in enumerate([self.d1, self.d2, self.d3, self.d4])]
self.comb += [self.d5.eq(1)]
self.sync += [
If(self.ready,
If(self.divider == int(self.clk_freq) - 1,
self.divider.eq(0),
self.rot.eq(Cat(self.rot[-1], self.rot[:-1]))
).Else(
self.divider.eq(self.divider + 1)
)
).Else(
self.ready.eq(1),
self.rot.eq(1),
self.divider.eq(0)
)
]
if __name__ == "__main__":
plat = icestick.Platform()
m = Rot()
m.comb += [plat.request("user_led").eq(l) for l in [m.d1, m.d2, m.d3, m.d4, m.d5]]
plat.build(m, run=True, build_dir="rot", build_name="rot_migen")
plat.create_programmer().flash(0, "rot/rot_migen.bin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment