split blinker into blinker and pulser
This commit is contained in:
parent
269d05bfe2
commit
c68ec0f876
@ -1,7 +1,7 @@
|
||||
import "/nmigen_boards.icebreaker/ICEBreakerPlatform"
|
||||
import "/nmigen_dg/*"
|
||||
import "modules/blinker/Blinker"
|
||||
import "modules/blinker/Pulser"
|
||||
import "modules/pulser/Pulser"
|
||||
import "resources/pmod"
|
||||
|
||||
Top = subclass Elaboratable where
|
||||
|
@ -2,28 +2,18 @@ import "/nmigen/cli/main"
|
||||
import "/nmigen_dg/*"
|
||||
|
||||
Blinker = subclass Elaboratable where
|
||||
__init__ = ncycles pulse: False ~> None where
|
||||
__init__ = ncycles ~> None where
|
||||
@ncycles = ncycles
|
||||
@pulse = pulse
|
||||
@out = Signal!
|
||||
|
||||
elaborate = platform ~> m where with m = Module! =>
|
||||
counter = Signal$ range (@ncycles + 1)
|
||||
Sync$ Drive counter (counter - 1)
|
||||
|
||||
if @pulse =>
|
||||
sync$ drive @out LOW
|
||||
|
||||
when
|
||||
counter == 0 ,->
|
||||
sync$ drive @out (~ @out)
|
||||
sync$ drive counter @ncycles
|
||||
otherwise ,->
|
||||
sync$ drive counter (counter - 1)
|
||||
|
||||
|
||||
Pulser = bind Blinker pulse: True
|
||||
|
||||
When (counter == 0) $ ->
|
||||
Sync$ Drive @out (~ @out)
|
||||
Sync$ Drive counter @ncycles
|
||||
|
||||
if __name__ == "__main__" =>
|
||||
blinker = Blinker ncycles: 10000000
|
||||
main blinker ports: [blinker.out]
|
||||
main blinker name: "blinker" ports: [blinker.out]
|
||||
|
21
fpga/modules/pulser.dg
Normal file
21
fpga/modules/pulser.dg
Normal file
@ -0,0 +1,21 @@
|
||||
import "/nmigen/cli/main"
|
||||
import "/nmigen_dg/*"
|
||||
|
||||
Pulser = subclass Elaboratable where
|
||||
__init__ = ncycles ~> None where
|
||||
@ncycles = ncycles
|
||||
@out = Signal!
|
||||
|
||||
elaborate = platform ~> m where with m = Module! =>
|
||||
Sync$ Drive @out LOW
|
||||
|
||||
counter = Signal$ range (@ncycles + 1)
|
||||
Sync$ Drive counter (counter - 1)
|
||||
|
||||
When (counter == 0) $ ->
|
||||
Sync$ Drive @out HIGH
|
||||
Sync$ Drive counter @ncycles
|
||||
|
||||
if __name__ == "__main__" =>
|
||||
pulser = Pulser ncycles: 10000000
|
||||
main pulser name: "pulser" ports: [pulser.out]
|
Loading…
Reference in New Issue
Block a user