0

In my VLAB python scripts, I am repeatedly typing the same arguments for time_unit and blocking:

# nothing for a while
write_port("pwm_0.period", 0)
run(200, "ns", blocking=True)

# start a waveform  
write_port("pwm_0.period", 100)

# see it operate for 2 cycle) 
run(230, "ns", blocking=True)

# change duty cycle
write_port("pwm_0.duty", 10)
run(200, "ns", blocking=True)

# change period
write_port("pwm_0.period", 50)
run(200, "ns", blocking=True)

Is there some way I can avoid having to type

"ns", blocking=True

every time I call run() ?

GreenAsJade
  • 14,459
  • 11
  • 63
  • 98

1 Answers1

3

Yes, you can define a function that takes your specified value as an input, then adds the default suffix:

def my_run(num):
    run(num, "ns", blocking=True)

Now, instead of your above code, this would become:

# nothing for a while
write_port("pwm_0.period", 0)
my_run(200)

# start a waveform  
write_port("pwm_0.period", 100)

# see it operate for 2 cycle) 
my_run(230)

# change duty cycle
write_port("pwm_0.duty", 10)
my_run(200)

# change period
write_port("pwm_0.period", 50)
my_run(200)
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76