summaryrefslogtreecommitdiff
path: root/blinky.py
blob: d43d4665f8471d0343d9a6def46a725d2500c4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from amaranth import Elaboratable, Module, Signal
from amaranth.build import Platform

from platform_alchitry_pt_v2 import AlchitryPtV2Platform


class Blinky(Elaboratable):
    def elaborate(self, platform: Platform) -> Module:
        m = Module()

        # Get the LED pins
        led = platform.request("led", 0)

        # Create a counter for timing
        counter = Signal(24)

        # Increment counter every clock cycle
        m.d.sync += counter.eq(counter + 1)

        # Connect the MSB of counter to LED (blinks at ~12Hz at 100MHz)
        m.d.comb += led.o.eq(counter[-1])

        return m


if __name__ == "__main__":
    platform = AlchitryPtV2Platform()
    platform.build(Blinky(), do_program=True)