Author Topic: Starting with fpga  (Read 11567 times)

0 Members and 1 Guest are viewing this topic.

Offline scarrierTopic starter

  • Contributor
  • Posts: 20
Starting with fpga
« on: June 11, 2013, 06:10:47 pm »
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
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: Starting with fpga
« Reply #1 on: June 11, 2013, 07:20:53 pm »
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]
« Last Edit: June 11, 2013, 07:25:19 pm by Christe4nM »
 

Offline marshallh

  • Supporter
  • ****
  • Posts: 1462
  • Country: us
    • retroactive
Re: Starting with fpga
« Reply #2 on: June 12, 2013, 12:48:50 am »
here's a basic i2c example, I think it will work the DE2's codec

Code: [Select]
/////////////////////////////////////////////////////
//
// 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,
);

input wire clk;
input wire ar;
output reg i2c_sclk;
output reg i2c_sdat_out;
output reg i2c_sdat_oe;

input wire [6:0] addr;
input wire wr;
input wire [8:0] data;
input wire strobe;
reg strobe_1;

reg [2:0] state;
reg [28:0] shift;
reg [28:0] shift_oe;
reg [6:0] clk_cnt;
reg [6:0] cnt;
output reg busy;

always @(posedge clk or negedge ar) begin
if(~ar) begin
// reset state
state <= 0;
i2c_sdat_oe <= 0;
i2c_sdat_out <= 1;
i2c_sclk <= 1;
busy <= 1;
end else begin
// normal operation
strobe_1 <= strobe;
case(state)
0: begin
busy <= 0;
i2c_sclk <= 1;
if(strobe & ~strobe_1) begin
// rising edge of strobe
shift <= {1'b0, 7'b0011010, ~wr, 1'b0, addr, data[8], 1'b0, data[7:0], 2'b0};
shift_oe <= 29'b11111111101111111101111111100;
state <= 1;
busy <= 1;
end
clk_cnt <= 0;
cnt <= 0;
end
1: begin
cnt <= cnt + 1;
i2c_sdat_out <= 1;
i2c_sdat_oe <= 1;
if(cnt == 31) begin
cnt <= 0;
state <= 2;
end
end
2: begin
// assert SDAT before starting clock
i2c_sdat_out <= 0;
cnt <= cnt + 1;
if(cnt == 31) begin
cnt <= 0;
state <= 3;
end
end
3: begin
// shift out the entire packet
i2c_sdat_oe <= shift_oe[28];
i2c_sdat_out <= shift[28];

clk_cnt <= clk_cnt + 1;
if(clk_cnt == 127) begin
// toggle clk
i2c_sclk <= ~i2c_sclk;
if(cnt == 28) begin
// done
state <= 4;
i2c_sclk <= 1;
//i2c_sdat_out <= 0;
end
end
if(clk_cnt == 64 && ~i2c_sclk) begin
// do shift
shift <= {shift[27:0], 1'b0};
shift_oe <= {shift_oe[27:0], 1'b0};
cnt <= cnt + 1;
end
end
4: begin
cnt <= cnt + 1;
if(cnt == 64) i2c_sdat_out <= 1;
if(cnt == 127) state <= 5;
end
5: begin
// return to idle state
i2c_sclk <= 1;
//i2c_sdat_oe <= 0;
state <= 0;
end
endcase

end
end

endmodule

Verilog tips
BGA soldering intro

11:37 <@ktemkin> c4757p: marshall has transcended communications media
11:37 <@ktemkin> He speaks protocols directly.
 

Offline millerb

  • Regular Contributor
  • *
  • Posts: 71
  • Country: us
Re: Starting with fpga
« Reply #3 on: June 12, 2013, 07:11:29 am »
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=sidebar

Obviously has nothing to do with your specific chip or board but they're good examples of the nuts and bolts of things.
 

Offline fpga

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
Re: Starting with fpga
« Reply #4 on: June 12, 2013, 08:06:57 am »
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.
I never did a day's work in my life, it was all fun -- Thomas Edison.
 

Offline ChrisW

  • Contributor
  • Posts: 43
Re: Starting with fpga
« Reply #5 on: June 12, 2013, 08:48:31 am »
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
 

Offline millerb

  • Regular Contributor
  • *
  • Posts: 71
  • Country: us
Re: Starting with fpga
« Reply #6 on: June 12, 2013, 11:02:04 am »
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

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

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: Starting with fpga
« Reply #7 on: June 12, 2013, 12:26:03 pm »
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.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Starting with fpga
« Reply #8 on: June 12, 2013, 01:59:32 pm »
is there an example of how to build SPI master/slave devices in Verilog ?
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: Starting with fpga
« Reply #9 on: June 12, 2013, 02:43:39 pm »
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.
 

Offline lorth

  • Contributor
  • Posts: 46
  • Country: us
Re: Starting with fpga
« Reply #10 on: June 13, 2013, 05:05:57 pm »
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...

 

Offline fpga

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
Re: Starting with fpga
« Reply #11 on: June 13, 2013, 07:51:18 pm »
is there an example of how to build SPI master/slave devices in Verilog ?

See Lattice Semiconductor website.
I never did a day's work in my life, it was all fun -- Thomas Edison.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: Starting with fpga
« Reply #12 on: June 14, 2013, 02:11:25 am »
is there an example of how to build SPI master/slave devices in Verilog ?

http://www.fpga4fun.com/SPI.html

Other than that ... SPI is a pretty simple interface so doing it yourself is actually a good way to learn some verilog & testbenching skills.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Starting with fpga
« Reply #13 on: June 14, 2013, 12:37:10 pm »
What about Actel ?
 

Offline lorth

  • Contributor
  • Posts: 46
  • Country: us
Re: Starting with fpga
« Reply #14 on: June 14, 2013, 07:39:32 pm »
Actel is good for low power and RAD tolerant FPGAs, but for size and speed,they cannot compete with Xilinx and Altera... the Igloo Nano Starter Kit is not a bad option... is a good dev kit. It uses the LT3080 though, but I have to say I haven't had any problems with the board...

 

Offline fpga

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
Re: Starting with fpga
« Reply #15 on: June 15, 2013, 03:17:06 am »
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.
I never did a day's work in my life, it was all fun -- Thomas Edison.
 

Offline MyCo

  • Contributor
  • Posts: 18
Re: Starting with fpga
« Reply #16 on: June 15, 2013, 08:16:42 pm »
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.

This 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
 

Offline fpga

  • Regular Contributor
  • *
  • Posts: 66
  • Country: us
Re: Starting with fpga
« Reply #17 on: June 17, 2013, 07:46:14 pm »
This 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

I 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.
I never did a day's work in my life, it was all fun -- Thomas Edison.
 

Offline marshallh

  • Supporter
  • ****
  • Posts: 1462
  • Country: us
    • retroactive
Re: Starting with fpga
« Reply #18 on: June 17, 2013, 08:32:03 pm »
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.
Verilog tips
BGA soldering intro

11:37 <@ktemkin> c4757p: marshall has transcended communications media
11:37 <@ktemkin> He speaks protocols directly.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27580
  • Country: nl
    • NCT Developments
Re: Starting with fpga
« Reply #19 on: June 17, 2013, 10:46:09 pm »
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  >:D
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf