Skip to content

Instantly share code, notes, and snippets.

@hgomersall
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgomersall/350a007980972a75859c to your computer and use it in GitHub Desktop.
Save hgomersall/350a007980972a75859c to your computer and use it in GitHub Desktop.
myhdl working multiple sim instances
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)
@hgomersall
Copy link
Author

When run with https://github.com/hgomersall/myhdl/tree/globals_free_sim the above outputs:

10 0
30 0
50 1
70 2
90 3
<class 'myhdl._SuspendSimulation'>: Simulated 100 timesteps
10 0
30 0
50 1
70 2
90 3
110 4
130 5
150 6
170 7
190 8
<class 'myhdl._SuspendSimulation'>: Simulated 200 timesteps
110 4
130 5
150 6
170 7
190 8
210 9
230 10
250 11
270 12
290 13
<class 'myhdl._SuspendSimulation'>: Simulated 200 timesteps
210 9
230 10
250 11
270 12
290 13
<class 'myhdl._SuspendSimulation'>: Simulated 100 timesteps

That is, the simulations act independently of one another.

@hgomersall
Copy link
Author

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