Technical data

Tcl/Tk and ModelSim
124
-
ModelSim EE Lessons ModelSim EE Tutorial
Press all the buttons and notice the object names in the Main transcript. Close the
image example window when you’re done.
Example 3 - The traffic li
g
ht simulation
In this example you’ll simulate an intersection with traffic lights. The simulation
interface you will create allows you to run "what if" scenarios efficiently.
Introduction of the traffic intersection widget
This portion of our example introduces the traffic intersection widget. You’ll add
other widgets to the intersection to create a custom traffic simulation environment.
Once again, make sure you have completed "Preparing for the Tcl/Tk examples"
(p121) before working this example.
1
Draw the intersection by invoking this command and procedure at the Model
Sim
prompt:
source intersection.tcl
draw_intersection
2
From the Model
Sim
prompt, use the procedure set_light_state to change the color of
the lights:
set_light_state green .traffic.i.ns_light
set_light_state green .traffic.i.ew_light
You can use the Copy and Paste buttons on the Main toolbar to help build
instructions from previous commands.
3
View the source code with this command at the Model
Sim
prompt:
notepad intersection.tcl
You can locate the
set_light_state
procedure with
Edit > Find
from the Main
menu (it’s located toward the middle of the file).
Connect traffic lights to the simulation
Using the intersection widget, you will add
when
statements to connect the lights
to the real simulation. Once the connection is made you will simulate the traffic
light controller and watch the lights change.
We'll use VSIM
when
statements to condition the simulation to call our Tcl
program when a desired simulation condition happens.