Video circle generator

I would like to use a FPGA to create some simple test patterns. One of which is a circle with a variable diameter. I'm not sure where to start. Can this be realistically be done in an FPGA using minimal resources?

Reply to
Fred
Loading thread data ...

As long as you only want one circle, this can be done fairly easily. For each generated pixel, calculate x^2 + y^2, and compare with r^2. If smaller than r^2, you're inside the circle, otherwise you're outside.

Updating x^2 + y^2 is simple because you can use the previous result: (x+1)^2 = x^2 + 2x + 1, so it only involves an addition. r^2 can be supplied as a pre-calculated parameter.

For multiple circles, you can instantiate multiple copies, and mix the outputs.

Reply to
Arlet

For a single line, the Y distance from center is known - it's from your line count - and you know the desired radius so your unknowns are the leading and trailing edges for either a filled circle or an outline.

X^2+Y^2=R^2 or X = +/-sqrt(r^2-Y^2)

Here you just need to think of the center as 0,0 and make adjustments accordingly. The calculation only needs to be done once per line rather than for each generated pixel which means you have a full scan line's worth of time to do a calculation; serial aritmatic anyone?

If you don't need to ultra-tiny solution, the raw math is pretty simple in an FPGA with embedded multipliers and a simple square root algorithm.

Reply to
John_H

Yes, it can. In fact, it doesn't take much logic if you think outside the box a little bit. Google "Bresenham circle" to find Bresenham's circle drawing algorithm. No need for multiplies and square roots...this does it with adds and subtracts by taking advantage of the incremental algorithm for drawing a circle on a raster.

Reply to
Ray Andraka

Hi Fred,

Circle are in fact very easy to draw (or "scan convert", in the lingo). You can do it without any square-roots or even multiplies (except by 2). The algorithm due to Bresenham has been around for some time. Here's a good tutorial page:

formatting link

The basic algorithm can easily be adapted to do filled circles.

Have a lot of fun,

-Ben-

Reply to
Ben Jones

If you already have an X and Y register from your video driver, and a starting-new-line signal, then you can manage with two adders and a comparator.

Have a register initialised to cx^2+cy^2 at the start of the frame.

At the start of each line, add 2*(y-cy)+1 to the register.

At every pixel, add 2*(x-cx)+1 to the register.

If the register value is less than a threshold, light the pixel, otherwise don't.

Tom

Reply to
Thomas Womack

Ben Jones schrieb:

You

Not even that because

2(x+1) + 1 = (2x+1) + 2 You need a total of two adders and one comparator per ordinate.

Kolja Sulimma

Reply to
Kolja Sulimma

I greatly appreciate the responses here. It's made life a great deal easier!

Many thanks again.

Reply to
Fred

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.