Author Topic: From Full Adder to a 8bit MCU  (Read 10059 times)

0 Members and 1 Guest are viewing this topic.

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
From Full Adder to a 8bit MCU
« on: November 03, 2013, 07:41:45 pm »
So Last year I started working on a simple par of an 4Bit ALU that would do multiplication and over a course of a year it evolved to a "fully functional" 8bit

Microcontroller, although it has no practical use and is only at a simulation stage.
Even though I'm not good at explaining my work, I'd like to share it with the few it might interest, this is not a guide for how to make a MCU, but there might be some extra information in the video descriptions for the people that are interested, I've also included two whole circuit schematics.

I need to say that I'm not a professional video editor/producer and that I have dyslexia, so the grammar and poor video editing might bee too much for some people and for that I'm sorry  there is only so much Google translate can do :'(

On July 13, 2012
After a few day of designing and running simulations I made this simple 4bit ALU doing Multiplication
and recorded a very bad video of it doing a three bit multiplication of 5*6:


July 15, 2012
I incorporated addition and subtraction:

This simulation was composed of 1609 components and used up to 1.6GB of RAM, and it would often crash due to the program being out of it's memory range.

Jul 16, 2012
After several painful hours of "OUT OF MEMORY" errors I decided to simplify the circuit and use pre-made components like a 4bit ALU (for addition and subtraction)

and counters.
in the previous simulations all the addition and subtractions were mad with a collection of half adders and all the components would eat up the memory.
At that point the simulation was able to run on only 500MB of RAM.


July 18, 2012
I tried a radially new approach to the problem of RAM usage and poor precision, during multiplications.
I decided to try doing the multiplications almost "physical", by shifting the values inside a collection of SRAM chips.

by doing so I was able to go down from 1.6GB to 200MB or RAM to run the simulation.
Even though it would be great to be able to make the circuit at a gate lever, with multisim it was not possible because of the 1.6GB restriction.

Jul 27, 2012
Nine days later I made a simple division circuit that would allow me to make a semi functional "ALU" actually just an AU without the logical parts  ;D

The circuit was able to choose witch operation would output and it would do all the operations at at the same time.

It's hard to see anything in those videos, but the point is that it was somewhat functional, the main problem was that division were horrible they would not give

out the correct answer if the result were not even.


So after month of working, procrastination and neglect I made a revised division circuit, that I could be proud off.

November 5, 2012


The circuit contained only one "minor" bug that was dividing 34 with 9 (and two other combination) if would not stop dividing and eventually give out a FF as a sum,
even though I fixed it afterwards I can't really recall what was the problem, if my memory isn't that bad, I think it was some where on the top with the registers.

at that time I was even smart enough to take pictures of the circuit  ;) , because I realized that the videos didn't show enough
circuit schematic: http://i49.tinypic.com/28s5tmv.png
Block 1:http://i46.tinypic.com/20068wp.png] [url]http://i46.tinypic.com/20068wp.png[/url]
Block 2: http://i46.tinypic.com/34nppi8.png
Block 3: http://i50.tinypic.com/2ch9fdd.png
Block 4: http://i47.tinypic.com/2nlwro8.png
Block 5: http://i46.tinypic.com/16ie0ib.png
Block 6: http://i49.tinypic.com/23sixrn.png
Block 6.1: http://i49.tinypic.com/34eymib.png


After a long break I decided to revise the division and multiplication

April 30, 2013
After trying to re revise the circuits I found them to be way to complicated and confusing.

The final design was organized, easy to debug, more precise and much faster then previously being able to at up to 2MHz,
limited by Multisim capability to produce such high clocks and still be able to simulate every componet precise without simulation errors.

At the end it was a fully functional 8bit Alu with 4 logic and 4 math functions, it may not be much but it can now be classified as an ALU  ;D
And I was able to reduce the total amount of components to just 626 components (using pre-made components), with the components distribution:

Division - 260
Multiplication - 175
Add/sub - 64
Xor (logic) - 16
Or (logic) - 16
Nand (logic) - 16
And (logic) -  8

Circuit schematics are available at :
http://share.pho.to/2vHQr
26 pictures, showing the whole design in great detail.


May 5, 2013
after watching a video called:
See How the CPU Works In One Lesson


I was starting to wonder just how I could use an ALU to control/execute operations inside a CPU.
I decided to make a circuit that would give me an idea of what I would need to do.
based on this part of the video
http://youtu.be/cNN_tTXABUA?t=17m34s

this is what I came up with, a crud circuit that pointed me in the right direction (I like to believe so)

Even though it's manually controlled It gave me a great insight of just what I would need to do to make by my standards a working CPU.


June 21, 2013
Almost a year after I made my first simple multiplication circuit I was finally seeing a potentially useful circuit.
It was now a 8Bit CPU that was capable of running simple instructions that I made for it.


Even though it's extremely messy, it was a great feeling to see the first program run successfully on an idea that I've been working and tweaking for almost a year.
I've been wondering for years how a CPU would execute instructions and control everything that a computer does, and I'm finally getting close to that answer  :blah:


Last month I made the step from a simple CPU to what I would call a microcontroller.

October 15, 2013
After over a years work (though mostly procrastinations  ::) ) I could finally call this a working MCU that is functional.

and

Those two videos shows in my opinion that the MCU is able to take and out put values from it's IO pints and it's able to execute 14 instructions (13+1 IO instruction)
The final design consist of 1089 components, 3512 pins and 1099 individual nets.
The MCU can be clocked at 2MHz (restricted by the accuracy of multisim)

 :=\
 :wtf: I can't believe anybody would read that much... Thank you for enduring my horrible video editing skills and poor grammar  ^-^





---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline ddavidebor

  • Super Contributor
  • ***
  • Posts: 1190
  • Country: gb
    • Smartbox AT
From Full Adder to a 8bit MCU
« Reply #1 on: November 03, 2013, 07:51:33 pm »
Readed!

Now put it in a fpga!
David - Professional Engineer - Medical Devices and Tablet Computers at Smartbox AT
Side businesses: Altium Industry Expert writer, http://fermium.ltd.uk (Scientific Equiment), http://chinesecleavers.co.uk (Cutlery),
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #2 on: November 03, 2013, 08:55:24 pm »
Very impressive, I am sure it taught you a lot.

How do you write programs? Machine code? Assembler?

 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #3 on: November 03, 2013, 09:53:18 pm »
 Thanks ;D

How do you write programs? Machine code? Assembler?

A mixture of both Assembly and Machine code.
The way I write the code is by first programing a 8051 MCU using Assembly, this is because I don't want to write every single value manually.
the 8051 would be the equivalent of a compiler/burner?

For example to do IF  A > B, I first program a 8051 MCU inside Multisim, and when the simulation runs it will load the values that are on P0 to the RAM using P2 to select the addresses and P1 to toggle Write enable.
When it's done loading the values to the RAM, I've programed it to shut itself down, so the only thing that execute any values stored on the RAM is my circuit.


;JUMP IF A > B
Code: [Select]
mov p0,#06
lcall ramout
mov p0,#00
lcall ramout
mov p0,#22
lcall ramout
mov p0,#70
lcall ramout
mov p0,#80
lcall ramout

Code: [Select]
ramout:
mov p2,A
inc A
mov p1,#07
mov p1,#03
ret
This should be easy to understand if you know Assembly, but it does not explain why I use those values or what they actually do.

The code that will be loaded and executed by my MCU is 06,00,22,70,80 where the decimal values (not hex) are:
06 is the instruction it selects what type of operations we want to do, here it's the number for Jump if A > B.
00 is the address that will be used for this specific operation only if A is greater then B (of course that depends on the instruction number), here it's 0 but it can vary from 0-252
(252 because you can't do anything other then jump back since there is only 255 available address and a jump requires 3 address).
22 is the Operation settings, here it is used to set the 8bit ALU to comparator mode.
70 is the value of B and
80 is the value of A.

The RAMOUT routine is only used to toggle the Write enable pin on the RAM, thus loading what ever is on P0 to the RAM the the address P2 (determined by the value of A).
It should bee easy to see that if I were to run this instruction/program it would always jump back to address 0 (the beginning) because A is always greater then B and
it would only be one line in a high language compiler.

The reason for all those values are due to design implementations and are unique to this circuit.
I'm actually trying to writing a documentation/manual for this MCU, as a tutorial for somebody that asked for my help to understand how he could build a "working" CPU/MCU, I must admit finding any information for making your own CPU is impossible I couldn't find any information other then this one "How the CPU Works In One Lesson " very informative but also very abstract.
The way I did it was by just trying out different designs and making my own "architecture".

So too answer your question, I use Assembly to load my code, but my programs are written in machine code in a decimal form in the 8051 environment to make is easier to the eye.
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #4 on: November 04, 2013, 01:30:16 am »
If I understand it correclty, you are programming in machine code, the 06, 00, 22, ... is your machine code.

Do you use the 8051 trick just to initialize your RAM with the program? If so, I would be very surprised if the simulation program does not support and more direct and easier approach, this is is a very general need.

If you must do it with the 8051 trick, probably you can simplify it by defining with the 8051 assembly a block of literal data and then call one function to copy it.  Most assembler also allow to define constants and macros so you can define them for your CPU's commands, this way you will have a pseudo assembler for your processor.
 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #5 on: November 04, 2013, 03:01:13 am »
Yes you understood correctly, and I've been asking around on this forum and even on the National Instrument forum for Multisim.
I was asking if there was any possible way to simulate some sore of EEPROM, because in Multisim 12.1 Power Pro edition it is no possible to program or store any thing on the EERPOMs that are in the libraries, and if my program uses 254 addresses it can take up too 3-5 minutes to load the programs, making debugging a pain in the ass.

Like you said there should be an easier way to do this.

You can simplify it by defining with the 8051 assembly a block of literal data and then call one function to copy it.

Could you explain to me what that would look like?
Because I don't know how I can do this, I've never learned assembly other then by Googleling the commands that I needed.
What I do is keep a copy of every command in a text file, then I just edit the different values of addresses, A and B variables to mach my current programs need, but you gave me a great idea.

I can't believe that not even the Ni forums couldn't even help/bother to answer me  |O
They have a word generator, you can type up to 32 bits of data (word length) and have it outputted on the pins.

http://i40.tinypic.com/2mffde1.png
(too big to include here)

Although this is not perfect, I'm able to first load the program by selecting "Control:Burst" with "Trigger:Internal", this will (I hope) load the program to the RAM, and when it's done it will pause the simulation, then I can select External trigger and resume the simulation, when resuming the simulation, the word generator will not do anything because it is not triggered.
In a real word scenario this would be optimal as I could reload/edit the data in the RAM by simply toggling the reset button (yes it even have a reset button) .

I'm gonna try out that method and see if it's any better.
One great thing with using the 8051 is that I don't have to worry that much with the addresses, they are incremented by the 8051 after it's done loading the current value to the RAM.
If I want to store a value in another address (other then the next)  I can just use:
Move A,(the new address)
and on the next RAM out call it will load the value to the new A and continue loading the program from that address and up (if that makes any sense).  :-//

Also I think I'm probably gonna use the 17th  and 18th bit as a triggers to logically connect/disconnect the word generator form the circuit, maybe I can skip the whole Pause and Resume process by using the current SR gates circuit that I use to disable the 8051.
I'll have to see if I get any performance drop/improvement, this is important since Multisim can only utilize one core of the CPU  :palm:


---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #6 on: November 04, 2013, 03:42:01 am »
>> Could you explain to me what that would look like?

What Assembler program do you use? I can try to look what commands it has.

(haven't done Assembly for long time. Nor promising anything ;-))


Edit: looking at an arbitrary 8051 assembler from the net:
1. Look at the DB  command, it allows you to put specific bytes in memory. You can define a block of data with your machine code and then copy it to the similator RAM.
http://plit.de/asem-51/pseudo.htm

2. the ORG command allows to to place your data at an arbitrary 8051 address

3. the EQU command allows you to define constants (e.g. your MCU commands).

4. Look at the HERE: example here http://plit.de/asem-51/statemen.htm  it define a constant whose value is the address of the next byte.  You can have one in the beginning of your block and one at the end and use a loop to copy everything between these addresses.

5. Look at macro example here  http://plit.de/asem-51/params.htm  macro or compile time functions. For example you can define a macro (I am guessing what is your MCU's commands and the syntax below is loose):

macro IS_GREATER_THAN_ZERO  memory1
  DB   MY_COMPARE, memory1   // MY_COMPARE is a const (EQU) with the compare opcode of your MCU
endm

A macro assembler can be very powerful and some people swear by it  https://www.grc.com/smgassembly.htm  ;-)
« Last Edit: November 04, 2013, 03:56:18 am by zapta »
 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #7 on: November 04, 2013, 04:03:08 am »
Thanks for even considering it  ;D

I use the Assemble inside of Multisime 12.1 Power pro edition, it appears to be 8051 metalink assembler.
This is a line that is always in a new project "$MOD51   ; This includes 8051 definitions for the Metalink assembler" so yeah I'm gonna guess it's metalink assemler.

8051 cross Assembler User's Manual PDF
http://www.xess.com/static/media/manuals/asm51.pdf
If I'm not mistaking all the commands should be on page 11 (12 in the PDF)
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #8 on: November 04, 2013, 04:10:22 am »
Wow thank http://plit.de/asem-51/params.htm seems to be very useful.  :-+
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8613
Re: From Full Adder to a 8bit MCU
« Reply #9 on: November 04, 2013, 06:40:02 am »
For a moment I thought you'd implemented an 8051... that would be even better!

Quote
The final design consist of 1089 components, 3512 pins and 1099 individual nets.
This is slightly less than the complexity of a 6502, and quite a bit less than that of an 1802 (schematics here).
 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #10 on: November 04, 2013, 07:39:20 am »
This is slightly less than the complexity of a 6502 and quite a bit less than that of an 1802

There is a lot of room for improvement on this design it's probably more complex then it needs to be, like I could remove all the IF instruction and just use the Jump IF (they do the same thing just reversed).
The thing is that in the simulation there is only 1089 components, but at a gate lever there would be a lot more then just 1089 gates.
I don't think multisim would be able to simulate that many gates without doing something weird, version 10 or 11 had problems simulating a "simple" 4bit ALU with adders made at a gate level.
I was only be able to run the simulation once before it crashed.
In Version 12.1 I  can't use CTRL+Z in big simulations or else it gives an error, I have to remember the changes that I made and if the circuit doesn't work I  delete them manually and try again or reload the the whole design. I might be doing something wrong though, there is probably some settings that can be tweaked/adjusted, though most CPU/MCU designs are made in VHDL and multisim is probably not the best program for this task.

Although I agree that making a complete 8051 would be pretty cool, it feels very rewarding to know that I've made it from "scratch" with only a single picture to go on and many possible ideas that were tried and failed to eventually come to this semi useful circuit.   ^-^
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline ddavidebor

  • Super Contributor
  • ***
  • Posts: 1190
  • Country: gb
    • Smartbox AT
From Full Adder to a 8bit MCU
« Reply #11 on: November 04, 2013, 12:37:51 pm »
With 3000$ you can probably build it in 74xx logic
David - Professional Engineer - Medical Devices and Tablet Computers at Smartbox AT
Side businesses: Altium Industry Expert writer, http://fermium.ltd.uk (Scientific Equiment), http://chinesecleavers.co.uk (Cutlery),
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #12 on: November 04, 2013, 11:44:00 pm »
Have you considered using a different simulator? About 5 years ago a used free tools from Xilinx, including a simulator, and they work pretty well. You may be able to find something more predictable and still free.

Edit: it seems to still be free and maybe much better than the old version I used 5 years ago

http://www.xilinx.com/products/design-tools/ise-design-suite/ise-webpack.htm

And here is the simulator manual

http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_1/plugin_ism.pdf
« Last Edit: November 05, 2013, 12:04:07 am by zapta »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #13 on: November 04, 2013, 11:47:15 pm »
Thanks for even considering it  ;D

I use the Assemble inside of Multisime 12.1 Power pro edition, it appears to be 8051 metalink assembler.
This is a line that is always in a new project "$MOD51   ; This includes 8051 definitions for the Metalink assembler" so yeah I'm gonna guess it's metalink assemler.

8051 cross Assembler User's Manual PDF
http://www.xess.com/static/media/manuals/asm51.pdf
If I'm not mistaking all the commands should be on page 11 (12 in the PDF)

I looked at the PDF at xess and it seems to have everything I mentioned in my suggestions, DB, EQU, macros, etc.

 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #14 on: November 05, 2013, 07:35:49 am »
Thank you Zapta  ;D

By using macros, I've made a simple "library" 58 lines long that includes every functions and  it took under 20 minutes to "convert it".

This is a program that checked P0 and compared it to some value (here it's 240) and out puts a value back to P1 (here the value is 40 as declared in the second MOVE command):
Code: [Select]
;MOVE
mov p0,#13  ;IN
lcall ramout
mov p0,#64  ;BANK A
lcall ramout
mov p0,#00  ;VALUE
lcall ramout

;MOVE
mov p0,#13  ;IN
lcall ramout
mov p0,#196 ;BANK B
lcall ramout
mov p0,#40  ;VALUE
lcall ramout

;IO
mov p0,#14  ;IN
lcall ramout
mov p0,#5   ;A
lcall ramout

;IF A>B
mov p0,#06  ;IN
lcall ramout
mov p0,#244 ;Address
lcall ramout
mov p0,#150 ;OP
lcall ramout
mov p0,#240 ;B
lcall ramout
mov p0,#0 ;A (P0)
lcall ramout

;JUMP
mov p0,#03  ;INR
lcall ramout
mov p0,#06  ;ADRESS
lcall ramout
mov p0, #0  ;jump
lcall ramout

mov A,#245  ;if A>B this is where it would jump else it does "no operation" until it reaches address 245
;IO
mov p0,#14   ;IN
lcall ramout
mov p0,#9    ;B
lcall ramout

;JUMP
mov p0,#03  ;INR
lcall ramout
mov p0,#06  ;ADRESS
lcall ramout
mov p0, #0  ;jump
lcall ramout

And this is how it looks now (excluding the Library)

Code: [Select]
MOVE 64, 00
MOVE 196, 40
IO 5
IFAB 06, 244, 150, 240, 00
JUMP 06
mov A,#245
IO 09
JUMP 06

The library contains only one single macro for every IF and JUMP since it can be controlled with the first parameter of IFAB.
This will make it a easier to explain and to debug. I haven't tested it yet in the actual MCU circuit, but in a separate simulation with just the 8051 everything looks to be working correctly and I've also added a piece of code that can reprogram the RAM to undo any changes made in the RAM made by any WRITE command from my MCU, it should be faster then resetting the simulation.
Thumbs up to you  :-+

Also I've been thinking of switching to VHDL simulations, but never really gotten in to it.
When this project is done I'm probably going to look more into it, because I know that I can't continue using multisim if I want to do more complex/bigger circuits.

With 3000$ you can probably build it in 74xx logic
If only I had the space and equipment for that  :'(
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: From Full Adder to a 8bit MCU
« Reply #15 on: November 05, 2013, 07:42:56 am »
With 3000$ you can probably build it in 74xx logic
If only I had the space and equipment for that  :'(

I really think you would enjoy using FPGA's, not a lot of space required for that.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6365
  • Country: 00
Re: From Full Adder to a 8bit MCU
« Reply #16 on: November 06, 2013, 07:56:44 am »
Also I've been thinking of switching to VHDL simulations, but never really gotten in to it.
When this project is done I'm probably going to look more into it, because I know that I can't continue using multisim if I want to do more complex/bigger circuits.

I am curious, what HDL language do you use now with multisim to describe your design?
 

Offline Gatos De La MuerteTopic starter

  • Contributor
  • Posts: 10
  • Country: na
Re: From Full Adder to a 8bit MCU
« Reply #17 on: November 06, 2013, 07:37:08 pm »
what HDL language do you use now with multisim to describe your design?

I don't, multisim has a library of components.
you just place them on the sheet and wire them up by hand.

also FPGAs sounds like the perfect tool for me and they aren't that expensive a much better alternative to microcontrollers ;D
---------------------------------------------------------------------------------------------------------------------------
No matter how clever and complete your research is, there is always someone who knows more.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf