Created
January 23, 2018 01:09
-
-
Save jimmo/618bd4342822a46ed1f16bd1e67b84f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from litex.gen import * | |
# Module that toggles an LED every `cycles` clock cycles. | |
class BlinkerFlash(Module): | |
def __init__(self, led, cycles): | |
# Create a counter that can hold a value at least as big as `cycles`. | |
counter = Signal(max=cycles) | |
# Every time the counter gets to zero, toggle the LED. | |
self.sync += [ | |
If(counter == 0, | |
# Reset the counter back to `cycles`. | |
counter.eq(cycles - 1), | |
# Toggle LED. | |
led.eq(~led), | |
).Else( | |
# Otherwise (i.e. most of the time) -- decrement the counter. | |
counter.eq(counter - 1), | |
), | |
] | |
class Blinker(Module): | |
def __init__(self, platform, *args, **kwargs): | |
led1 = platform.request('user_led') | |
self.submodules.blinker = BlinkerFlash(led1, cycles=int(1e9 / platform.default_clk_period)) | |
SoC = Blinker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment