Instantly share code, notes, and snippets.

@cr1901 /rot.py
Last active Nov 17, 2017

Embed
What would you like to do?
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