Technical data

Tcl/Tk and ModelSim
6-54 ModelSim EE/SE Tutorial
source intersection.tcl
draw_intersection
2 From the ModelSim 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 ModelSim 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.
For our example, the desired condition is the state of the lights. Whenever the state
of the light in the simulation changes, we want to change the color of the light on
the screen.
4 Load the VHDL libraries you compiled in preparation for these examples using this
command at the ModelSim prompt:
vsim tb_traffic
Be sure you invoke this command before the start of the connect_lights
procedure, if you don't load the libraries, you won't have a design to simulate.
5 Connect the lights to the simulation with this command and procedure:
source lights.tcl
connect_lights
Try running the simulation now; select either run button on the intersection. Select
Break if you used the Run Forever button. Notice how the Source window opens