Monday, February 06, 2006

The Interesting Tcl Language


People pronounce Tcl as "Tickel". Tcl means Tool Command Language. Usually, you see Tcl paired with its young brother, Tk. Tk is the Tcl toolkit for building graphical user interfaces.
I was first introduced by this cool Tcl language about 3 years ago when I tried to find a solution to automate the compilation of Quartus II overnight and during the weekend. Basically, I had about twenty different Quartus II projects to compile and each of them took a few hours to complete due to the large logic usage and strict timing requirement inside the designs. If I didn't automate this process, I would be wasting my time to do the manual push-button compilation after every one or two hours of compilation, which was kind of stupid. So, that was my first purpose of using the Tcl language.

However, soon after that, I found out that the Tcl language is not merely a scripting language that is limited for automation process. It can do much more than that, such as file processing, easy interface with the PC serial port without any external DLL, easy construction of GUI, interface with a DLL written by you or others, etc. Besides that, I also found out that most of the FPGA tools like Quartus II, ISE and famous third-party simulation tool, ModelSim, provide the API and platform for you to command them in Tcl language.

One of the reasons people use Tcl language is that the script written in Tcl language works regardless of the operating system used. It saves the hassle of providing the software in different versions just to support different OS.
If you never heard about the Tcl and are interested with this Tcl language, you can go to ActiveState to download the ActiveTcl software, and it is freely distributed. There are many Tcl application examples that you can easily download from the website for reference. If you would like to know even more details about this cool language, you can read the Practical Programming in Tcl and Tk written by Brent B. Welch, Ken Jones with Jeffrey Hobbs. This Tcl/Tk bestseller comes with a CD-ROM that includes all the examples used in the book and also the ActiveTcl software which may have been outdated. This book (fourth edition) has been my Tcl/Tk bible since I start using Tcl and Tk and it still is.

8 comments:

Anonymous said...

I like the site. I am interested in using TCL with Quartus. My only experience is using TCL to define pins.

How did you learn the tool specific scripts? Could you post some example programs or links to sample programs/methods? ~ Thanks

fpgaforum said...

Hi there, thanks for visiting this site and your comment. I just notice the existence of this comment.

You are asking a typical question that most of the Quartus II users are asking. Just type "tcl" on the Altera search column in www.altera.com and you can get some examples there. The most relevant reading material for Quartus II tool specific scripts would be http://www.altera.com/literature/hb/qts/qts_qii52003.pdf

Anyway, here is a sample Tcl script that I use to automate the compilation of my Quartus II projects overnight or over the weekend. Feel free to let me know if I can provide you more information on Quartus II Tcl script.

############################################
## auto_compile.tcl
## date created : April 9, 2006
## author : http://fpgaforum.blogspot.com
############################################


###Assume that the objective of this script is to compile
###a similar project twice, one with a minimum current strength
###and the other with a maximum current strength.
###(Sometimes you need to do some characterization of the current
###strength on your hardware!)
###The final product is two sof files, one for the minimum
###current strength and the other one for the maximum
###current strength. This means that this script will also rename
###the sof file for after every compilation to avoid being overwritten
###on the next compilation cycle

###go to project folder in command prompt
### Then type quartus_sh -s
### Verify the Quartus II Version number is as targeted, if you have multiple
### versions of Quartus II on your PC
### source (This file name.tcl)

####### Auto Compilation TCL Script ############
#change the following line according to your Quartus II project folder##
##assume the 1st project that I want to compile is in the following folder
cd D:/data/project1

##This is to set the minimum current strength
set project_name project1
set revision_name project1
project_open -revision $revision_name $project_name;
set_global_assignment -name Family StratixII
set_global_assignment -name DEVICE EP2S60F1020C3ES

#some assignments to the pins. Of course, I am not going to list all
set_instance_assignment -name CURRENT_STRENGTH_NEW "MINIMUM CURRENT" -to data_bus[0]
set_instance_assignment -name CURRENT_STRENGTH_NEW "MINIMUM CURRENT" -to data_bus[1]

load_package flow
execute_flow -compile
project_close

set sof [pwd]/project1.sof
if [file exists $sof] {
file rename $sof project1_MIN.sof
} else {
puts "ERROR! RENAME $sof to project1_MIN.sof"
}

###======================================

##This is to set the maximum current strength
set project_name project1
set revision_name project1
project_open -revision $revision_name $project_name;
set_global_assignment -name Family StratixII
set_global_assignment -name DEVICE EP2S60F1020C3ES

#some assignments to the pins. Of course, I am not going to list all
set_instance_assignment -name CURRENT_STRENGTH_NEW "MAXIMUM CURRENT" -to data_bus[0]
set_instance_assignment -name CURRENT_STRENGTH_NEW "MAXIMUM CURRENT" -to data_bus[1]

load_package flow
execute_flow -compile
project_close

set sof [pwd]/project1.sof
if [file exists $sof] {
file rename $sof project1_MAX.sof
} else {
puts "ERROR! RENAME $sof to project1_MAX.sof"
}

###======================================

Anonymous said...

Hi, I am not sure if I can find anyone here, but my company looking for some FPGA engineers, esprcially in Xilinx area. Can you help? Write to me at kingbirdi@yahoo.com. Thanks.

Jon

Anonymous said...

Thank you!
[url=http://kkoltsyw.com/nawg/qsus.html]My homepage[/url] | [url=http://dnyfbwhh.com/nrtt/rlxe.html]Cool site[/url]

Anonymous said...

Good design!
My homepage | Please visit

Anonymous said...

hi
http://www.bisco-if.com/ - valium anxiety
There are plenty of medications available on the market which can help you alleviate your anxiety symptoms, and eventually phase them out once and for all.
[url=http://www.bisco-if.com/]generic diazepam[/url]
There are plenty of medications available on the market which can help you alleviate your anxiety symptoms, and eventually phase them out once and for all.
valium no prescription
Pretty amazing huh?
Valiums method of action is to suppress the CNS(Central Nervous System), slowing thought processes, and providing a more stable relaxed frame of mind.

Anonymous said...

Интересно написано....но многое остается непонятнымb

Anonymous said...

Hello. And Bye.