Table of Contents Previous page Next page Index

ModelSim Documentation Bookcase

Model Technology Inc.


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 ModelSim 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 lights in the simulation change states, we want to change the color of the lights on the screen.

  1. Load the VHDL libraries you compiled in preparation for these examples using this command at the ModelSim prompt:

  2. 
    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.

  1. Connect the lights to the simulation with this command and procedure:

  2. 
    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 and indicates the next line to be executed. (If the simulator is not evaluating an executable process when the break occurs, the Source window will not open.) Only the East/West lights are working. You can make both lights work by editing the lights.tcl file.

  1. Edit lights.tcl with the notepad to add a when statement for the North/South light.

  2. 
    notepad lights.tcl 
    
    

You need to add this because the current statement is for the East/West light only. You'll find the solution commented. (Remember to change the read-only status of the file so you can edit it.)

You'll find the code commented-out toward the end of the file (use Edit >Find and look for light_ns).

  1. After you have made the changes, reload and run the simulation again.

  2. 
    source lights.tcl 
    connect_lights 
    
    

Both lights are now working.


Note: Remember, if you need to return to the original Tcl files (maybe you've edited the file and it doesn't work right) you'll find the files in the tcl_tutorial\originals directory.


Model Technology Inc.
Model Technology Incorporated
Voice: (503) 641-1340
Fax: (503)526-5410
www.model.com
sales@model.com
Table of Contents Previous page Next page Index

ModelSim