Last active
August 29, 2015 14:20
-
-
Save hgomersall/350a007980972a75859c to your computer and use it in GitHub Desktop.
myhdl working multiple sim instances
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 myhdl import * | |
a = Signal(intbv(0)[5:]) | |
clock = Signal(False) | |
reset = ResetSignal(False, active=True, async=False) | |
def clockgen(clock): | |
@instance | |
def clkgen(): | |
while True: | |
yield delay(10) | |
clock.next = not clock | |
return clkgen | |
def stimulus(a, clock, reset): | |
data = [0] | |
@always(clock.posedge, reset) | |
def stimulus_inst(): | |
a.next = data[0] | |
data[0] += 1 | |
return stimulus_inst | |
def printer(a, clock, reset): | |
@always_seq(clock.posedge, reset) | |
def printer_inst(): | |
print now(), a | |
return printer_inst | |
sim1 = Simulation([clockgen(clock), stimulus(a, clock, reset), | |
printer(a, clock, reset)]) | |
sim1.run(100) | |
sim2 = Simulation([clockgen(clock), stimulus(a, clock, reset), | |
printer(a, clock, reset)]) | |
sim2.run(200) | |
sim1.run(200) | |
sim2.run(100) |
For reference, myhdl 0.9 will output:
10 0
30 0
50 1
70 2
90 3
<class 'myhdl._SuspendSimulation'>: Simulated 100 timesteps
10 4
10 4
30 5
30 5
50 1
50 1
70 7
70 7
90 3
90 3
110 9
110 9
130 5
130 5
150 11
150 11
170 7
170 7
190 13
190 13
<class 'myhdl._SuspendSimulation'>: Simulated 200 timesteps
210 9
210 9
230 15
230 15
250 11
250 11
270 17
270 17
290 13
290 13
310 19
310 19
330 15
330 15
350 21
350 21
370 17
370 17
390 23
390 23
<class 'myhdl._SuspendSimulation'>: Simulated 200 timesteps
410 19
410 19
430 25
430 25
450 21
450 21
470 27
470 27
490 23
490 23
<class 'myhdl._SuspendSimulation'>: Simulated 100 timesteps
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When run with https://github.com/hgomersall/myhdl/tree/globals_free_sim the above outputs:
That is, the simulations act independently of one another.