Skip to main content
GameDev.net gamedev.net
🔒 Locked

Trying to build a calculator.

Started by Sagar_Indurkhya Oct 14, 2004 at 1:51 PM 44 replies 7.9k views
Original Post
Sagar_Indurkhya
Sagar_Indurkhya
Ok. I am trying to build a calculator that can add and substract 8-bit integers from each other. I won't be using a ALU, because that takes the fun out of it!!! I have a couple books, and understand how to do it. However, I know that in an ALU, everything is perfectly measured, timed, etc. If I make my own circuits, is having one of the inputs to a and-gate having a small delay going to make a difference? I mean, I am going to radioshack to buy my gates, and wire and crap, but I know I can't cut those wires with extreme accuracy. Also, does anyone know of any free software that lets me build and test circuits virtually? Thanx!
smart_idiot
smart_idiot
Try searching for spice.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Promit
Promit
I take it you want to build this calculator without using a microprocessor. You will still have an ALU, you're just not using a pre-built ALU.

Quote:

If I make my own circuits, is having one of the inputs to a and-gate having a small delay going to make a difference?

There's a given latency for each gate, and a total latency for a given circuit that is just a touch above the sum of all the individual latencies. If this latency value is higher than the time between clock cycles, then you're going to have problems. Big problems.



There's a programming language of sorts for designing integrated circuits that is called Verilog. It lets you define registers, pieces of the ALU, etc. and put them together into a design. To be perfectly honest, I've never used it. From what I can gather, it's a tool for designing integrated circuits and won't be too much help.

Actually, spice is probably a good choice.



Now, design stuff. I suggest you start simple, by building an 8 bit adder. Do you have any idea what you're doing, or do I need to elaborate on the typical construction of an adder?

After doing the adder, you'll probably need to construct a register file. RadioShack sells flip-flops which will suffice for this purpose (not ideal, but they'll do). If you're working in 8 bit, you'll need 8 flip-flops per register. You want D type flip flops, which are numbered 4013 in CMOS; they're 74HCT174 in TTL, as sold by Radio Shack. The 74HCT174 is probably the easier one to get a hold of, since I can't figure out if Radio Shack carries the 4012 or not. The 74HCT174 is a Hex D-type flip flop, which is a little weird, since it doesn't really fit into 8 bits neatly. What you do about that is up to you.

You'll need a minimum of 4 registers, eventually. You'll need to have Source 1, Source 2, Dest, and Instruction. This isn't a proper chip design, mind you; it'll just add/subtract Source 1 and Source 2 and put the result in Dest on every clock cycle. (If you don't have a proper clock, you definitely, definitely want a bounceless switch of some sort. Touching 2 wires together will NOT work.)
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
mnansgar
mnansgar
Beige Bag's SPICE is a good choice for a simulator:
http://beigebag.com/adv4_lite.htm.

Another way that might be a little less aggravating is to use PLDs (Programmable Logic Devices) if you have access to a programmer. Using one of these, you can type in the logic expressions using a hardware description language such as ABEL then the computer will automatically optimize your logic and weld/unweld tiny connections in the PLD.

A good resource for building an entire computer (including its ALU) by only using PLDs and standard logic gates is the supplemental chapter here: http://shay.ecn.purdue.edu/~dsml/ece270/Refs/index.html. The ECE270 site also has some lecture notes that might help with ALU design (although they're incomplete).

Don't worry about wire length when you're building your circuit -- since electricity flows at almost the speed of light, wire length is negligible. However, a timing diagram is important because sometimes signals can be sent before you want them to be depending on the "lag" times of the gates involved. There are some components such as latches perhaps that you can use to synchronize signals.
h20, member of WFG 0 A.D.
Extrarius
Extrarius
In addition to Verilog, there is a language called VHDL[1] that is for designing such circuits as you describe.

Reguardless of which you choose (Verilog or VHDL), there are freely available packages from all major FPGA manufacturers that will allow you to turn your hardware description into a cirtcuit diagram and then simulate it. If you want to actually build the device with an FPGA, that can be costly (well, compared to buying the 20¢ logic gate chips), but it is also much more rewarding because you can easily(relative to using gates) build HUGE logic circuits in the same chip that your very basic calculator will occupy, and you can have all kinds of fun doing really advanced things (one guy for ex is building a processor that runs java bytecode natively in an FPGA using VHDL). You can get a complete starter kit (with all the hardware you'd need to program an FPGA and play with it etc) for $99 from Xilinx, and that includes a fast RAM chip, LEDs, LCD, VGA out, etc etc all preassembled on a board so all you have to do is program the chip to take advantage of all the things on the board.

1: From dictionary.com: Very High Speed Integrated Circuit (VHSIC) Hardware Description Language. A large high-level VLSI design language with Ada-like syntax. The DoD standard for hardware description, now standardised as IEEE 1076.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Sagar_Indurkhya
Sagar_Indurkhya
Yeah, I'm a programmer, which is why it amazes me how what I take for granted is so complex. Ok, I know how to make an 8 bit adder and substracter. The book I have showed me how it is done, and then told me that I can just use the ALU IC to do it for me. The diagrams very pretty intricate, and my hands aren't the most intricate things.

It tells about all these different types of inverters and flip-flops to store something, and they are used for registers. I am gonna check out spice. How much will this cost me? Is there anyway to make my own professional circuit boards? cuz those IC connections are tiny.
smart_idiot
smart_idiot
Buy a breadboard.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Sagar_Indurkhya
Sagar_Indurkhya
Um... Spice is like a command prompt? I was looking for something graphical, like VB :) I have only $20 dollars I can spend for this. Once I get this to work, I want to build a really crude computer that has a small ram, with a crappy processor. Just for fun.
cmptrgear
cmptrgear
I have used both VHDL and Verilog to program FPGA/CPLD chips and I would have to say that Verilog is much easier to use from a programmers standpoint since it has a C like syntax. Having built a lot of digital circuitry it can either be fun or the most frustrating thing you have ever worked on depending on what sort of bugs pop up.

You didnt mention how you plan to put things together but I would suggest buying a breadboard. It makes this kind of thing much easier to build since you wont have to solder anything.
Here is a picture of one of mine

Just to give you some motivation and to let you know it is possible I built a 16 instruction RISC processor which ran at 10MHZ while I was in college. Man that was an awesome class, some groups spent 24 hours straight in the lab trying to get it to work before presentations were due. I think the chips in that picture are some of the ones I used in the processor.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
Extrarius
Extrarius
Quote:
Original post by Sagar_Indurkhya
Um... Spice is like a command prompt? I was looking for something graphical, like VB :) I have only $20 dollars I can spend for this. Once I get this to work, I want to build a really crude computer that has a small ram, with a crappy processor. Just for fun.
For the computer, you're going to need an FPGA or something similar. If you just bought logic chips and wired up the circuits for a processor and RAM etc, it would be HUGE and cost probably 50 times as much.

For the calculator, I suggest you just use the software from Xilinx or Altera or another company and program the circuit in VHDL or Verilog and just simulate it. When you're ready to do 'real' stuff like the computer, you can buy the Spartan 3 Starter Kit for $99 with VGA output and the like built in so you can 'easily'(compared to having to start from nothing) make a computer. You can download the free software at the same website (Xilinx.com).
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Sagar_Indurkhya
Sagar_Indurkhya
Does someone know of a tutorial(not a college one with a shit load of greek letters etc) that will tell me about the different kinds of IC's, and basic computer architecture there is? Also, is their a virtual breadboard I can practice on my computer, rather than breadboard everything?

My ultimate goal is to make a computer, that runs at preferably 30mhz, with components such as multiple CPU's etc. I enjoy dreaming: it's a hobby.
etothex
etothex
Quote:
Original post by Sagar_Indurkhya
Um... Spice is like a command prompt? I was looking for something graphical, like VB :) I have only $20 dollars I can spend for this. Once I get this to work, I want to build a really crude computer that has a small ram, with a crappy processor. Just for fun.


Tradition weighs heavy in circuit design...remeber, people were designing these things long before each engineer had his/her own graphical workstation.

Usually this is taught in a 2 semester electrical engineering course, from basic logic design to constructing a (limited), MIPS-like microprocessor. If you're really interested in this, a course like that would be the best thing.

If you want to DIY, I think there's some free verilog simulators out there somewhere. You could maybe design an ALU for a calculator on paper, but pretty soon you'll want to switch to software design tools.

Oh, and on the delay, you could probably build an 8 bit adder/subtractor without worrying about delay, etc.
cmptrgear
cmptrgear
Aha, if you just want a simple circuit simulator to fool around with you can try out this one.

Circuit Maker

This is the one I used in college. It is free since it is a student edition but it doesnt have a total list of parts. However for what you are doing it should have enough. It definetly has D Flip Flops and basic Digital Gates. I dont know what your background in electronics is, so it may or may not be hard to use.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
Sagar_Indurkhya
Sagar_Indurkhya
Wait. I am going to use a prebuilt ALU, because I just realized that I don't have tons of time to reinvent the wheel(happens periodically). So making a 8-bit adder should be very simple.
Where can I find a map of the input and outputs of an ALU chip?
Sagar_Indurkhya
Sagar_Indurkhya
I was just wondering, but once I build a simple microprocessor... and ram... how do I input and output? I mean, should I build my own black and white monitor out of christmas lights? For input, should I design my own keyboard? Is it possible to run linux? What about java? "Code once, run everywhere?"
Xiachunyi
Xiachunyi
Hello, I am building a computer(4-bit) for my senior project. I would suggest the TTL family for your chips since seem, to me, very easy to work with.

This website has a plethora of information on constructing such home-made computers. As for pin-out information, you can visit manufacturer's, such as Fairchild, Texas Instruments, Motorola websites to download their data sheets. The ALU you are probably looking for is the 74181.

Home-made computers utilizing pre-made processors One of the links even has a person interfacing through a monitor with his own built VGA card.

Good reference for constructing power supplies
benryves
benryves
For IO ports, you could just map memory addresses to physical connectors (ie, memory addresses 0x00 and 0x01 could be an 8-bit input port and an 8-bit output port).
For input: you could build a keyboard, I guess, but the AT protocol used on PS2 keyboards is quite easy to get your head around. For output: try a cheapy LCD? Or just a simple dot matrix of LED's for starters - multiplexed? *musings*
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Extrarius
Extrarius
Quote:
Original post by Sagar_Indurkhya
I was just wondering, but once I build a simple microprocessor... and ram... how do I input and output? I mean, should I build my own black and white monitor out of christmas lights? For input, should I design my own keyboard? Is it possible to run linux? What about java? "Code once, run everywhere?"
You can do it however you want. The easiest way would be to just attach a vga port and use a regular monitor for output (of course your system will have to generate the correct signals on the correct pins at the right frequency) or you could use an LCD (easier since for character LCDs all you have to do generally is tell the controller 'display an A, B, C, F' and like magic it is on the LCD screen). For input you could just use a PS/2 port with a regular keboard, or you could just attach two buttons and input binary or do whatever you want =-)

How you get your processor to talk to the output depends on how you make the instruction set - you could have 'ports' that the pc can talk to, or you might make them 'memory mapped' so that memory address X is really device Y, etc.

A good place for getting random parts is All Electronics.com. They're a surplus store or something like that, so their inventory is somewhat random and varies once in a while, but what they have, they generally sell for much, much less.

That is the magic of hardware design - you get more freedom even than software engineering because you get to create the system that the software runs on.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Promit
Promit
Sagar, decide what exactly you want to do. Designing a mini-microprocessor out of standard gates is one thing. Building a calculator-ish thing from pre-built microprocessors and components is another. Output requires a totally different study.

Make up your mind first.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Sagar_Indurkhya
Sagar_Indurkhya
I want to build my own computer. I will design the microprocessor myself, but use prebuilt ALU IC, etc. I have a VGA monitor, so I can use that. I looked at the design for a simple calculator that lets me enter two binary numbers, and operate on them. It is really just 5-6 components since I already am using a prebuilt ALU IC.

My plan is this: Each component of my little computer will be on a seperate card. That way, if I decide to upgrade my processor, I don't have to rip it to pieces. I want to be able to use a floppy drive as well. Basically, I have a Dell Pentium 90 with a busted video card(cuz I was trying to rearrange my CD ROM bus, and put it in wrong place.). I have an old Floppy drive, a cdrom drive, 64mb memory, and 5gigs of harddisk space.

For the processor, could some one be so kind and tell me how much time it takes to make one? The idea I have is to have a decoder, which decodes the instruction, loads the appropriate stuff, and then operates on them. First, what kind of ALU IC should I buy? Should I try to build it up myself, or should I design it on the computer, and then pay some company to do it for me? I am leaning towards the latter. Also, I have maximum of $50 for this.

I am thinking to make it a 16 bit cpu? I would have maybe 8 registers, 4 for the two operands, one for instruction, and one for result, and then 4 more for a cache of somesort.

For the cpu clock, I am planning to buy one from radioshack or something. Any pointers?

For my memory... I would like to make my own, if it isn't too expensive, but if it is possible... and cheap, I would like to us ED or SD ram.

How do I learn about the interface specification between these harddisks and ram and crap? is there a super standard? I don't want to end up just buying all my parts prebuilt.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.