<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Idle-Logic</title>
	
	<link>http://idle-logic.com</link>
	<description>The Official Blog of Chris Zeh</description>
	<lastBuildDate>Sun, 15 Apr 2012 21:59:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Idle-logic" /><feedburner:info uri="idle-logic" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Talking to the DE0-Nano using the Virtual JTAG interface.</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/SfWzzWIEeXE/</link>
		<comments>http://idle-logic.com/2012/04/15/talking-to-the-de0-nano-using-the-virtual-jtag-interface/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 21:59:19 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[DE0-Nano]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tcl]]></category>
		<category><![CDATA[vJTAG]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[virtual jtag]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1247</guid>
		<description><![CDATA[How to communicate between a PC and a design running on the DE0-Nano using the Virtual JTAG Megafunction, a Tcl TCP/IP Server running in quartus_stp with virtually any programming language. The first thing I wondered when I got my hands on the DE0-Nano was how best to communicate with a design inside the FPGA. Initially, ]]></description>
			<content:encoded><![CDATA[<p><a href="http://idle-logic.com/wp-content/uploads/2012/04/Main1.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/Main1.png" alt="DE0-Nano to Python via TCL" title="DE0-Nano to Python via TCL" width="236" height="419" class="alignright size-full wp-image-1266 colorbox-1247" /></a><br />
<em>How to communicate between a PC and a design running on the DE0-Nano using the Virtual JTAG Megafunction, a Tcl TCP/IP Server running in quartus_stp with virtually any programming language.</em></p>
<p>The first thing I wondered when I got my hands on the DE0-Nano was how best to communicate with a design inside the FPGA. Initially, I assumed that with the USB connection onboard there would be some form of UART connected to a few of the FGPA Pins. Unfortunately, this was not the case.</p>
<p>I sent an email to the creators of the DE0-Nano, <a href="http://www.terasic.com.tw/en/">terasIC</a> asking how best to go about communicating with a design and their application engineer recommended adding a second USB connection with something like the FTDI 232RL USB to UART Bridge. </p>
<p>I was still convinced there had to be a more elegant way. Fortunately, I came across <a href="http://www.alteraforum.com/forum/showthread.php?t=32354&#038;page=3">this post</a> on the Altera forums talking about the Virtual JTAG interface. Thanks to those pointers from the ever helpful <a href="http://www.alteraforum.com/forum/member.php?u=21847">Dave</a>, the seed was planted for the solution presented below.</p>
<p><HR><br />
<H2>Virtual JTAG Example &#8211; Blinky Lights</H2><br />
To demonstrate this functionality I put together a project that uses the DE0-Nano LEDs to count from 0 to 128 in binary, all at the command of a Python script. Nothing better than some flashing lights to demonstrate a new technique.</p>
<p><iframe width="450" height="265" src="http://www.youtube.com/embed/AkjO1nSEXsY" frameborder="0" modestbranding="1" showinfo ="0" allowfullscreen ></iframe></p>
<p><H3>Download the Project Files</H3>Here I&#8217;m attaching the project files, then below I&#8217;ll discuss how everything works. I&#8217;ve uploaded the files as an <a href="https://www.google.com/search?q=restoring+Archived+Quartus+Project">Archived Quartus Project</a> (inside a ZIP file since WordPress doesn&#8217;t like .qar file types), this contains all of the Quartus Design Files (in Verilog), the Tcl Server Script and the Python File. Let me know in the comments if you would prefer the raw files outside a QAR file instead. (Or both?)</p>
<div class="greybox">Download the project here:<br />
<a style="float:left" href="http://idle-logic.com/wp-content/uploads/2012/04/vJTAG_DE0-Nano_Example.zip"><img class="cleanimg  colorbox-1247" src="http://idle-logic.com/wp-content/uploads/2010/02/box_download_48.png" alt="Download" title="Download" width="48" height="48" class="alignleft size-full wp-image-411" /></a><br />
<a href='http://idle-logic.com/wp-content/uploads/2012/04/vJTAG_DE0-Nano_Example.zip'>vJTAG_DE0-Nano_Example.zip</a><BR></p>
</div>
<p><HR><H3>Digital Design Files (Quartus Project)</H3>I&#8217;m just going to provide a quick overview of the design and not go into a step by step guide for how to recreate the project from scratch. Have a look at the two examples in the DE0-Nano <a href="http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&#038;CategoryNo=139&#038;No=593&#038;PartNo=4">User Manual</a> for very good instructions on how to create a project from start to finish.<br />
<H4>Top Level</H4>My preference is to use schematic entry for the top level design, I think this makes it easier to understand the overall functionality:<br />
<div id="attachment_1280" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/TopLevel.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/TopLevel-300x110.png" alt="Top Level Schematic" title="Top Level Schematic" width="300" height="110" class="size-medium wp-image-1280 colorbox-1247" /></a><p class="wp-caption-text">Top Level Schematic</p></div><br />
<H4>vJTAG</H4><div id="attachment_1283" class="wp-caption alignright" style="width: 160px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/vJTAG.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/vJTAG-150x150.png" alt="" title="vJTAG" width="150" height="150" class="size-thumbnail wp-image-1283 colorbox-1247" /></a><p class="wp-caption-text">vJTAG Block</p></div>The first block is the vJTAG, which is a <code>sld_virtual_jtag</code> instance generated by the Altera Megafunction Wizard.</p>
<p>The <a href="http://www.altera.com/literature/ug/ug_virtualjtag.pdf">Megafunction User Guide</a> has a great description for what this block is all about:</p>
<blockquote><p>The virtual JTAG megafunction IP gives you direct access to the JTAG control signals routed to the FPGA core logic, which gives you a fine granularity of control over the JTAG resource. This opens up the JTAG resource as a general-purpose serial communication interface. A complete Tcl API is available for sending and receiving transactions into your device during runtime. Because the JTAG pins are readily accessible during runtime, this megafunction can be an easy way to customize a JTAG scan chain internal to the device, which can be used to create debugging applications.</p></blockquote>
<p><H4>vJTAG_interface</H4><div id="attachment_1290" class="wp-caption alignright" style="width: 160px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/vJTAG_interface.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/vJTAG_interface-150x150.png" alt="" title="vJTAG_interface" width="150" height="150" class="size-thumbnail wp-image-1290 colorbox-1247" /></a><p class="wp-caption-text">vJTAG_interface</p></div>This is the block with all the brains for capturing and sending data through the vJTAG. There are two main pieces of information that come from the PC to the Virtual JTAG, an instruction register and a data register. Essentially, we are required to capture bit shifted data from the <code>tdi</code> pin while shifting out data back to the interface through the tdo pin. The <code>ir_in</code> output tells us what specific instruction is being requested. </p>
<p>In this case we configured the vJTAG to have a 1 bit wide instruction register (0 = Bypass, 1 = Capture New LED Output Settings). </p>
<p>Here is the verilog code for this block:</p>
<pre class="brush: plain; title: vJTAG_interface.v; notranslate">
module vJTAG_interface (
	input tck, tdi, aclr, ir_in,v_sdr, udr,

	output reg [6:0] LEDs,
	output reg tdo

);

reg DR0_bypass_reg; // Safeguard in case bad IR is sent through JTAG
reg [6:0] DR1; // Date, time and revision DR.  We could make separate Data Registers for each one, but

wire select_DR0 = !ir_in; // Default to 0, which is the bypass register
wire select_DR1 = ir_in; //Data Register 1 will collect the new LED Settings

always @ (posedge tck or posedge aclr)
begin
	if (aclr)
	begin
		DR0_bypass_reg &lt;= 1'b0;
		DR1 &lt;= 7'b000000;
	end
	else
	begin
		DR0_bypass_reg &lt;= tdi; //Update the Bypass Register Just in case the incoming data is not sent to DR1

		if ( v_sdr )  // VJI is in Shift DR state
			if (select_DR1) //ir_in has been set to choose DR1
					DR1 &lt;= {tdi, DR1[6:1]}; // Shifting in (and out) the data

	end
end

//Maintain the TDO Continuity
always @ (*)
begin
	if (select_DR1)
		tdo &lt;= DR1[0];
    else
		tdo &lt;= DR0_bypass_reg;
end		

//The udr signal will assert when the data has been transmitted and it's time to Update the DR
//  so copy it to the Output LED register.
//  Note that connecting the LED's to the DR1 register will cause an unwanted behavior as data is shifted through it
always @(udr)
begin
	LEDs &lt;= DR1;
end

endmodule
</pre>
<p>This code was developed and derived with the help of some <a href="http://www.alterawiki.com/wiki/FPGA_Debugging_Example_with_Sources,_Probes,_and_Virtual_JTAG">examples from the Altera Wiki</a></p>
<p><H4>Clock Blinker</H4><div id="attachment_1296" class="wp-caption aligncenter" style="width: 160px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/clk_Blinker.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/clk_Blinker-150x106.png" alt="" title="Clock Blinker" width="150" height="106" class="size-thumbnail wp-image-1296 colorbox-1247" /></a><p class="wp-caption-text">clk_blinker</p></div>This is just a small block to generate a slow blinking indicator to tell us the design has downloaded to the FPGA and has started running.</p>
<pre class="brush: plain; title: clk_blinker.v; notranslate">
module clk_blinker (
	input clk,
	output blink
);
reg [25:0] count;
always @(posedge clk)
	count &lt;= count + 1'b1;
assign blink = count[25];
endmodule
</pre>
<p><H4>LED Connector</H4><div id="attachment_1302" class="wp-caption aligncenter" style="width: 160px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/LED_Connector.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/LED_Connector-150x150.png" alt="" title="LED_Connector" width="150" height="150" class="size-thumbnail wp-image-1302 colorbox-1247" /></a><p class="wp-caption-text">LED Connector</p></div><br />
This block just rips the LED_Output bus down into the individual pin connections. I think there is an easier way to do this schematically, but this works for now.</p>
<pre class="brush: plain; title: LED_Connector.v; notranslate">
module LED_Connector(
	input [6:0]LEDs,
	output wire LED_6,
	output wire LED_5,
	output wire LED_4,
	output wire LED_3,
	output wire LED_2,
	output wire LED_1,
	output wire LED_0

);

assign LED_6 = LEDs[6];
assign LED_5 = LEDs[5];
assign LED_4 = LEDs[4];
assign LED_3 = LEDs[3];
assign LED_2 = LEDs[2];
assign LED_1 = LEDs[1];
assign LED_0 = LEDs[0];
endmodule
</pre>
<p><HR><H3>TCL TCP/IP Server</H3><br />
The functions that we use to communicate to the Virtual JTAG instance inside our design are exposed inside the <code>quartus_stp.exe</code> application. Presented below is a small Tcl script which runs in the <code>quartus_stp.exe</code> that starts a TCP/IP server and pipes data to the DE0-Nano, thus giving access to the DE0-Nano design with virtually any programming language.</p>
<pre class="brush: plain; title: TCL_Server_vJTAG_SimpleTest.tcl; notranslate">

##############################################################################################
############################# Basic vJTAG Interface ##########################################
##############################################################################################

#This portion of the script is derived from some of the examples from Altera

global usbblaster_name
global test_device
# List all available programming hardwares, and select the USBBlaster.
# (Note: this example assumes only one USBBlaster connected.)
# Programming Hardwares:
foreach hardware_name [get_hardware_names] {
#	puts $hardware_name
	if { [string match &quot;USB-Blaster*&quot; $hardware_name] } {
		set usbblaster_name $hardware_name
	}
}

puts &quot;\nSelect JTAG chain connected to $usbblaster_name.\n&quot;;

# List all devices on the chain, and select the first device on the chain.
#Devices on the JTAG chain:

foreach device_name [get_device_names -hardware_name $usbblaster_name] {
#	puts $device_name
	if { [string match &quot;@1*&quot; $device_name] } {
		set test_device $device_name
	}
}
puts &quot;\nSelect device: $test_device.\n&quot;;

# Open device
proc openport {} {
	global usbblaster_name
        global test_device
	open_device -hardware_name $usbblaster_name -device_name $test_device
}

# Close device.  Just used if communication error occurs
proc closeport { } {
	catch {device_unlock}
	catch {close_device}
}

proc set_LEDs {send_data} {
	openport
	device_lock -timeout 10000
	# Shift through DR.  Note that -dr_value is unimportant since we're not actually capturing the value inside the part, just seeing what shifts out
	puts &quot;Writing - $send_data&quot;
	device_virtual_ir_shift -instance_index 0 -ir_value 1 -no_captured_ir_value
	#set tdi [device_virtual_dr_shift -dr_value $send_data -instance_index 0  -length 7] #Use this if you want to read back the tdi while you shift in the new value
	device_virtual_dr_shift -dr_value $send_data -instance_index 0  -length 7 -no_captured_dr_value

	# Set IR back to 0, which is bypass mode
	device_virtual_ir_shift -instance_index 0 -ir_value 0 -no_captured_ir_value

	closeport

	#return $tdi
}

##############################################################################################

##############################################################################################
################################# TCP/IP Server ##############################################
##############################################################################################

#Code Dervied from Tcl Developer Exchange - http://www.tcl.tk/about/netserver.html

proc Start_Server {port} {
	set s [socket -server ConnAccept $port]
	puts &quot;Started Socket Server on port - $port&quot;
	vwait forever
}

proc ConnAccept {sock addr port} {
    global conn

    # Record the client's information

    puts &quot;Accept $sock from $addr port $port&quot;
    set conn(addr,$sock) [list $addr $port]

    # Ensure that each &quot;puts&quot; by the server
    # results in a network transmission

    fconfigure $sock -buffering line

    # Set up a callback for when the client sends data

    fileevent $sock readable [list IncomingData $sock]
}

proc IncomingData {sock} {
    global conn

    # Check end of file or abnormal connection drop,
    # then write the data to the vJTAG

    if {[eof $sock] || [catch {gets $sock line}]} {
	close $sock
	puts &quot;Close $conn(addr,$sock)&quot;
	unset conn(addr,$sock)
    } else {
	#Before the connection is closed we get an emtpy data transmission. Let's check for it and trap it
	set data_len [string length $line]
	if {$data_len != &quot;0&quot;} then {
		#Extract the First Bit
		set line [string range $line 0 6]
		#Send the vJTAG Commands to Update the LED
		set_LEDs $line
	}
    }
}

#Start thet Server at Port 2540
Start_Server 2540

##############################################################################################
</pre>
<p>In order to run this server, I recommend you create a shortcut to the <code>quartus_stp.exe</code> application, then modify the shortcut to execute this script like I&#8217;ve shown here:<br />
<div id="attachment_1311" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/Shortcut.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/Shortcut-300x204.png" alt="" title="Shortcut to Tcl TCP/IP Server" width="300" height="204" class="size-medium wp-image-1311 colorbox-1247" /></a><p class="wp-caption-text">Shortcut Example to Run Tcl TCP/IP Server</p></div></p>
<p>When you run this shortcut the device should be detected automatically, and the server will start and begin listening for connections. It should look like this:<br />
<div id="attachment_1317" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2012/04/TCL-Server.png"><img src="http://idle-logic.com/wp-content/uploads/2012/04/TCL-Server-300x188.png" alt="" title="TCL Server" width="300" height="188" class="size-medium wp-image-1317 colorbox-1247" /></a><p class="wp-caption-text">TCL Server</p></div></p>
<p><HR><H3>Python LED Counting Script</H3><br />
Here is the small script used to make a socket connection to the Tcl server, and send the binary string data to exercise the LEDs.</p>
<pre class="brush: python; title: CII_Config_LED_Counter.py; notranslate">
import socket

host = 'localhost'
port = 2540
size = 1024 

def Open(host, port):
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect(( host,port))
	return s

def Write_LED(conn,intValue):
    size = 7
    bStr_LEDValue = bin(intValue).split('0b')[1].zfill(size) #Convert from int to binary string
    conn.send(bStr_LEDValue + '\n') #Newline is required to flush the buffer on the Tcl server

conn = Open(host, port)

for val in range(0, 2**7):
    Write_LED(conn, val)

conn.close()
</pre>
<p><HR><H3>Summary</H3>This tutorial demonstrates a proof of concept for creating a communication path between almost any programming language running on your PC and your digital design running on the DE0-Nano. In this example I&#8217;ve sacrificed detail for brevity, I think you&#8217;ll find that the Virtual JTAG User Manual explains very well the operation of that block. Feel free to leave a question in the comments section below if you are looking for more detail on any portion of this posting.</p>
<p>In the next blog post I&#8217;ll show how to simulate this design in ModelSim, I think this is an excellent way to understand how the digital design works.</p>
<p>In addition, just after I finished putting this post together I stumbled across a very rigorous, and more complex example of using this Virtual JTAG, and Tcl Server. In this tutorial the author shows how to connect the Virtual JTAG to an Avalon-MM master, find it here: <a href="http://www.alterawiki.com/wiki/Using_the_USB-Blaster_as_an_SOPC/Qsys_Avalon-MM_master_Tutorial">Using the USB-Blaster as an SOPC/Qsys Avalon-MM master Tutorial</a>.</p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/SfWzzWIEeXE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2012/04/15/talking-to-the-de0-nano-using-the-virtual-jtag-interface/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2012/04/15/talking-to-the-de0-nano-using-the-virtual-jtag-interface/</feedburner:origLink></item>
		<item>
		<title>Using ModelSim with Quartus II and the DE0-Nano</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/RHR90TQ0sGU/</link>
		<comments>http://idle-logic.com/2011/12/04/using-modelsim-with-quartus-ii-and-the-de0-nano/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 22:00:48 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[DE0-Nano]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[ModelSim]]></category>
		<category><![CDATA[Cyclone IV]]></category>
		<category><![CDATA[de0-nano]]></category>
		<category><![CDATA[inverter]]></category>
		<category><![CDATA[Quartus]]></category>
		<category><![CDATA[Simulation]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1116</guid>
		<description><![CDATA[This is a tutorial to walk you through how to use Quartus II and ModelSim software together to create and analyze a simple design (an inverter), then we&#8217;ll compare the RTL and Gate-Level simulations with the results on a DE0-Nano. This tutorial assumes you have some basic experience working with Quartus II. Going through the ]]></description>
			<content:encoded><![CDATA[<p><img src="http://idle-logic.com/wp-content/uploads/2011/12/Tutorial.png" alt="" title="Tutorial" width="176" height="305" class="alignright size-full wp-image-1236 colorbox-1116" /><br />
This is a tutorial to walk you through how to use Quartus II and ModelSim software together to create and analyze a simple design (an inverter), then we&#8217;ll compare the <a href="http://en.wikipedia.org/wiki/Register_transfer_level">RTL</a> and <a href="http://en.wikipedia.org/wiki/Logic_simulation#Levels_of_abstraction">Gate-Level</a> simulations with the results on a <a href="http://idle-logic.com/2011/10/13/welcome-the-de0-nano/">DE0-Nano</a>. </p>
<p>This tutorial assumes you have some basic experience working with Quartus II. Going through the examples in the <a href="http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&#038;CategoryNo=139&#038;No=593&#038;PartNo=4">DE0-Nano User manual</a> should be sufficient.</p>
<p style="padding-bottom:0">For the tutorial, I&#8217;m using the following versions of the software:</p>
<ul>
<li><strong>Quartus II v. 11.0 Build 208</strong></li>
<li><strong>ModelSim 10.0C (Quartus 11.1) Starter Edition</strong></li>
</ul>
<p>You can see the versions of my software aren&#8217;t the same, this is probably why I have the EDA tool pathing issue described below. I recommend installing both tools at the same time, from the same release.</p>
<p style="padding-bottom:0">Note that you will have to install the ModelSim (Altera Version) software separately from Quartus, Altera&#8217;s website makes it seem like they come bundled but this is not the case.
</p>
<p><BR></p>
<hr />
<h3>First Step &#8211; Create the Design</h3>
<p>Start by creating a new project in Quartus II. When using the <code>New Project Wizard</code>, make sure to select the DE0-Nano&#8217;s FPGA which is the <code>EP4CE22F17C6</code>. Also, select the ModelSim-Altera as the simulation tool and select the format as Verilog HDL.</p>
<div id="attachment_1164" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Wizard_EDAToolSettings.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Wizard_EDAToolSettings-300x232.png" alt="" title="Wizard_EDAToolSettings" width="300" height="232" class="size-medium wp-image-1164 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<h3>Create the Inverter HDL Code</h3>
<p>Now create a new Verilog file, which you can save as SimpleInverter.v.</p>
<pre class="brush: plain; title: SimpleInverter.v; notranslate">
module SimpleInverter(
	input wire a,
	output wire a_bar
	);

	assign a_bar = ~a;

	endmodule
</pre>
<p>Now you need to set the Inverter as the TopLevel Entity</p>
<div id="attachment_1161" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Top_Level.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Top_Level-300x199.png" alt="" title="Top_Level" width="300" height="199" class="size-medium wp-image-1161 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>You&#8217;ll need to run the Analysis &#038; Synthesis portion of the compilation process to prepare the files for ModelSim<br />
<div id="attachment_1137" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/AnalysisSynthesisStart.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/AnalysisSynthesisStart-300x211.png" alt="" title="AnalysisSynthesisStart" width="300" height="211" class="size-medium wp-image-1137 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<h3>RTL Level Simulation with ModelSim</h3>
<p>Now that the HDL has been created we can start ModelSim (from within Quartus) to do the RTL verification and ensure the design works as we expect. </p>
<p>Start ModelSim using the menu: <code><strong>Tools -> Run EDA Simulation Tool -> EDA RTL Simulation</strong></code><br />
<div id="attachment_1156" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/RTLSimulation_Menu.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/RTLSimulation_Menu-300x100.png" alt="" title="RTLSimulation_Menu" width="300" height="100" class="size-medium wp-image-1156 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>If you get an error message where the path to the ModelSim software is not specified, search your C:\altera folder for the vsim.exe file. Then update the path by using the <code><strong>Tools -> Path </strong></code>menu, next set the path in the <code>EDA Tool Options </code>category</p>
<div id="attachment_1162" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/UpdatePath.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/UpdatePath-300x136.png" alt="" title="UpdatePath" width="300" height="136" class="size-medium wp-image-1162 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>It&#8217;s quite confusing the first time you use ModelSim from Quartus because after ModelSim opens it doesn&#8217;t give you any tips as to where your Inverter went. By default the Inverter is put into the &#8220;work&#8221; Library.</p>
<p>Once you find the module, double click it, or right click and start the simulation:</p>
<div id="attachment_1152" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/RDL_Simulate_Click.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/RDL_Simulate_Click-300x165.png" alt="" title="RTL_Simulate_Click" width="300" height="165" class="size-medium wp-image-1152 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Now you should see something like this:<br />
<div id="attachment_1148" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/ModelSim_RTLSimulationStart.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/ModelSim_RTLSimulationStart-300x270.png" alt="" title="ModelSim_RTLSimulationStart" width="300" height="270" class="size-medium wp-image-1148 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>If you don&#8217;t see all these windows you can bring them up from the <code><strong>Windows -> Toolbar</strong></code> menu.</p>
<h3>Create a Stimulus</h3>
<p>First thing we need to do is to create a stimulus on our input (<code>a</code>), you can right click the <code>a</code> in the <code>Objects</code> window and for this example let&#8217;s just make it a clock:<br />
<div id="attachment_1174" class="wp-caption aligncenter" style="width: 293px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/StimulusClock.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/StimulusClock-283x300.png" alt="" title="StimulusClock" width="283" height="300" class="size-medium wp-image-1174 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>Let&#8217;s make it a 20Mhz clock, so a period of 50nS, make sure to keep the lowercase &#8220;ns&#8221; or ModelSim will complain.</p>
<div id="attachment_1172" class="wp-caption aligncenter" style="width: 251px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/DefineClock1.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/DefineClock1-241x300.png" alt="" title="DefineClock" width="241" height="300" class="size-medium wp-image-1172 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Next, we&#8217;ll add the two signals (<code>a</code> and <code>a_bar</code>) to the Wave window, there are a few different ways to do this, but I prefer to just shift-select both <code>a</code> and <code>a_bar</code> and drag-drop it into the Wave window:</p>
<div id="attachment_1224" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/AddSignalsToWave.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/AddSignalsToWave-300x268.png" alt="" title="AddSignalsToWave" width="300" height="268" class="size-medium wp-image-1224 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<h3>Simulate some Time</h3>
<p>Now we need to tell ModelSim to start simulating some portion of time, so lets click the Run button after adjusting the RunLength to 200nS:</p>
<div id="attachment_1157" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Run200ns.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Run200ns-300x121.png" alt="" title="Run200ns" width="300" height="121" class="size-medium wp-image-1157 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Now you should see something like the following in the Wave window:<br />
<div id="attachment_1163" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/WaveWindow_First.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/WaveWindow_First-300x271.png" alt="" title="WaveWindow_First" width="300" height="271" class="size-medium wp-image-1163 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>We need to re-zoom the Wave window to better see the simulation:<br />
<div id="attachment_1153" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/ReZoomWave.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/ReZoomWave-300x254.png" alt="" title="ReZoomWave" width="300" height="254" class="size-medium wp-image-1153 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>You can also change the &#8220;Radix&#8221; so the values will come up as binary and not &#8220;St1&#8243; and &#8220;St0&#8243;, just shift-select both signals, right click and select Radix&#8230;</p>
<div id="attachment_1151" class="wp-caption aligncenter" style="width: 204px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/RadixMenu.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/RadixMenu-194x300.png" alt="" title="RadixMenu" width="194" height="300" class="size-medium wp-image-1151 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>And select &#8220;Binary&#8221;:<br />
<div id="attachment_1138" class="wp-caption aligncenter" style="width: 241px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/BinaryRadix.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/BinaryRadix-231x300.png" alt="" title="BinaryRadix" width="231" height="300" class="size-medium wp-image-1138 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<h3>Analyzing the signal</h3>
<p>You can zoom in on the signal easily using the CTRL+Mousewheel. Now we can see that our design is working exactly as we expect an ideal inverter to work. There is no propagation delay between <code>a</code> going high and <code>a_bar</code> going low:</p>
<div id="attachment_1146" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/IdealInverter.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/IdealInverter-300x55.png" alt="" title="IdealInverter" width="300" height="55" class="size-medium wp-image-1146 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<h3>Simulating a Real-World Inverter (Gate-Level Simulation)</h3>
<p>In order to see what a non-ideal inverter might look like, let&#8217;s jump back to Quartus.</p>
<h3>Assign pins</h3>
<p>Open the pin planner and assign the following pins:</p>
<div id="attachment_1149" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/PinPlanner.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/PinPlanner-300x177.png" alt="" title="PinPlanner" width="300" height="177" class="size-medium wp-image-1149 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Here is the location of the pins we chose:<br />
<div id="attachment_1231" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/PinSelection.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/PinSelection-300x227.png" alt="" title="PinSelection" width="300" height="227" class="size-medium wp-image-1231 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<h3>Full Compilation</h3>
<p>Now kick off a full compilation:<br />
<div id="attachment_1142" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/FullComiplation.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/FullComiplation-300x144.png" alt="" title="FullCompilation" width="300" height="144" class="size-medium wp-image-1142 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<h3>Gate Level Simulation</h3>
<p>Now that the full compilation has finished, we can run gate level simulation. This will include some of the real-world delays and give us a better expectation of how the design will really work.</p>
<p>Using the <code><strong>Tools</strong></code> menu, start the gate level simulation:</p>
<div id="attachment_1143" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelMenu.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelMenu-300x124.png" alt="" title="GateLevelMenu" width="300" height="124" class="size-medium wp-image-1143 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Next, you&#8217;ll be asked which timing model you want to use, let&#8217;s just pick the default, &#8220;Slow -6 1.2V 85 Model&#8221;, this simulates nominal core voltage at 85degC.</p>
<div id="attachment_1160" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/TimingModel.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/TimingModel-300x102.png" alt="" title="TimingModel" width="300" height="102" class="size-medium wp-image-1160 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>If you get a NativeLink error, something like &#8220;<code>error deleting "msim_transcript": permission denied.</code>&#8221; you&#8217;ll need to make sure you close your current ModelSim environment, or at least stop the current simulation.</p>
<h3>Kicking off the Gate-Level Simulation</h3>
<p>Now comes a little trick to start this simulation. If you try to begin the gate-level simulation like we did with the RTL simulation (double clicking the <code>work/SimpleInverter</code> module), you&#8217;ll be given the following error:</p>
<pre class="brush: plain; title: ; notranslate">
# Loading work.SimpleInverter
# ** Error: (vsim-3033) SimpleInverter_6_1200mv_85c_slow.vo(67): Instantiation of 'cycloneive_io_obuf' failed. The design unit was not found.
#         Region: /SimpleInverter
#         Searched libraries:
#             C:\altera\11.0sp1\simulation\modelsim\gate_work
# ** Error: (vsim-3033) SimpleInverter_6_1200mv_85c_slow.vo(77): Instantiation of 'cycloneive_io_ibuf' failed. The design unit was not found.
#         Region: /SimpleInverter
#         Searched libraries:
#             C:\altera\11.0sp1\simulation\modelsim\gate_work
# Error loading design
</pre>
<p>We need to start the simulation and tell it where to find the Cyclone IVe I/O pin library.</p>
<p>We&#8217;ll click the <code><strong>Simulate -> Start Simulation...</strong></code> menu:<br />
<div id="attachment_1158" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/StartGateLevelSim.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/StartGateLevelSim-300x174.png" alt="" title="StartGateLevelSim" width="300" height="174" class="size-medium wp-image-1158 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>In the <code>Design</code> tab, enter the <code>work.SimpleInverter</code> as the Design unit:<br />
<div id="attachment_1141" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/DesignUnit.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/DesignUnit-300x266.png" alt="" title="DesignUnit" width="300" height="266" class="size-medium wp-image-1141 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>Next we click the <code>Library</code> tab, and add the <code>cycloneive_ver</code> (&#8220;<code>ver</code>&#8221; for the verilog version of the Library). (Make sure you have the &#8220;e&#8221; after the &#8220;iv&#8221; otherwise your design will fail.)</p>
<div id="attachment_1139" class="wp-caption aligncenter" style="width: 299px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Cycloneiv_verLibrary.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Cycloneiv_verLibrary-289x300.png" alt="" title="Cycloneiv_verLibrary" width="289" height="300" class="size-medium wp-image-1139 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>After you kick off the simulation you&#8217;ll be presented with a similar ModelSim simulation as before, however there are now a few extra signals and design units. You can see the signals we care about, <code>a</code> and <code>a_bar</code> are still present.</p>
<div id="attachment_1144" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelSim.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelSim-300x213.png" alt="" title="GateLevelSim" width="300" height="213" class="size-medium wp-image-1144 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<h3>Simulate</h3>
<p>Let&#8217;s add those signals to the <code>Wave</code> window, create an input stimulus on the <code>a</code> signal and start a 200nS simulation like we did in the RTL Simulation above.</p>
<h3>Analyzing the Results</h3>
<p>Now we see a very different behavior than we saw in the RTL simulation, there is some propagation delay between <code>a</code> going high and <code>a_bar</code> going low.</p>
<div id="attachment_1145" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelSimwave.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/GateLevelSimwave-300x70.png" alt="" title="GateLevelSimwave" width="300" height="70" class="size-medium wp-image-1145 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<h3>Measuring Propagation Delay</h3>
<p>You can add a second cursor to the wave window by clicking the &#8220;<code>Insert Cursor</code>&#8221; button:<br />
<div id="attachment_1147" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/InsertCursor.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/InsertCursor-300x97.png" alt="" title="InsertCursor" width="300" height="97" class="size-medium wp-image-1147 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<p>We can see ModelSim and the Altera models are estimating a 6.7nS delay.<br />
<div id="attachment_1150" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/PropagationDelay.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/PropagationDelay-300x120.png" alt="" title="PropagationDelay" width="300" height="120" class="size-medium wp-image-1150 colorbox-1116" /></a><p class="wp-caption-text"> </p></div></p>
<hr />
<h3>Verifying in Hardware</h3>
<p>In order to verify the results given in ModelSim, I downloaded the configuration file to my DE0-Nano. Using a pulse generator and an oscilloscope I was able to collect the following data. (Data was pulled from the scope and regenerated in <a href="http://python.org/">Python</a> using <a href="http://matplotlib.sourceforge.net/">matplotlib</a>)</p>
<div id="attachment_1154" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Rising.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Rising-300x208.png" alt="" title="Rising" width="300" height="208" class="size-medium wp-image-1154 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<p>Zooming in a little closer, we can measure a propagation delay of about 6.5nS, quite close to the results given in the simulation. (My testing was done at ~30degC not the 85degC)</p>
<div id="attachment_1155" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/12/Rising_Zoom.png"><img src="http://idle-logic.com/wp-content/uploads/2011/12/Rising_Zoom-300x208.png" alt="" title="Rising_Zoom" width="300" height="208" class="size-medium wp-image-1155 colorbox-1116" /></a><p class="wp-caption-text"> </p></div>
<hr />
<p>In this tutorial, we&#8217;ve covered the basics of running simulations in ModelSim of designs created in Quartus II. Let me know if this was useful and informative, or if I&#8217;ve left anything important out.</p>
<p>Further Reading:<br />
<a href="http://web.mit.edu/6.111/www/s2005/guides/ModelSim_tutorial.pdf">MIT ModelSim Tutorial (Introductory Digital Systems Laboratory)</a></p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/RHR90TQ0sGU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/12/04/using-modelsim-with-quartus-ii-and-the-de0-nano/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/12/04/using-modelsim-with-quartus-ii-and-the-de0-nano/</feedburner:origLink></item>
		<item>
		<title>Welcome the DE0-Nano</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/0sQfoevN5jM/</link>
		<comments>http://idle-logic.com/2011/10/13/welcome-the-de0-nano/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 19:18:23 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[DE0-Nano]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[adc]]></category>
		<category><![CDATA[cyclone]]></category>
		<category><![CDATA[de0-nano]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1076</guid>
		<description><![CDATA[My posting this summer, due to outside obligations, has been ridiculously sparse. (Literally &#8216;outside obligations&#8217;: I&#8217;ve been landscaping my yard all summer). I&#8217;m starting to have a little more idle time now that the summer is winding down, and now my motivation has been completely revitalized by this little guy: The DE0-Nano development board from ]]></description>
			<content:encoded><![CDATA[<p>My posting this summer, due to outside obligations, has been ridiculously sparse. (Literally &#8216;outside obligations&#8217;: I&#8217;ve been landscaping my yard all summer). I&#8217;m starting to have a little more idle time now that the summer is winding down, and now my motivation has been completely revitalized by this little guy:</p>
<div id="attachment_1096" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/10/de0-nano.jpg"><img src="http://idle-logic.com/wp-content/uploads/2011/10/de0-nano-300x221.jpg" alt="" title="de0-nano" width="300" height="221" class="size-medium wp-image-1096 colorbox-1076" /></a><p class="wp-caption-text"> </p></div>
<p>The DE0-Nano development board from Terasic. This little guy is exactly what I was aiming for with my <a href="http://idle-logic.com/2010/02/03/introducing-the-saturn-project/">Saturn Project</a>. Looking at everything they pack in here for $79, I don&#8217;t think there was anyway I could have competed. I&#8217;m getting the feeling FPGA development in the hobby-space is still pretty limited, especially with the Cyclone II Breakout board being <a href="http://idle-logic.com/2011/08/04/sparkfun-retires-cyclone-ii-breakout-board/">discontinued</a>.</p>
<p>Follow <a href="http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&#038;CategoryNo=139&#038;No=593&#038;PartNo=2">this link</a> to get the full specs on the board, but for a quick summary:</p>
<h4>DE0-Nano Development and Education Board</h4>
<ul>
<li>Cyclone® IV FPGA</li>
<li>On-board USB-Blaster circuit for programming</li>
<li>Altera serial configuration device – EPCS16</li>
<li>Two 40-pin Headers (GPIOs) provides 72 I/O pins</li>
<li>One 26-pin Header </li>
<li>32MB SDRAM</li>
<li>2Kb I2C EEPROM</li>
<li>8 green LEDs</li>
<li>2 debounced push-buttons</li>
<li>4 dip switches </li>
<li>3-axis accelerometer </li>
<li>8-Channel, 12-bit A/D Converter</li>
</ul>
<p>If you want to pick up one of these for yourself you have a few different options. From what I&#8217;ve read on various forums it&#8217;s really difficult (and actually more expensive in the end) to order directly from Terasic and ship to the US. <a href="http://alteraforum.org/forum/showthread.php?p=116036">Apparently</a>, you have to pay with a money order and the shipping options are pretty limited out of Taiwan.</p>
<p>Another option is to cruise on over to <a href="http://www.adafruit.com/products/451">Adafruit</a>, they are selling it for $99. Finally, probably the best option is to pick this up from <a href="http://search.digikey.com/us/en/products/P0082/P0082-ND/2625112">Digikey</a> for $86.25, you&#8217;ll want to compare the shipping options and prices to find what&#8217;s best for you.</p>
<p>(If you&#8217;re a student you can get the board from Terasic at a significant discount that might make it worth the hassle buying through them.)</p>
<p>Using the board is super easy, in the first hour or two of getting the board I was able to run through both of the tutorials in the <a href="http://www.terasic.com.tw/cgi-bin/page/archive_download.pl?Language=English&#038;No=593&#038;FID=75023fa36c9bf8639384f942e65a46f3">manual</a>. The first project is a simple blinking LED project, and the second is dropping in a NIOS II softcore processor using the <a href="http://www.altera.com/literature/lit-sop.jsp">SOPC Builder tool</a>.</p>
<p>The SOPC Builder tool is actually being replaced by the newer better <a href="http://www.altera.com/products/software/quartus-ii/subscription-edition/qsys/qts-qsys.html">Qsys tool</a>. I&#8217;m going to start playing around with Qsys and see if I can make a comparable tutorial.</p>
<p>This board really is nano, check out this picture I snapped with my phone, using my hand to help put the size into perspective:</p>
<div id="attachment_1100" class="wp-caption aligncenter" style="width: 310px"><a href="http://idle-logic.com/wp-content/uploads/2011/10/de0NanoIsNano.jpg"><img src="http://idle-logic.com/wp-content/uploads/2011/10/de0NanoIsNano-300x224.jpg" alt="" title="de0-Nano Is Nano" width="300" height="224" class="size-medium wp-image-1100 colorbox-1076" /></a><p class="wp-caption-text"> </p></div>
<p>Looking forward to playing around with this little toy and blogging my progress.</p>
<p>Did you pick one up? Working on any fun projects with it? Leave a comment and let me know.</p>
<p>(Side note: I learned from watching one of their video&#8217;s that the company name Terasic is pronounced like Jurassic, and not like &#8220;tear-ASIC&#8221;)</p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/0sQfoevN5jM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/10/13/welcome-the-de0-nano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/10/13/welcome-the-de0-nano/</feedburner:origLink></item>
		<item>
		<title>SparkFun retires Cyclone II Breakout board</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/CL9XkI7Bykk/</link>
		<comments>http://idle-logic.com/2011/08/04/sparkfun-retires-cyclone-ii-breakout-board/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 03:45:39 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Cyclone II]]></category>
		<category><![CDATA[fpga]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1051</guid>
		<description><![CDATA[Usually, I would get a few people linking to Idle-Logic from SparkFun&#8217;s Cyclone II Breakout board product page. Looking through the logs recently I noticed that this trickle of referrals dried up. I went to investigate only to find that the board has been discontinued&#8230; sad times. Down the road I plan on making my ]]></description>
			<content:encoded><![CDATA[<p>Usually, I would get a few people linking to Idle-Logic from <a href="http://www.sparkfun.com/products/8596">SparkFun&#8217;s Cyclone II Breakout board</a> product page. Looking through the logs recently I noticed that this trickle of referrals dried up. I went to investigate only to find that the board has been discontinued&#8230; sad times.</p>
<p>Down the road I plan on making my own breakout board, probably with the basic <a href="http://idle-logic.com/2010/02/25/cyclone-ii-voltage-regulators/">regulators</a> and <a href="http://idle-logic.com/2011/03/05/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-python-code/">USB</a> connections to make it run. I would try to keep it cheap and as barebones as possible, and my thought is to build custom &#8220;headers&#8221; similar to what is done on the Arduino.</p>
<p>Leave a message in the comments if you would be interested in such a product so I can set my motivation appropriately. </p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/CL9XkI7Bykk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/08/04/sparkfun-retires-cyclone-ii-breakout-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/08/04/sparkfun-retires-cyclone-ii-breakout-board/</feedburner:origLink></item>
		<item>
		<title>A Smathering of the Interesting</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/R0XAb8YBV9Y/</link>
		<comments>http://idle-logic.com/2011/07/14/a-smathering-of-the-interesting/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 18:59:45 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[MetaBlogging]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1035</guid>
		<description><![CDATA[Unfortunately, I haven&#8217;t had much Idle time lately for working on my nerd projects or blogging. In all my free time I&#8217;m outside tearing out trees and bushes and landscaping my yard. Not much Logic involved there, only destruction and mayhem. To get myself back into the blogging spirit, I decided to put together a ]]></description>
			<content:encoded><![CDATA[<p>Unfortunately, I haven&#8217;t had much <em>Idle</em> time lately for working on my nerd projects or blogging. In all my free time I&#8217;m outside tearing out trees and bushes and landscaping my yard. Not much <em>Logic</em> involved there, only destruction and mayhem. </p>
<p>To get myself back into the blogging spirit, I decided to put together a series of posts sharing what content I&#8217;m absorbing these days. Let&#8217;s start off with:</p>
<p><strong>RSS Feeds I&#8217;m subscribed to:</strong></p>
<p><a href="http://engineerblogs.org/">EngineerBlogs.org</a> &#8211; A great mashup of different types of engineers (Electrical, Mechanical, etc.) all posting on a select topic each week. Not all the posts hit home for me, but most are worth the read.</p>
<p><a href="http://www.sparkfun.com/">SparkFun</a> &#8211; Always exciting to see the projects they share, and most importantly the Friday &#8220;New Product Posts&#8221;.</p>
<p><a href="http://www.flyingflux.com">FlyingFlux</a> &#8211; A blog of an anonymous Analog Engineer who doesn&#8217;t hold back. His blog is no longer updated, as he&#8217;s left to spend more time with his family, but there is still a few years worth of posts to go read.</p>
<p><a href="http://www.electronics-lab.com/blog">Electronics-Lab.com</a> &#8211; The electronic hobbyist news blog. Very active stream of cool hobby projects.</p>
<p><a href="http://www.edn.com/blog/EDN_Product_fEEd/">EDN Product fEEd</a> &#8211; New products, most aren&#8217;t very applicable to my job and/or hobbies, but it&#8217;s good to stay on top of new products coming out.</p>
<p><a href="http://blogs.discovermagazine.com/cosmicvariance/">Cosmic Variance</a> &#8211; Random samplings from a universe of ideas. Discover Magazine presents a blog from a group of scientists, most of the best posts come from <a href="http://en.wikipedia.org/wiki/Sean_M._Carroll">Sean Carroll</a></p>
<p><a href="http://xkcd.com/">XKCD</a> &#8211; A webcomic of romance, sarcasm, math, and language. Everyone should be subscribed to this comic without a doubt.</p>
<p><a href="http://scienceblogs.com/pharyngula/">Pharyngula</a> &#8211; Blog of biologist PZ Myers, like Dawkins only with an ample dose of hilarity and sarcasm.</p>
<p><a href="http://www.codinghorror.com/blog/">Coding Horror</a> &#8211; The blog of prominent coding guru Jeff Atwood. He&#8217;s doesn&#8217;t really blog as much these days as he used to, but still worth staying subscribed.</p>
<p><a href="http://www.julieharrisphotography.com/blog/">Julie Harris Photography</a> &#8211; An amazing photographer, a good artistic diversion from the day to day nerdom.</p>
<p><a href="http://failblog.org/">Fail Blog</a> &#8211; Constant stream of hilarity.</p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/R0XAb8YBV9Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/07/14/a-smathering-of-the-interesting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/07/14/a-smathering-of-the-interesting/</feedburner:origLink></item>
		<item>
		<title>Programming the Cyclone II using C++, libftdi and a FT2232H</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/0--bX6ev06Y/</link>
		<comments>http://idle-logic.com/2011/03/22/programming-the-cyclone-ii-using-c-libftdi-and-a-ft2232h/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 19:44:44 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[Cyclone II]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cyclone]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[fpga configuration]]></category>
		<category><![CDATA[FT2232H]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=1027</guid>
		<description><![CDATA[Using a similar technique I covered in my last post, reader Bryan Richmond has been able to successfully program an Altera Cyclone II using C++, libftdi and a FT2232H USB/UART. From my understanding Bryan is running Debian on an ARM, and is programming the Cyclone II on his Morph-IC-II development board. I haven&#8217;t had a ]]></description>
			<content:encoded><![CDATA[<p>Using a similar technique I covered in my <a href="http://idle-logic.com/2011/03/05/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-python-code/">last post</a>, reader Bryan Richmond has been able to successfully program an Altera Cyclone II using C++, libftdi and a <a href="http://www.ftdichip.com/Products/ICs/FT2232H.htm">FT2232H</a> USB/UART.</p>
<p>From my understanding Bryan is running <a href="http://en.wikipedia.org/wiki/Debian">Debian</a> on an ARM, and is programming the Cyclone II on his <a href="http://www.mouser.com/ProductDetail/FTDI/Morph-IC-II/?qs=6PjUDzoLQMEi%252bekCTmVC6g%3D%3D">Morph-IC-II</a> development board.</p>
<p>I haven&#8217;t had a chance to test the code, but Bryan has shown it to process and send a 50K RBF file in less than 3 seconds. The code demonstrates the usage of many libftdi function calls not mentioned in my last post. Also, Bryan&#8217;s code is checking the NCONF_DONE pin of the FPGA to ensure the configuration file has been sent correctly.</p>
<p>Great work Bryan!</p>
<div class="greybox">You can download the C++ file here:</p>
<p><a style="float:left" href="http://idle-logic.com/wp-content/uploads/2011/03/passiveSerial.zip"><img class="cleanimg  colorbox-1027" src="http://idle-logic.com/wp-content/uploads/2010/02/box_download_48.png" alt="Download" title="Download" width="48" height="48" class="alignleft size-full wp-image-411" /></a><br />
<a href="http://idle-logic.com/wp-content/uploads/2011/03/passiveSerial.zip">passiveSerial.zip</a><BR><br />
<strong>Contains:</strong></p>
<ul>
<li>passiveSerial.cpp</li>
</ul>
</div>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/0--bX6ev06Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/03/22/programming-the-cyclone-ii-using-c-libftdi-and-a-ft2232h/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/03/22/programming-the-cyclone-ii-using-c-libftdi-and-a-ft2232h/</feedburner:origLink></item>
		<item>
		<title>Programming an Altera Cyclone II FPGA with a FT232RL – Python Code</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/U6o2h4PsRrY/</link>
		<comments>http://idle-logic.com/2011/03/05/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-python-code/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 20:59:06 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[Cyclone II]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[FT232RL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Quartus]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bit bang]]></category>
		<category><![CDATA[cyclone]]></category>
		<category><![CDATA[PS Configuration]]></category>
		<category><![CDATA[quartus ii]]></category>
		<category><![CDATA[rbf file]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=947</guid>
		<description><![CDATA[This is the final post in a series of three to explain how to use the FT232RL USB to UART Bridge to program a Cyclone II FPGA. The first part in the series describes how to compile and install the hardware drivers in Ubuntu that we need to use to access the FT232RL functions. The ]]></description>
			<content:encoded><![CDATA[<p><a href="http://idle-logic.com/wp-content/uploads/2011/02/PythonConfig_viaFT232RL.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/PythonConfig_viaFT232RL-150x150.png" alt="Python - Configuring the CII via an FT232R" title="Python - Configuring the CII via an FT232R" width="150" height="150" class="alignright size-thumbnail wp-image-948 colorbox-947" /></a><br />
This is the final post in a series of three to explain how to use the FT232RL USB to UART Bridge to program a Cyclone II FPGA.</p>
<p>The <a href="http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/">first part</a> in the series describes how to compile and install the hardware drivers in Ubuntu that we need to use to access the FT232RL functions. The <a href="http://idle-logic.com/2011/02/21/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-usb-to-uart-bridge/">second part</a> describes the hardware modifications and connections required to interface the FT232RL to <a href="http://idle-logic.com/2010/03/31/cyclone-ii-bill-of-materials/">SparkFun&#8217;s Cyclone II Breakout board.<br />
</a></p>
<p>Let me give you a quick high-level overview of what we must do in order to configure the Cyclone II using the FT232RL, after which we will dive head first into all the juicy details.</p>
<hr />
<H3>High Level Steps:</H3><br />
<strong>In Quartus II:</strong></p>
<ol>
<li>Convert the FPGA Config file from SOF to RBF (Raw Binary File) in Quartus.</li>
</ol>
<p><strong>In Python:</strong></p>
<ol start="2">
<li>Read and process the .rbf configuration file into a serial bit stream. We then need to &#8220;weave&#8221; in the DCLK transitions to create a parallel byte stream which will be sent to the FT232RL. More on that in a bit.</li>
<li>Open a connection to the FT232RL hardware, and configure it for Bit Bang mode operation.</li>
<li>Trigger the Cyclone II into configuration mode.</li>
<li>Push the bit stream to the FPGA.</li>
<li>Close our FT232RL connection.</li>
</ol>
<p><BR></p>
<hr />
<h3>Generate the RBF File (Quartus II)</h3>
<p>Once you &#8220;compile&#8221; (synthesis) an FPGA design in the Quartus II software, the tool generates a file which contains all the information required to configure your FPGA. However, the default file type is a .SOF which I&#8217;m not sure how to manage. However there are other file types available to use for configuration, so much so that Quartus II has a built in tool to convert between formats.</p>
<p>We will be converting the SOF file to an RBF, Raw Binary File which appears to be easier to work with.</p>
<p>The graphic below highlights these steps you will need to take:<br />
(First, open the Convert Programming File tool from the menu.)</p>
<ol>
<li>Select the Programming file type as &#8220;Raw Binary File (.rbf)</li>
<li>Set the new file&#8217;s path and name.</li>
<li>Add the source SOF file to be converted. (This file should be in the root directory of your FPGA&#8217;s project after you synthesis the design)</li>
<li>Click on the Properties button and enable Compression. This reduces the number of bits we need to send. (The CII has an onboard decompression engine)</li>
<li>The final step is to click the &#8220;Generate&#8221; button.</li>
</ol>
<p><a href="http://idle-logic.com/wp-content/uploads/2011/02/ConverttoRBF_Quartus.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/ConverttoRBF_Quartus-300x274.png" alt="Convert to RBF" title="Convert to RBF" width="300" height="274" class="aligncenter size-medium wp-image-954 colorbox-947" /></a></p>
<hr />
<h3>Python Code</h3>
<p>First, I just want to throw all the code out there for people who would like to copy &#038; paste it in it&#8217;s entirety, next I&#8217;ll break it down and explain its components.</p>
<pre class="brush: python; title: CII_Config_ExampleSimple.py; notranslate">
'''
Created on Feb 21, 2011

@author: Chris Zeh

'''

from binascii import hexlify
import ftdi

NCONFIG_HIGH = 0x4 #Bitbang Pin #3 (NCONFIG)
DCLK_HIGH = 0x2    #Bitbang Pin #2 (DCLK)

def InitFDTI():
    _ftdic = ftdi.ftdi_context()
    ftdi.ftdi_init(_ftdic)
    ftdi.ftdi_usb_open(_ftdic,0x0403,0x6001) #The last 2 params identify the Vendor_ID and Product_ID programmed into your FT chip. 0x6001 is FT232RL
    #Go here to find the default Product_ID for different parts:
    #www.ftdichip.com/Documents/technicalnotes/tn_100_usb_vid-pid_guidelines.pdf

    ftdi.ftdi_enable_bitbang(_ftdic,0xFF)
    ftdi.ftdi_set_baudrate(_ftdic,9600*16) #Not certain what is the fastest setting possible yet.
    return _ftdic

def StartConfig(ftdic):
    #To start the config process we need to take FPGA's NCONFIG pin LOW then HIGH
    ftdi.ftdi_write_data(ftdic,chr(0),1)
    ftdi.ftdi_write_data(ftdic,chr(NCONFIG_HIGH),1)

def toBINstr(hexstr):
    #Converts a hex string ('\xff' to a binary str 11111111)

    data_byte = eval('0x' + hexlify(hexstr))
    bindata = ''
    for b in range(7,-1,-1):
        bindata+=str(data_byte&gt;&gt;b &amp; 1)

    return bindata

def ReadFile(path):

    f = open(path,'r')
    dat = f.read()
    f.close()
    return dat #Read all of the data into a string

ftdic = InitFDTI()

print 'Device Opened'
StartConfig(ftdic)

data = ReadFile('/home/chris/Projects/Saturn Project/FPGA Code/Hello World/Hello_World_Compressed.rbf')
NewData=''
print 'Preparing the Config Data'

#We set the current state of all 8 Bit-Bang pins of the FT232RL by sending it one byte.
#      each bit in said byte cooresponds to one pin on the FT232RL.

#So we need to convert the bits in the RBF file into bytes to send to the FT232RL, setting the DATA0 pin and then &quot;clocking&quot; it in.

#The following generates the byte stream from the RBF file.
#Basically, every config bit we send to the FPGA needs to be clocked in.
#So take the DCLK low. Set the DATA0 to the value of the bit we want
#to send. Then take the DCLK high. Repeat for all bits in the file.
#You can see we need to send 3 Bytes to the FT232RL in order to send one
#configuration bit.

for byte in range(0,len(data)):
    bits = toBINstr(data[byte])
    for bit in range(-1,-9,-1): #The strange range parameters are to reorder the bits in the RBF correctly for the FPGA
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH) #Set DATA0 to the bit, Set DCLK Low. (Be sure to keep holding up the NCONFIG pin)
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH | DCLK_HIGH) #Clock the data in
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH) #Falling edge of the clock, this can probably be removed but I have to check the timing to be sure (setup/hold times).

print 'Writing to the FPGA'
#The following code is/was needed for version 0.17-1 of the ftdi driver (There is a bug where too large a buffer kicks back a -14 memory error)
#Re = ''
#for x in range(1,24):
    #Re = NewData[(x-1)*2**18:x*2**18]
    #rc = ftdi.ftdi_write_data(ftdic,Re,len(Re))
    #print rc

#Version 0.18 allows for the full buffer to be passed:
rc = ftdi.ftdi_write_data(ftdic,NewData,len(NewData))
print 'Configured!'

ftdi.ftdi_usb_close(ftdic)
</pre>
<p><strong>Breaking down the code.</strong><br />
Alright, we&#8217;ll skip past the declarations for now and start with the code in the order it executes.</p>
<p>First step is to initialize our connection with the ftdi driver and connect to the FT232RL device:</p>
<pre class="brush: python; first-line: 58; title: ; notranslate">
ftdic = InitFDTI()
</pre>
<pre class="brush: python; first-line: 16; title: ; notranslate">
def InitFDTI():
    _ftdic = ftdi.ftdi_context()
    ftdi.ftdi_init(_ftdic)
    ftdi.ftdi_usb_open(_ftdic,0x0403,0x6001) #The last 2 params identify the Vendor_ID and Product_ID programmed into your FT chip. 0x6001 is FT232RL
    #Go here to find the default Product_ID for different parts:
    #www.ftdichip.com/Documents/technicalnotes/tn_100_usb_vid-pid_guidelines.pdf

    ftdi.ftdi_enable_bitbang(_ftdic,0xFF)
    ftdi.ftdi_set_baudrate(_ftdic,9600*16) #Not certain what is the fastest setting possible yet.
    return _ftdic
</pre>
<p>If you are using a device other than the FT232RL you might need to modify the Product_ID in the <code>ftdi_usb_open</code> function. See the comments in the code for more details.</p>
<p>The <code>ftdi_enable_bitbang</code> function configures the 8 bit-bang pins to either an Input or an Output. For this example I&#8217;m setting all 8 pins to be Outputs, hence the <code>0xFF</code>. If you wanted all the pins to be Inputs you would send <code>0x00</code>, and if you wanted half to be input and half output: 0xF0. </p>
<p>According to the <a href="http://www.intra2net.com/en/developer/libftdi/documentation/group__libftdi.html#ga73127091e1d4d50b2b7c0e005c4900f7">documentation</a> this<code> ftdi_enable_bitbang</code> function is depreciated and favors the new function <code>ftdi_set_bitmode</code>. This new function wasn&#8217;t working for me, but maybe you&#8217;ll have more luck with it than I did.</p>
<p>The next step is to signal to the FPGA that we are going to send it a configuration stream. We need to yank its NCONFIG line low then high:</p>
<pre class="brush: python; first-line: 61; title: ; notranslate">
StartConfig(ftdic)
</pre>
<pre class="brush: python; first-line: 29; title: ; notranslate">
def StartConfig(ftdic):
    #To start the config process we need to take FPGA's NCONFIG pin LOW then HIGH
    ftdi.ftdi_write_data(ftdic,chr(0),1)
    ftdi.ftdi_write_data(ftdic,chr(NCONFIG_HIGH),1)
</pre>
<p>We send data to the FT232RL as a Byte of data (<code>ftdi_write_data</code>), with each bit corresponding to the state of each pin. You can see I defined the NCONFIG_HIGH to set the 3rd pin high:</p>
<pre class="brush: python; first-line: 11; title: ; notranslate">
NCONFIG_HIGH = 0x4 #Bitbang Pin #3 (NCONFIG)
DCLK_HIGH = 0x2    #Bitbang Pin #2 (DCLK)$
</pre>
<p>Next I load the FPGA&#8217;s configuration file into memory:</p>
<pre class="brush: python; first-line: 64; title: ; notranslate">
data = ReadFile('/home/chris/Projects/Saturn Project/FPGA Code/Hello World/Hello_World_Compressed.rbf')
</pre>
<p>Next we need to process the RBF file to get it ready to send to the FT232RL and the Cyclone II:</p>
<pre class="brush: python; first-line: 81; title: ; notranslate">
for byte in range(0,len(data)):
    bits = toBINstr(data[byte])
    for bit in range(-1,-9,-1): #The strange range parameters are to reorder the bits in the RBF correctly for the FPGA
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH) #Set DATA0 to the bit, Set DCLK Low. (Be sure to keep holding up the NCONFIG pin)
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH | DCLK_HIGH) #Clock the data in
        NewData += chr(int(bits[bit]) | NCONFIG_HIGH) #Falling edge of the clock, this can probably be removed but I have to check the timing to be sure (setup/hold times).
</pre>
<p>Here is the key sentence from the Altera CII <a href="http://www.altera.com/literature/hb/cyc2/cyc2_cii5v1_06.pdf">documentation</a> explaining how the data needs to be sent to the FPGA:</p>
<blockquote><p>
send the configuration data on the DATA0 pin one bit at a time. If you are using configuration data in RBF, HEX, or TTF format, send the least significant bit (LSB) of each data byte first. For example, if the RBF contains the byte sequence 02 1B EE 01 FA, you should transmit the serial bitstream 0100-0000 1101-1000 0111-0111 1000-00000101-1111 to the device first.
</p></blockquote>
<p>Now, every bit we send on DATA0 needs to be <a href="http://en.wikipedia.org/wiki/Flip-flop_%28electronics%29">clocked-in</a>, which is why we set the DCLK low, put the data on the DATA0 pin, then take DCLK high. You can see for each configuration bit we want to send to the FPGA, we are sending 3 bytes to the FT232RL.</p>
<p>(If you are trying to use this code on Windows, you might have to adjust the code to avoid <a href="http://en.wikipedia.org/wiki/Endianness">Endian</a> problems)</p>
<p>Now that we have the byte stream generated we need to send it to the FT232RL. Fortunately, the <code>ftdi</code> library makes this pretty easy for us:</p>
<pre class="brush: python; first-line: 99; title: ; notranslate">
rc = ftdi.ftdi_write_data(ftdic,NewData,len(NewData))
</pre>
<p>I had a problem using the older version of the <code>libftdi</code> driver (v0.17-1) where sending the full buffer in one go would kick back a -14 memory error. The following code was a workaround to send the data in smaller bits:</p>
<pre class="brush: python; first-line: 90; title: ; notranslate">
#The following code is/was needed for version 0.17-1 of the ftdi driver (There is a bug where too large a buffer kicks back a -14 memory error)
#Re = ''
#for x in range(1,24):
    #Re = NewData[(x-1)*2**18:x*2**18]
    #rc = ftdi.ftdi_write_data(ftdic,Re,len(Re))
    #print rc
</pre>
<p>Finally, let&#8217;s close our connection with the ftdi device:</p>
<pre class="brush: python; first-line: 104; title: ; notranslate">
ftdi.ftdi_usb_close(ftdic)
</pre>
<p>And that is all there is to it! After running the code your FPGA should be up and running.</p>
<p>I had a lot of problems initially because of Ubuntu&#8217;s security blocking me from accessing the FT232RL, so be sure to read my <a href="http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/">first post</a> describing how to setup a <code>udev</code> rule to allow non-root access to the device.</p>
<p>I recommend looking at the <a href="http://www.intra2net.com/en/developer/libftdi/documentation/group__libftdi.html"><code>libftdi</code> documentation</a> as well as the <a href="http://www.altera.com/literature/hb/cyc2/cyc2_cii5v1_06.pdf">Cyclone II Configuration documentation</a> if you have any problems with the code and/or configuration process.</p>
<p>Best of luck. Please leave a comment and let me know if this code has helped you, or if you have any questions.</p>
<div class="greybox">You can download the Python file here:</p>
<p><a style="float:left" href="http://idle-logic.com/wp-content/uploads/2011/03/CII_Config_ExampleSimple.zip"><img class="cleanimg  colorbox-947" src="http://idle-logic.com/wp-content/uploads/2010/02/box_download_48.png" alt="Download" title="Download" width="48" height="48" class="alignleft size-full wp-image-411" /></a><br />
<a href='http://idle-logic.com/wp-content/uploads/2011/03/CII_Config_ExampleSimple.zip'>CII_Config_ExampleSimple.zip</a><BR><br />
<strong>Contains:</strong></p>
<ul>
<li>CII_Config_ExampleSimple.py</li>
</ul>
</div>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/U6o2h4PsRrY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/03/05/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-python-code/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/03/05/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-python-code/</feedburner:origLink></item>
		<item>
		<title>Programming an Altera Cyclone II FPGA with a FT232RL USB to UART Bridge</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/q59VescW5MI/</link>
		<comments>http://idle-logic.com/2011/02/21/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-usb-to-uart-bridge/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 20:23:14 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Altera]]></category>
		<category><![CDATA[Cyclone II]]></category>
		<category><![CDATA[FT232RL]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[fpga configuration]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=903</guid>
		<description><![CDATA[As I alluded to in a previous post, I&#8217;ve come up with a way to program my Altera Cyclone II FPGA with a $15 FT232RL USB to UART Bridge, avoiding the $300 investment in one of Altera&#8217;s USB-Blaster cables. I&#8217;m going to break this tutorial up into three separate posts. The first has already been ]]></description>
			<content:encoded><![CDATA[<p>As I alluded to in a <a href="http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/">previous post</a>, I&#8217;ve come up with a way to program my Altera Cyclone II FPGA with a $15 FT232RL USB to UART Bridge, avoiding the $300 investment in one of Altera&#8217;s <a href="http://www.buyaltera.com/scripts/partsearch.dll?Detail&#038;name=544-1775-ND">USB-Blaster cables</a>.</p>
<p>I&#8217;m going to break this tutorial up into three separate posts. The first has already been uploaded: <a href="http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/">libFTDI v0.18 with Ubuntu (Lucid Lynx)</a>, which describes how to install the proper version of the hardware drivers on Ubuntu. This post, being the second in the series, will cover the hardware modifications required to interface the FT232RL with an <a href="http://idle-logic.com/2010/03/31/cyclone-ii-bill-of-materials/">FPGA setup</a>. The third post will show the Python code used to push the FPGA configuration file down to the FPGA bit by bit.</p>
<p>The Cyclone II FPGA has a few different methods for configuration as described by the <a href="http://www.altera.com/literature/hb/cyc2/cyc2_cii5v1.pdf">Altera Cyclone II Handbook:</a></p>
<ol>
<li>Active serial (AS) : Configuration using serial configuration devices (EPCS1, EPCS4, EPCS16 or EPCS64 devices). These can be described as basically non-volatile memory blocks that hold your configuration file. The Cyclone II will actually access this memory to configure itself on power-up.
</li>
<li>Passive serial (PS) : Configuration using enhanced configuration devices (EPC4, EPC8, and EPC16 devices), EPC2 and EPC1 configuration devices, an intelligent host (microprocessor), or a download cable.
</li>
<li>JTAG-based configuration : Configuration via JTAG pins using a download cable, an intelligent host (microprocessor), or the JamTM Standard Test and Programming Language (STAPL)
</li>
</ol>
<p>Previously, I had been <a href="http://idle-logic.com/2010/04/19/configuring-the-cyclone-ii/">configuring the Cyclone II</a> on my <a href="http://idle-logic.com/2010/03/31/cyclone-ii-bill-of-materials/">SparkFun breakout board</a> using the JTAG configuration method. Now I decided I wanted to start using a USB connection instead of the antiquated parallel port required for the <a href="http://www.sparkfun.com/products/8705">Altera JTAG programmer</a>, but to be honest this decision was partially based on the fact that my <a href="http://idle-logic.com/2010/10/17/adventures-in-a-new-pc/">new computer</a> has no parallel port. <img src='http://idle-logic.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley colorbox-903' /> </p>
<p>For this USB programming solution, we will be using the Passive Serial (PS) configuration method where our computer will act as the intelligent host.</p>
<p>The following diagram shows how we need to configure the breakoutboard for Passive Serial:</p>
<p><a href="http://idle-logic.com/wp-content/uploads/2011/02/PSConfiguration.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/PSConfiguration-300x141.png" alt="" title="Passive Serial (PS) Configuration" width="300" height="141" class="aligncenter size-medium wp-image-915 colorbox-903" /></a></p>
<p>Here is the breakout board schematic showing the modifications we need to make: Removing four solder jumpers, and connecting half of one jumper to the supply voltage (Original Schematic <a href="http://www.sparkfun.com/datasheets/DevTools/FPGA/Cyclone%20II%20Breakout/AlteraCycloneIIBreakout-v02_Schematic.pdf">here</a>):<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/JTAGSchematic.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/JTAGSchematic-300x106.png" alt="" title="Breakout board (PS) Changes" width="300" height="106" class="aligncenter size-medium wp-image-919 colorbox-903" /></a></p>
<p>And here is the breakout board layout showing the changes to be made:<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/PSConfigSchematic.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/PSConfigSchematic-300x277.png" alt="" title="B.O.B Layout" width="300" height="277" class="aligncenter size-medium wp-image-920 colorbox-903" /></a></p>
<p>Finally, here is a picture of the changes made on my breakout board:<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/C2Rework.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/C2Rework-300x241.png" alt="" title="CII BOB Rework" width="300" height="241" class="aligncenter size-medium wp-image-933 colorbox-903" /></a></p>
<p>Okay, now we need to connect the FT232RL Breakout-board (BOB) to our Cyclone II BOB. First, let me show you the schematic for the <a href="http://www.sparkfun.com/datasheets/BreakoutBoards/FT232RL-Breakout-Schematic.pdf">FT232RL Breakout Board</a>:<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/FT232RL_BOB.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/FT232RL_BOB-300x165.png" alt="" title="FT232RL BOB" width="300" height="165" class="aligncenter size-medium wp-image-922 colorbox-903" /></a></p>
<p>We are going to be using the FT232RL in <a href="http://en.wikipedia.org/wiki/Bit-banging">bitbang</a> mode. According to Table 2.1 of the <a href="http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf">FT232R Bit Bang Mode&#8217;s application note</a> we have the following pin-outs for bitbang mode:</p>
<table style="width: 245px;">
<tr>
<td>Bit Bang Pin</td>
<td>Chip Pins</td>
<td>Name</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>TXD</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td>RXD</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>RTS</td>
</tr>
<tr>
<td>3</td>
<td>11</td>
<td>CTS</td>
</tr>
<tr>
<td>4</td>
<td>2</td>
<td>DTR</td>
</tr>
<tr>
<td>5</td>
<td>9</td>
<td>DSR</td>
</tr>
<tr>
<td>6</td>
<td>10</td>
<td>DCD</td>
</tr>
<tr>
<td>7</td>
<td>6</td>
<td>RI</td>
</tr>
</table>
<p>For convenience, I&#8217;ve drawn out where the bitbang pins are on the breakoutboard:<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/BitBang-Pins.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/BitBang-Pins-300x160.png" alt="" title="BitBang Pins" width="300" height="160" class="aligncenter size-medium wp-image-926 colorbox-903" /></a></p>
<p>Now, our final step in setting up the hardware is to connect the DATA0, DCLK and NCONFIG pins of the Cyclone II to the FT232RL breakout board:</p>
<ol>
<li>Connect Pin 20 (DATA0) of the Cyclone II BOB to the BitBang Pin 0 of the FT232RL.</li>
<li>Connect Pin 21 (DCLK) to BitBang Pin 1.</li>
<li>Connect Pin 26 (NCONFIG) to Bitbang Pin 2.</li>
<ul>
<p>Here is a capture from the Cyclone II BOB Schematic:<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/C2BOB_PS_Schematic.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/C2BOB_PS_Schematic-300x236.png" alt="" title="Cyclone II PS Config Pins" width="300" height="236" class="aligncenter size-medium wp-image-929 colorbox-903" /></a></p>
<p>Finally, here is a picture of my FT232RL BOB inserted into my protoboard, you can see I ran some wires from the eight BitBang lines to the side of the protoboard for easier access.<br />
<a href="http://idle-logic.com/wp-content/uploads/2011/02/FT232RL_proto.png"><img src="http://idle-logic.com/wp-content/uploads/2011/02/FT232RL_proto-300x235.png" alt="" title="FT232RL BOB on Protoboard" width="300" height="235" class="aligncenter size-medium wp-image-935 colorbox-903" /></a></p>
<p>That concludes the hardware modifications required for programming the Cyclone II (on a SparkFun BOB) using the FT232RL. Next post I&#8217;ll show the software required to process a configuration file and send it to the Cyclone II, bit by bit.</p>
<p>(Teaser: I&#8217;m currently working on a MUX system that will allow us to &#8220;reconnect&#8221; those FT232RL pins to I/O pins of the Cyclone II, instead of always being connected to the FPGA&#8217;s config pins. With a little work it should give us the ability to program and communicate with the FPGA for less than $15! <img src='http://idle-logic.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley colorbox-903' />  )</p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/q59VescW5MI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/02/21/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-usb-to-uart-bridge/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/02/21/programming-an-altera-cyclone-ii-fpga-with-a-ft232rl-usb-to-uart-bridge/</feedburner:origLink></item>
		<item>
		<title>IEEE Paper Published</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/AtApVZBmHbA/</link>
		<comments>http://idle-logic.com/2011/01/18/ieee-paper-published/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 04:00:25 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[MetaBlogging]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[Hard Drives]]></category>
		<category><![CDATA[IEEE]]></category>
		<category><![CDATA[Paper]]></category>
		<category><![CDATA[Poster]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=774</guid>
		<description><![CDATA[I thought I would utilize my blog for a little bit of shameless self promotion&#8230; Several months back I was fortunate enough to join some of my work colleagues in publishing a paper and presenting a poster at the IEEE COMPEL 2010 conference. The title of the paper is &#8220;Power Electronics Control to Reduce Hard ]]></description>
			<content:encoded><![CDATA[<p>I thought I would utilize my blog for a little bit of shameless self promotion&#8230;</p>
<p>Several months back I was fortunate enough to join some of my work colleagues in publishing a paper and presenting a poster at the <a href="http://ecee.colorado.edu/compel10/">IEEE COMPEL 2010</a> conference. The title of the paper is <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5562364">&#8220;Power Electronics Control to Reduce Hard Disk Drive Acoustics Pure Tones&#8221;</a>:</p>
<blockquote><p>
<em>Abstract</em><br />
Hard Disk Drives are used more and more in environments where the noise level needs to be kept at a very low level. One example is the DVR-application in a bedroom. While the mechanics are important, power electronics control can help to reduce the noise. This paper is presenting two new algorithms that reduce significantly the acoustics pure tones generated by the spindle motor. The first method counters 5/7th harmonics. The second dilutes the pure tones thanks to a spread spectrum approach. Comprehensive theory and measurement data are presented. The electronics driver stays simple and is available into low-cost custom IC.
</p></blockquote>
<p>Most of my work involved preparing the poster presentation along with developing software and giving the live demo. However, I was still able to tack my name onto the paper, and partake in the eternal glory.<br />
<div class="wp-caption alignnone" style="width: 460px"><a href="http://ecee.colorado.edu/compel10/conclusions.html"><img class="colorbox-774"  alt="" src="http://ecee.colorado.edu/compel10/pix/poster1.jpg" title="My mug made it on the conference website" width="450" height="301" /></a><p class="wp-caption-text">My mug made it on the conference website</p></div></p>
<p>Finally, after several months of anxious waiting the paper has been published <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5562364">here</a> on the IEEE Xplore. I&#8217;m still waiting for the truckloads of cash and notoriety that comes along with having a paper published&#8230; but something tells me I&#8217;ll be waiting hopelessly.</p>
<p>Maybe my next paper: &#8220;Alcohol&#8217;s effects on reducing eyeball effective resolution; a technique in pub television cost investment optimization&#8221; will have a wider audience <img src='http://idle-logic.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley colorbox-774' /> </p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/AtApVZBmHbA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2011/01/18/ieee-paper-published/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2011/01/18/ieee-paper-published/</feedburner:origLink></item>
		<item>
		<title>libFTDI v0.18 with Ubuntu (Lucid Lynx)</title>
		<link>http://feedproxy.google.com/~r/Idle-logic/~3/AKFN6bm8uQw/</link>
		<comments>http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 19:43:42 +0000</pubDate>
		<dc:creator>Chris Zeh</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[saturn project]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[FT232RL]]></category>
		<category><![CDATA[libFTDI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SWIG]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://idle-logic.com/?p=798</guid>
		<description><![CDATA[Now that I&#8217;ve upgraded my computer, I no longer have a Parallel port which renders my Altera FPGA Compatible Programmer obsolete. Instead of buying a $300 USB-Blaster from Altera, I&#8217;m developing a much cheaper solution&#8230; In my next post I&#8217;m going to show a technique I&#8217;ve come up with to configure the Cyclone II FPGA ]]></description>
			<content:encoded><![CDATA[<p><div class="wp-caption alignright" style="width: 198px"><img class="colorbox-798"  alt="" src="http://dlnmh9ip6v2uc.cloudfront.net/images/products/00718-03-L.jpg" title="FT232RL Breakout Board" width="188" height="188" /><p class="wp-caption-text">FT232RL Breakout Board</p></div>Now that I&#8217;ve <a href="http://idle-logic.com/2010/10/17/adventures-in-a-new-pc/">upgraded my computer,</a> I no longer have a Parallel port which renders my <a href="http://www.sparkfun.com/products/8705">Altera FPGA Compatible Programmer</a> obsolete. Instead of buying a $300 <a href="http://www.buyaltera.com/scripts/partsearch.dll?Detail&#038;name=544-1775-ND">USB-Blaster</a> from Altera, I&#8217;m developing a much cheaper solution&#8230;</p>
<p>In my next post I&#8217;m going to show a technique I&#8217;ve come up with to configure the Cyclone II FPGA using a <a href="http://www.sparkfun.com/products/718">FT232RL</a> USB to UART Bridge. The breakout board costs $15, while the part itself costs $4 which is a much more agreeable solution for my wallet.</p>
<p>Before I can get into the specifics of the FPGA configuration, I need to show you how to install the proper drivers to play with the FT232RL. Presently FTDI recommends using the <a href="http://www.intra2net.com/en/developer/libftdi/">libFTDI</a> driver which appears to be maintained by the Intra2Net company. The library is released under the <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">GNU Lesser General Public License</a> so you can use it in free and proprietary programs. Currently only version 0.17-1 of  libFTDI is available from the Ubuntu Software center, which has a few too many bugs for my liking. This lead me to another learning experience in my linux adventures: I had to learn how to compile the driver from its source code.</p>
<p>I should mention quickly that I&#8217;m going to be writing code using <a href="http://www.python.org/">Python</a>. I&#8217;m using the <a href="http://www.eclipse.org/">eclipse</a> editor with the <a href="http://pydev.org/">Pydev</a> IDE.</p>
<p>In order to use the libFTDI driver in Python you will need to run the <a href="http://www.swig.org/">SWIG</a> tool to generate the &#8216;glue code&#8217; to call the libFTDI&#8217;s C/C++ functions. I&#8217;ll cover this aspect of the install in this tutorial as well.</p>
<p>Here are the steps to get going with the latest version of libFTDI:</p>
<p><strong>1. </strong>Download the latest tarball from their website: <code><strong><a href="http://www.intra2net.com/en/developer/libftdi/download/libftdi-0.18.tar.gz">libftdi-0.18.tar.gz</a></strong></code><br />
<a href="http://www.intra2net.com/en/developer/libftdi/download.php">http://www.intra2net.com/en/developer/libftdi/download.php</a></p>
<p><strong>2. </strong>Extract the files into another directory named <code>libftdi</code>.</p>
<p><strong>3.</strong> Using Ubuntu Software Center install the following:<br />
<strong>SWIG</strong> (To generate the Python &#8216;glue code&#8217;)<br />
<a href="http://idle-logic.com/wp-content/uploads/2010/12/SWIG.png"><img src="http://idle-logic.com/wp-content/uploads/2010/12/SWIG-300x112.png" alt="" title="SWIG" width="300" height="112" class="size-medium wp-image-860 colorbox-798" /></a><br />
<strong>Python Headers</strong> (Dependencies for using SWIG)<br />
<a href="http://idle-logic.com/wp-content/uploads/2010/12/PythonHeader.png"><img src="http://idle-logic.com/wp-content/uploads/2010/12/PythonHeader-300x67.png" alt="" title="PythonHeader" width="300" height="67" class="size-medium wp-image-865 colorbox-798" /></a><br />
<strong>libusb-dev</strong> (Need these development (header) files to compile the libFTDI drivers)<br />
<a href="http://idle-logic.com/wp-content/uploads/2010/12/libusb-dev.png"><img src="http://idle-logic.com/wp-content/uploads/2010/12/libusb-dev-300x46.png" alt="" title="libusb-dev" width="300" height="46" class="size-medium wp-image-864 colorbox-798" /></a></p>
<p><strong>4. </strong>We need to make a minor modification to the source code to allow us to actually read data from the device using Python due to a <a href="http://libftdi.141977.n3.nabble.com/ftdi-read-chipid-cannot-be-used-from-python-due-to-TypeError-td956451.html">bug</a>:<br />
In the file: <code>/libftdi/libftdi-0.18/bindings/ftdi.i</code></p>
<p>We need to insert a single line:<br />
<code>%pointer_functions(unsigned int, uintp);</code><br />
(Check the screenshot)<br />
<a href="http://idle-logic.com/wp-content/uploads/2010/12/ftdi_i_modification.png"><img src="http://idle-logic.com/wp-content/uploads/2010/12/ftdi_i_modification-300x275.png" alt="" title="ftdi_i_modification" width="300" height="275" class="alignnone size-medium wp-image-870 colorbox-798" /></a></p>
<p><strong>5. </strong>Now we go through the install process.<br />
In a terminal window, navigate to the folder where you extracted the tarball files:<br />
For me: <code>~/Downloads/libftdi/libftdi-0.18$ </code> and type the following statement:<br />
<code><strong>./configure --enable-python-binding </strong></code><br />
(Note that the <code>--enable-python-binding</code> option will automatically tell the installer to run SWIG and generate our python glue-code.)<br />
next type:<br />
<code><strong>make</strong></code></p>
<p>then:<br />
<code><strong>sudo make install</strong></code></p>
<p><strong>6. </strong>Now, we have one last step in order to make the device available to non-root users. We&#8217;ll be adding a rule to the udev:<br />
Create a new file in the <code>/etc/udev/rules.d</code> folder called <code>60-FTDIRT232R-usb.rules</code></p>
<p>Enter the following text into the file:<br />
<code>ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", MODE="0666"</code></p>
<p>(I&#8217;m pretty sure you will need root to create this file)</p>
<p><a href="http://idle-logic.com/wp-content/uploads/2010/12/UDEV_Rules.png"><img src="http://idle-logic.com/wp-content/uploads/2010/12/UDEV_Rules-300x181.png" alt="" title="UDEV_Rules" width="300" height="181" class="aligncenter size-medium wp-image-869 colorbox-798" /></a></p>
<p>Now you should be good to go. Try running python in interactive mode and type <code>import ftdi</code> to make sure the install and pathing is correct.</p>
<p>In the next post I&#8217;ll show you how to actually use this library to do work.</p>
<img src="http://feeds.feedburner.com/~r/Idle-logic/~4/AKFN6bm8uQw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://idle-logic.com/2010/12/13/libftdi-v0-18-with-ubuntu-lucid-lynx/</feedburner:origLink></item>
	</channel>
</rss>

