Starting with fpga - Page 1
Forum section: electronics / general

author: scarrier
author_rank: Contributor
timestamp: June 11, 2013, 06:10:47 pm
content: I have use mcu for many years now and i am starting with FPGA i have done(State machine, ALU and , 7 segment ...) . I am wondering now if i can make something more useful. I would like to know if there is some generic component like spi or i2c that exist to communicate with a lot of component like (adc, rtc ..). I am using a Altera DE2 do they come with it or is there any library to include?Thank you

author: Christe4nM
author_rank: Unknown
timestamp: June 11, 2013, 07:20:53 pm
content: Writing an I2C controller for FPGA/CPLD could be a nice project. This summer I'll be spending part of my time writing my own in VHDL. You have experience with microcontrollers, so you could use an external MCU to communicate with your FPGA and vice versa, or use the on-board I2C EEPROM. But I'm not sure if the latter is present on all DE2 boards. Mine is the DE2-115 with Cyclone IV FPGA. I couldn't find info about I2C EEPROM on the DE2-70 for example.If you want a prewritten I2C or SPI core either in VHDL or Verilog try OpenCores. Keep in mind however that those cores could be complex, depending on functionality. At least you might need to spend time to adapt it to your specific interface(s). For I2C I'd recommend getting Vincent Himpe / free_electron's book 'Mastering the I2C bus', the I2C specification by NXP, and get to writing your own controller. Start with a simple master or slave and build from there.Another tip: if you haven't already, register at TerasIC and download the CD's for the boards of your interest. In the zip file there are many examples, and I2C, SPI or other logic's source code might be present in them.Other fun / useful project:VGA controller. Start simple using internal RAM. Build from there and add SRAM / SDRAM. Get to using sprites or rendering objects like rectangles and cubes. Heck, build you own platform game while you're at it.A quick search on Google reveals many other example projects that are both fun and challenging on any level of experience.[Edit: typo]

author: marshallh
author_rank: Unknown
timestamp: June 12, 2013, 12:48:50 am
content: here's a basic i2c example, I think it will work the DE2's codecCode:///////////////////////////////////////////////////////// Wolfson WM8731 Audio Codec Interface (I2C)//// marshallh, Feb 14, 2012//// Implements the I2C interface for configuration.////////////////////////////////////////////////////////module audio_i2c(clk,ar,addr,wr,data,strobe,busy,i2c_sclk,i2c_sdat_out,i2c_sdat_oe,);inputwireclk;inputwirear;outputregi2c_sclk;outputregi2c_sdat_out;outputregi2c_sdat_oe;inputwire[6:0]addr;inputwirewr;inputwire[8:0]data;inputwirestrobe;regstrobe_1;reg[2:0]state;reg[28:0]shift;reg[28:0]shift_oe;reg[6:0]clk_cnt;reg[6:0]cnt;outputregbusy;always @(posedge clk or negedge ar) beginif(~ar) begin// reset statestate <= 0;i2c_sdat_oe <= 0;i2c_sdat_out <= 1;i2c_sclk <= 1;busy <= 1;end else begin// normal operationstrobe_1 <= strobe;case(state)0: beginbusy <= 0;i2c_sclk <= 1;if(strobe & ~strobe_1) begin// rising edge of strobeshift <= {1'b0, 7'b0011010, ~wr, 1'b0, addr, data, 1'b0, data[7:0], 2'b0};shift_oe <= 29'b11111111101111111101111111100;state <= 1;busy <= 1;endclk_cnt <= 0;cnt <= 0;end1: begincnt <= cnt + 1;i2c_sdat_out <= 1;i2c_sdat_oe <= 1;if(cnt == 31) begincnt <= 0;state <= 2;endend2: begin// assert SDAT before starting clocki2c_sdat_out <= 0;cnt <= cnt + 1;if(cnt == 31) begincnt <= 0;state <= 3;endend3: begin// shift out the entire packeti2c_sdat_oe <= shift_oe;i2c_sdat_out <= shift;clk_cnt <= clk_cnt + 1;if(clk_cnt == 127) begin// toggle clki2c_sclk <= ~i2c_sclk;if(cnt == 28) begin// donestate <= 4;i2c_sclk <= 1;//i2c_sdat_out <= 0;endendif(clk_cnt == 64 && ~i2c_sclk) begin// do shiftshift <= {shift[27:0], 1'b0};shift_oe <= {shift_oe[27:0], 1'b0};cnt <= cnt + 1;endend4: begincnt <= cnt + 1;if(cnt == 64) i2c_sdat_out <= 1;if(cnt == 127) state <= 5;end5: begin// return to idle statei2c_sclk <= 1;//i2c_sdat_oe <= 0;state <= 0;endendcaseendendendmodule

author: millerb
author_rank: Regular Contributor
timestamp: June 12, 2013, 07:11:29 am
content: There's a ton of various interface examples in verilog and vhdl on Lattice's website:http://www.latticesemi.com/dynamic/index.cfm?fuseaction=view_documents&document_type=49&sloc=01-01-02-12&source=sidebarObviously has nothing to do with your specific chip or board but they're good examples of the nuts and bolts of things.

author: fpga
author_rank: Regular Contributor
timestamp: June 12, 2013, 08:06:57 am
content: Some of the useful things FPGAs are used for is to add custom peripherals to microcontrollers, signal pre/post processing, and hard real time control. Think of FPGAs not only as glue logic or to replace commonly available interfaces, but as custom peripherals or controllers that implement multiple features in one custom device.

author: ChrisW
author_rank: Contributor
timestamp: June 12, 2013, 08:48:31 am
content: Interested in purchasing a terasic board, but can't decide between DE1 or DE2. Anybody have any recommendations? I am a newbie to fpgas. Is it worth the extra for the DE2 considering I am new to fpgas?Cheers

author: millerb
author_rank: Regular Contributor
timestamp: June 12, 2013, 11:02:04 am
content: Quote from: ChrisW on June 12, 2013, 08:48:31 amIf you're just cutting your teeth on FPGAs, I wouldn't go with an expensive board. Why not check out the DE0 Nano?Also, I believe Terasic ships from Taiwan which can be expensive depending on where you live. I got mine from Digikey.

author: Christe4nM
author_rank: Unknown
timestamp: June 12, 2013, 12:26:03 pm
content: I started out with the DE0 nano as well. The reason I switched to the DE2 is that I didn't want to spend time building all sorts of peripherals when my aim was get into VHDL. I felt it would interrupt my "learning flow" at that time. In my experience the DE2-115 is overkill for a starter. It offers hardware (interfaces) beyond what you might ever need. Looking back I should have thought a bit more about purchasing, but hey, I got the money back then and academic pricing so I went for it.The DE0-nano is a very good starting point. Use it with your breadboard and you can do for a long time. When you want just a bit more I/O options instead of doing it yourself (like audio codec, VGA interface, 7segments) the DE1 seems capable enough for a long time.One thing I missed on the DE0-nano was SRAM. But then again, the Cyclone IV offers a lot of internal RAM which is quite versatile to configure, so I understand why they did SDRAM only. On the other hand the DE0-nano has a nice ADC, EEPROM and G-sensor.Maybe the best thing to do is browse the web a bit to look into some projects that you think you might want to do and what hardware you'd need. Compare the DE series board specs and decide then what you think you need in the board and what you could put on your breadboard or even custom made pcb.

author: legacy
author_rank: Super Contributor
timestamp: June 12, 2013, 01:59:32 pm
content: is there an example of how to build SPI master/slave devices in Verilog ?

author: Christe4nM
author_rank: Unknown
timestamp: June 12, 2013, 02:43:39 pm
content: Try this link. This is not meant to be rude or something, just that if you know what you look for you can find an answer very quick. It's just a matter of spending a little time finding the right combination of search terms. In most cases you'll never be the first to ask a question and reading through the answers to others will guide you to yours.

author: lorth
author_rank: Contributor
timestamp: June 13, 2013, 05:05:57 pm
content: I would suggest DE-0, not the nano, has a few more connecting capabilities despite having an older and smaller Cyclone, but, for what you are saying is not like you are going to max it out...

author: fpga
author_rank: Regular Contributor
timestamp: June 13, 2013, 07:51:18 pm
content: Quote from: legacy on June 12, 2013, 01:59:32 pmSee Lattice Semiconductor website.

author: mrflibble
author_rank: Super Contributor
timestamp: June 14, 2013, 02:11:25 am
content: Quote from: legacy on June 12, 2013, 01:59:32 pmhttp://www.fpga4fun.com/SPI.htmlOther than that ... SPI is a pretty simple interface so doing it yourself is actually a good way to learn some verilog & testbenching skills.

author: legacy
author_rank: Super Contributor
timestamp: June 14, 2013, 12:37:10 pm
content: What about Actel ?

author: lorth
author_rank: Contributor
timestamp: June 14, 2013, 07:39:32 pm
content: Actel is good for low power and RAD tolerant FPGAs, but for size and speed,they cannot compete with Xilinx and Altera... theIgloo Nano Starter Kitis not a bad option... is a good dev kit. It uses theLT3080 though, but I have to say I haven't had any problems with the board...

author: fpga
author_rank: Regular Contributor
timestamp: June 15, 2013, 03:17:06 am
content: For those just starting out with FPGAs, get a well supported Altera or Xilinx development board with a nice large FPGA and all of the interfaces you're interested in on the board. Once you have done several projects and have a good handle, then go exploring the other vendor's FPGAs and CPLDs.Well supported development boards have documentation, example projects, tutorials, support websites, blogs, and a community of users eager to help out. The problem with the no-name boards is that they will generally lack documentation, have minimal examples, and nothing else. Using small devices or those designed for special applications will be even more trouble.Also the Altera and Xilinx FPGAs are SRAM based, which means that they are programmed with the bitstream each time they are powered on, so they have no limit on how many times they can be reprogrammed. With the non-volatile EEPROM and Flash based devices, such as Lattice and Actel, they take a much longer time to reprogram and are limited to around 100 times that they can be reprogrammed.Once you are fluent in FPGA design, then by all means, try them out.

author: MyCo
author_rank: Contributor
timestamp: June 15, 2013, 08:16:42 pm
content: Quote from: fpga on June 15, 2013, 03:17:06 amThis can happen to you also with the big names like Terasic and Digilent. I've the Altera DE2 and the Basys2, the examples that are included are just completely useless. eg. The DE2 comes only with Verilog examples... for the more advanced peripherals, the examples use a Softcore. This means, there is no pure Verilog/VHDL demo that uses RAM or Flash.The examples for the the Basys2... how can I say it... don't work! There are two versions of the Basys2, and when you have the bigger version you have to change the examples by hand, before you can test your board.I think an open source board like Papilio is a better start than Xilinx or Alteras own Dev.Boards:http://papilio.cc/index.php?n=Papilio.PapilioOne

author: fpga
author_rank: Regular Contributor
timestamp: June 17, 2013, 07:46:14 pm
content: Quote from: MyCo on June 15, 2013, 08:16:42 pmI didn't realize that the Terasic and Digilent would be so bad! I had my start in FPGAs well before Terasic and Digilent were prevalent, and so learned the hard way on whatever FPGA based board I could get a hold of. Both Terasic and Digilent focus on the education market, and I presumed that if anyone, they would be the ones with the most extensive tutorial and example material.The boards from Altera and Xilinx ARE open source. You get full schematics, manuals, gerbers, and for some even the schematic and layout source files. This is also true with the Avnet and Arrow development boards, though they are more limited with the tool versions they support or the extent of the examples. The only downside with Altera and Xilinx boards is that they tend to be expensive unless you can get them as part of a training seminar at a big discount.One truly extensive board is the Digilent designed Avnet Xilinx Zynq based Zed board (zedboard.org). At the prices they are offering the board, both the academic and the regular price are subsidized by Xilinx. Even though this board has extensive capabilities with or without using the dual core ARM A9 processor, it is an advanced board and could be intimidating to beginners. Also most of the examples focus on the use of the ARM SoC rather than the FPGA fabric. It will take a while before you outgrow this one.Altera has also released their dual core ARM A9 SoC FPGA device and board. Right now they are offering training classes world wide, and in the U.S. you get the board with the $99USD registration.Given that the quality of the training material and examples can vary, its probably best to first find the examples and training material most appealing to you before spending money on a particular board.

author: marshallh
author_rank: Unknown
timestamp: June 17, 2013, 08:32:03 pm
content: Terasic make almost all the Altera dev boards (even the ones that are supposedly sold by Altera themselves)They are quite good hardware generally.However, the code examples generally fall into the "lego blocks" type with SOPC builder and Qsys emphasis. E.g. the SD example uses a NIOS softcore to bang on the SD interface and parse the FS.The FPGA vendors tend to push total system integration into one fpga. This is simply not cost effective nor practical for many applications. It almost always makes more sense to have a basic fpga and standalone CPU next to it on the PCB.So while the hardware is a good base, don't expect to gain much from the sample code. In fact there is so much shitty HDL on the internet I ended up just writing everything on my own. It tends to be quicker and less painful than trying to adapt someone else's crappy code for my own purposes."fpga"'s advice on the last page was spot-on with regards to the vendor software.There is no free lunch with FPGAs. If you want to get good you need to SLOG, SLOG, and SLOG. You can be a pro MCU/software coder and be complete shit with FPGAs, it's common. The way of thinking required is extremely different and if you want to write good HDL that utilizes the hardwre efficiently you can't just throw softcores and endless layers of abstraction at the problem.

author: nctnico
author_rank: Super Contributor
timestamp: June 17, 2013, 10:46:09 pm
content: The latter goes for writing software as well. If you want to whip something together quick then softcores / libraries are the easy route but don't complain about performance or needing work-arounds to get it working