draw lines, circles, squares on FPGA by mouse and display on VGA ( not use NIOS)

hi ! im from vietnam . my english is not good , i hope you can understand what i say . thanks ! i have project to graduate university . my project is draw circle , line , triagle in FPGA , display on VGA ( only use verilog , don't use C) . i have many problems , and time is running out . if you have data , code about it , please help me. .... thanks you so much !

Reply to
lexuancong
Loading thread data ...

I don't have any code, but the usual VGA display logic takes a block of memory and writes that out repeatedly. If you don't need color, write the same to all three outputs.

Then you have to figure out how to get the shapes drawn into memory.

As it doesn't change, easiest is to load it in a a constant (ROM) that you have to somehow generate. You can write a ROM initialization table in any language, then translate that to verilog.

But first you need the display logic. You need a high speed clock, a row counter, and column counter. You need to generate the syncronization pulses of the appropriate width and length.

That is as close as I can give now.

-- glen

Reply to
glen herrmannsfeldt

The "video controller" section of Opencores has some VGA controllers source code.

formatting link

There is a line drawing implementation in VHDL.

formatting link

(I've never tried these projects, so I don't know how useful they are.)

Hope this helps, Jean-Marc

--
http://www.cod5.org
Reply to
Jean-Marc Lienher

First get your FPGA so that it generates valid VGA sync signals (and a pixel clock, if VGA needs that). Once you've done that, then do some bog- simple thing with your pixel generator, like putting out eight white pixels followed by eight black ones -- that should give you vertical stripes on the screen, to show progress. Then figure out how to read pixels out of memory. Finally, stuff the memory with your circles, lines and squares.

Do you have any friends in the class who are similarly bogged down? Helping one another isn't a bad idea.

I don't know how your prof is planning on grading things, but if this were a US university, getting partial functionality is going to be better than nothing -- a C isn't as good as an A, but it's a lot better than a D or an F!

--
www.wescottdesign.com
Reply to
Tim Wescott

I have implemented a VGA signal generator, line drawing and bit-blitting in VHDL:

formatting link

You could take a look at it, try to understand how it works (with ModelSim you can even single-step the VHDL code and watching how the registers changes) and then try to implement it yourself in Verilog. For circles there is a modified Bresenham algorithm. Triangles are trivial, if you don't need to fill it. If you need filled polygons, it gets a bit more interesting.

--
Frank Buss, http://www.frank-buss.de
piano and more: http://www.youtube.com/user/frankbuss
Reply to
Frank Buss

Hi I am in the same situation with the same project. can u please help me

Reply to
ajbhavana89

Implement a simple CPU on the FPGA and do the drawing in software.

Reply to
Herbert Kleebauer

Have fun.

Adam

Reply to
Adam Górski

(snip)

The usual way to run a VGA display is in raster mode reading from a display RAM. First write the code for that.

Then write code to load the appropriate shapes into memory. (First clear it to background color.)

That should be a relatively simple state machine, though the easier way is probably to build a simple processor and execute compiled C code. (Or some other language.)

-- glen

Reply to
glen herrmannsfeldt

I think you need to turn in code, diagram, all in paper right?

If so you can do searchig on net, some folks here are really good help

On the basic, you need a cpu, a video frame buffer (sram, sdram, ...) that can hold let say 640 x 480 pixels vga... And your FPGA is the center of this project, you use the fpga to glue all together and to make them to work

The cpu somehow needs to take the mouse input to generate pixel data and write it to the buffer

On the other hand, the FPGA has to read the data out from the buffer in raster manner and display it on screen

anyway, this sounds a big project if you do it all by yourself, unless you already had some support

your professor must be the first one to ask...what have he taught you, what hints he can suggest, what evaluation board available etc...

Reply to
Mawa_fugo

Overkill.. the video memory can be a ROM preloaded with the video image. The ROM is just a big case statement (the tools will infer a ROM). Use run-length coding so that it will fit on the chip (avoiding external memory interface, allowing it to work on small parts). I think it's just about 100 lines of code.

endmodule

--
/*  jhallen@world.std.com AB1GO */                        /* Joseph H. Allen */ 
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0) 
+r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p158?-79:0,q?!a[p+q*2 
]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}
Reply to
Joseph H Allen

(snip)

(snip)

The OP didn't say how the shapes got into memory, just that they were there. One could just build the logic to generate them and store them on start up.

Well, another way is to generate the bits without storing them. (Closer to how it was done years ago.)

Say you wanted to just draw a rectangle on the screen. You could store the top and bottom scan rows, and left and right positions in the row. Then run row and column counters, and when they are between the appropriate values, output white, otherwise black.

That doesn't take so much logic, so you can do a few of them. Not a lot more logic will get you a Pong game from years ago.

Generating a circle that way is a little more work, but not an impossible amount. Triangles and trapezoids, not so hard.

-- glen

Reply to
glen herrmannsfeldt

Ahhhh, you caught me on this, ... btw hello, long time no chat to anyone in this group ...

Anyway, the OP might/might not say that... I read his title twice, and thought that he want to: "draw lines, circles, squares on FPGA by mouse"

I'm still not so sure what he wanna do, just imagine ...when user click the left button on the mouse and make a circle-like movement, on his/her vga screen will then display a circle-liked shape, still not sure it's perfect circle or an egg alike ???

That's interesting, that you can do the 'direct draw' like that from the logic... the rectangle is piece of cake & pretty easy to understand, ... I wonder how to do that for other shapes like you said ?

Reply to
Mawa_fugo

(snip)

(snip, I wrote)

Could be. But just drawing some figures is a not too simple, but also not too hard project for an introduction to actually building logic.

That is pretty tricky to do all in hardware. Well, as a combination of state machines not so hard to do. One state machine to keep track of the mouse position, (and generate the cursor), another to keep track of what the mouse is doing, then some more to draw the figure. But only after you know how to draw figures.

(snip, I also wrote)

One way is with some form of Bresenham's algorithm. That is mostly used for drawing lines instead of filled shapes, but should also work for filled shapes. There is also a related algorithm for circles.

Another is with a phase accumulator to keep track of the starting and ending points. Consider a binary value with the binary point not just after the ones bit, such that it can hold fractional values. Now, each cycle (scan line) you add a binary value approximating the slope of the line. The integer (ignore fractional bits) value is now the starting coordinate on that scan line. For curved shapes, you could find the start and end points with some form of CORDIC.

Once you have the start and end points for each scan line, all you need is the logic to determine inside and outside, and generate the appropriate output signal.

In the days of expensive computing hardware, it was more usual to do something like that, though maybe more usual to do it with analog electronics.

There were some fairly expensive vector graphics systems that continually refreshed the display from a display buffer. With the two end points of a line segment, some D/A converters, and some analog circuitry you can generate the X and Y values long a line segment. Charge two capacitors with the appropriate currents, and the voltage as a function of time will be reasonably linear.

Then there were the Tektronix terminals based on storage CRTs, as developed for oscilloscopes. The image is stored as charge on the screen.

-- glen

Reply to
glen herrmannsfeldt

Hi all,

to the OP: you can examine PLOTLINE and PLOTCIRCLE, two demo IPs by Ajax Co mpilers

formatting link
They come for FREE, just register t o the Ajax Compilers store. They are ZERO EURO, no cost, totally free IPs, just give them a shot. They come with reasonable documentation and a demo p latform setup for a Spartan-3AN starter kit FPGA board!

If you are in a hurry, I have another version for the Bresenham line drawin g function here:

formatting link
(scroll down, there ar e lots of other materials on high-level synthesis there). It is called "lin edraw" there.

In short, I have used pure C code implementations for both the line and cir cle drawing algorithms, and then passed them through HercuLeS (my HLS tool) . It is purely automated work, no hand coding please, this is 2013 and I'm an EDA tool developer (LOL)

I also have lots of other graphics primitives stuff, like an ellipse algori thm, etc. I don't recall having implemented a flood filler in hardware. I t hink you can do better than iteratively running Bresenham's algorithm. If y ou do this, you will have to make a second pass, patching untouched pixels (this is what it looks like at first glance).

Hope these help.

Best regards, Nikolaos Kavvadias

formatting link

Reply to
Nikolaos Kavvadias

I'm happy to point you in the right direction, but I don't think it's appropriate to provide code.

In our product I create concentric circles using the Bresenham's circle algorithm on raster display and is ideal for square pixel formats. It is possible to vary the theme to make ovals, or even circles on non square pixel formats.

The algorithm doesn't need a multiplier, but most FPGAs have a wealth of ALUs such that it might be just as appropriate to calculate squared numbers using an ALU.

Google will find a number of articles though some are more confusing than others. I had considered adding an article myself to our website but just haven't got around to it!

Similarly for drawing lines, have a look at Bresenham's line algorithm, but that is something I have never used! I've stuck to only drawing horizontal and vertical lines!

--
Mike Perkins 
Video Solutions Ltd 
www.videosolutions.ltd.uk
Reply to
Mike Perkins

There is wrong topic. It is more like "Do my homwork for free" not "help me understand my problem " Don't u see !?

Adam

Reply to
Adam Górski

Probably a moot point as the original post came two weeks ago and the OP has disappeared since then. This seems typical of the "do my work for me" threads. While the community has fun discussing possibilities, the original poster has missed his deadline and is now flipping burgers.

--
Gabor
Reply to
GaborSzakacs

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.