Author Topic: Lets Learn Verilog!  (Read 11161 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
So for satanmas i got an fpga dev board:

https://www.sparkfun.com/products/11953

its a no frills board, doesnt have cool **** like dacs and large banks of ram and the like. doesn't have a lot of interfaces besides epic gpio, but thats ok i can add those on. what it does have is an mcu that makes it easy to upload your netlist to the fpga.

an fpga is a blank slate. pretty much a bunch of configurable logic cells that you can wire together by configuring switching matrices. logic cells are versatile little things which you can configure as any low level logic device. its pretty much just a look up table, or just a small bit of memory that stores an arbitrary truth table, some muxes and flip flops as well. by storing data in the lut, you define what the cell does. my fpga has over 9000 of them, grouped together in slices. there are also lines for propagating clock signals, some other clock hardware (clock multipliers/dividers). there is some memory as well.

fpgas are used when you need custom hardware, but cant afford the fab costs. they are used in a lot of video processing hardware, trackir uses one to turn a lot of pixels into a few vectors. you can design a custom cpu or gpu on one, or to validate new architecture designs. will probibly start out on some kind of video generation project at first.

so why is this on programming?

to configure an fpga i need to learn verilog. verilog is a hardware description language similar to c. this code is used to generate a file that will be stored on a flash chip to configure the fpga when it starts up. the key difference is you are defining new hardware, not creating instructions for existing hardware. variables are mapped out to physical wires, they are not memory. interfaces to memory dont even exist until you define them.

this will be a long drawn out process. i just got the toolchain setup. and i barely skimmed the wikipedia entry on verilog. il have to stop and build hardware every now and again. ive got a long list of tutorials to play with. code will follow.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Minecraft
    • Steam
I've got a book or two on VHDL from a stupid course in Uni. The course (actually 2 of them) pretty much flopped because of troubles with the professor not having some sort of plan from the get-go.

Anyway, one notable thing that we did is that we used some of the excess gates to test the circuit that we where designing, basically allowing us to set a state or variable of some sort from the monitoring program and see what happens. We used that Altera software, which doesn't seem to be particularly good as a learning tool, but it does work.
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
finished the last tutorial, and i dont think i learned very much at all. all the tutorials pretty much did was cover stuff you would be better off with a micro controller to do. but i think i got enough of a handle on the hardware and verilog to do an actual project that i give a **** about.

ive attempted to design a video card from scratch before, using discrete logic components. my design was massive, i didnt have the right parts. the project never got very far beyond an oversized eagle schematic. the fpga lets me do things in a less masochistic way.

first order of buisness is a framebuffer. the fpga has about 512k of dual ported 9-bit (8+pairity bit) memory + an extra 90k of distributed memory. obviously the frame buffer will go in the 512k section. it will be a dual buffer so each frame needs to fit in 256k. my color depth will be 3'3'3 rgb, making use of the otherwise unused parity bit. now i cant quite get the vga standard of 640x480, i dont have the memory, the closest i can fit is 552x414, which will mean a border and not much room for anything else. if i drop down to 320x240, i can free up memory for other things like pallets and sprites. the abundance of pins however makes it possible for me to just stick a fast dram on an expansion board, but that will require me to build something, so il just use what i got.

video cards have more than just a frame buffer. if i want to do any kind of layering or 3d, i need a z buffer. i can still get 320x240 if i go with an 18-bit frame buffer giving me 9 for color and 9 for z. obviously 512 steps of z probibly wont look very good. i can borrow some bits from color in favor of z. if i use a 2'2'2 rgb color space, then i can have a 12 bit z buffer, or if i want more z, i can do 16 color pallets (in the 9'9'9 color space) with a 14 bit z buffer. if i dont eat up too much logic, i may even be able to do 27 bit frame buffer with 9'9'9 color and 18 bit z. so i have lots of options.

the pixel clock will probibly be pretty fast. i will need to use a counter and some comparators to generate sync pulses and another counter for the memory address, which will be counted up when i need the next pixel in sync with the pixel clock. i need to do the math to figure out what this will be. its dual ported ram, so all this stuff will be isolated from the part that does all the work. collisions shouldnt be an issue if i put each frame in different memory banks. i can render one and output the other.

to do a 3d card means i will need to have to do vector and matrix math on the fpga. fortunately it has 16 dsp slices on it which each have an 18 bit multiplier and a 48 bit accumulator. this should handle matrix multiply, dot products, vector transforms, lerp, etc quite nicely. probibly wont get things like lighting, or textured polygon fill, or shaders.

then there is communication. the board comes with a usb serial interface which i will use for initial testing. i can issue rendering commands over serial (all be it at a fairly slow rate), but eventually i will just do a synchronous parallel interface to speed things up. it will feed a fifo and commands will be handled as fast as possible.

obviously the first order of buisness is to output a usable vga signal. namely figuring out the frequency of the pixel clock, and all the timings.

anyway put a little effort into designing a resistive dac. unfortunately i dont have any female vga ports laying around, so i have to destroy a cable. the good news is i have spares. i can just use some strip board and some headers i got, and i have more resistors than i know what to do with. i considered using some buffers to boost 3.3v to 5v, and to isolate the fpga, but it turns out this is not neccisary. since the vsync/hsync signals can be 3.3v, and the resistors will be high enough to limit any feedback current. analog signals need to be 0-0.7v, and i may need to stick a divider on each ladder to bring the voltage down. will put it together tomorrow or whenever. probibly build one channel on a breadboard and test it with a multimeter to verify the design and make sure my values are correct. onve the hardware is out of the way it becomes a full on code project.

« Last Edit: January 02, 2014, 09:04:01 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
i think if figured out how to build my dac. unfortunately i have to wait several weeks for my 1% tolerance resistors to arrive from china. its just an R-2R ladder with 3 inputs. this will require 4 510 ohm resistors plus 2 at half that resistance. unfortunately i didnt order any 255 ohm resistors, i ordered one of those grab bags with a bazillion different values, but it does contail 10 ohm, 22 ohm and 200 ohm resistors, which sum up to 254 ohm. close enough. if i put the multimeter to the 200 ohm resistors, i can find ones an ohm or two above the marked value (the tolerance means they can be +/- 2 ohms from the designated value), so i can probibly get exactly 255 ohms out of the whole chain. cool beans.

after some math this ladder will have an equivalent series resistance of 255 ohms. vga standard specifies an impedance of 75 ohms and wants a signal somewhere between 0.7 and 1 volts. with 3.3v logic, this creates a voltage divider to produce a value between 0-0.75v. so this is right in the ballpark.

other parts i can salvage, i took a vga port off of an old video card. im also going to use those buffer chips to protect my fpga board from any feedback from the monitor (and because i have a ****load of them and want to get rid of them). i was going to just use some radio shack strip board to build it, but the vga port has a staggered pinout so thats not going to work. i might actually need to do a custom etch, which is ok. i wanted to do several other pcbs for 5 other projects (such as a switch mode supply, a 3.3/5v breadboard supply, a custom pcb for a gamepad that i want to turn into a r/c controller, and some adapters for arbitrary surface mount parts). i can combine these into a single etch job, which gives me things to do while i wait for parts.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
Nuke, after you inevitably cause the apocalypse, I'm hanging out with you, because you'll probably get the majority of personal electronics back up and running within a week. :D

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
more than likely i will scrap them all for parts. i love questionable hardware. turn it into parts i will probibly never use.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
i seek answers for the fundamental mystery of verilog:

what's the actual difference between it and vhdl
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
verilog looks like c, vhdl looks like ada. i havent looked at vhdl yet, im just going by what was on wikipedia/things i googled.

i did get my dac layed out, will etch as soon as i fill in the empty spaces with other unfinished projects. i didnt like the transfer paper i used before so im using that $2 a sheet blue press n peel stuff. at $2 a page im going to use the whole thing, even if i just end up printing a bunch of adapters and other prototyping stuffs. if i run out of things to do before my parts show up im just going to take the one channel prototype dac and try producing a b&w composite tv signal (no color since i dont have an ad725 laying around, unless i can synthesize one, i have some dsp slices to work with after all).
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Vrets

  • 27
Re: Lets Learn Verilog!
This thread immediately triggered college anxiety memories. Nobody is good at Verilog, nobody...I had to carry so many fail teams that every project felt like playing World of Tanks.

STREAM OF CONSCIOUSNESS VERILOG REFLEX POST

always @(negedge clock or negedge reset_b) begin
    if (!reset_b) begin crap = 1'b0; state = oh_my_gawd; end
    else case(state)
        oh_my_gawd: begin crap = 1'b1; if (enter) state = verilog_sux; else state = oh_my_gawd; end
        ....


 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Lets Learn Verilog!
9 years later and i still havent learned verilog.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN