Let's Make Robots!

Creating a Microcontroller from Scratch

So i want to make a basic first robot and i understand what to do with an already built microcontroller but as a challenge i actually want to build a microcontroller from SCRATCH.

Yes i understand that it's a tough thing to start off with but my plan is to understand how everything works by actually doing it. I'm currently working towards an electrical engineering degree so i know basic terminology or i can look up anything new.

Basically, can anyone provide links/videos/books/comments that i should read to understand how to start building a microcontroller from scratch. I know that once i get going or when i get in the 'zone' i will get the hang of it, but starting is the hard part right now because i have no idea where to start. I have coded before in plenty of languages so programming is definitely not a problem too.

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I guess the FPGA way is the most appropriate.

Have a look at Opencores (opencores.org). They have open source elements for FPGA.

Search for microcontrollers.

 

 

Perhaps an intermediate step would be best. A micro controller consist of a CPU, memory (RAM, ROM, Flash etc.) and an IO interface. When I was in TAFE I built my own using a Z80, 64K RAM, 64K of EPROM and discreet logic IC's. This was and still would be a challenging excersise as there are various timing issues to be resolved and logic circuitry to be designed.

 

Thanks for the replies guys. I think i used 'from scratch' incorrectly. I definitely don't want to recreate each part literally from scratch, i'm not reinventing the wheel here :)

I understand how transistors are made. I took VLSI courses, and i know what everything in the above picture is.

rogue's answer is probably what i'm thinking of doing actually (but I didn't word my question properly): " Have you considered using discrete parts in conjunction with a field programmable gate array?"

The main problem for me right now is that it still hasn't 'clicked' in my brain yet. Can i go out and purchase a kit with pretty much everything that i need, then kinda "rip out" the mcu and introduce an fpga that i manually program myself? Does that make any sense or does anyone have an idea? 

I want to use this for a school project, but i don't want to go and purchase everything already premade and then put it together in a week and that's that. I want to reprogram a central part of the kit somehow but i don't have the knowledge to express myself properly. Any comments?

 

This could be an interesting school project, but also possibly daunting at the same time.

Here's what I mean (and forgive me if I get a bit too much towards the basic). As Krumlink pointed out the microcontrollers are made up of individual "blocks" each of which do certain functions. As OddBot said, you can break the μController into larger blocks such as memory, logic gates, calculations and input/output buffering.

If you were to build the μController from individual transistors, capacitors, resistors, etc. you could easily have hundreds of thousands of parts (or more). [ For example, I have read that the latest processor chips from Intel have over 2 Billion transistors (Yep, billion not million --Talk about Large Scale Integration !). They used other computers to design the newer computer 'brains' because it is a job far beyond one man's ability.]

Now, it is true, that microcontrollers are more simple, but they can still be quite advanced.  As you alluded, reinventing the wheel is not something a person should commit their lives to. <g> Now all that said, I think there is an area that could be a useful part of your project, and I would have to call that "customization" of a μC to fit your own needs. There are several, (perhaps I should say many), different microcontrollers on the market.  They were built with versatility in mind Each one was designed by engineers who decided what they thought would be useful components and programming for the end-user. Ultimately, the finished products contain a lot of features that the individual robot-builder does not need, does not understand or just plain does not wish to use in his/her project. While the microcontroller has a multitude of features, if you are not using them, they are a waste to have them there.

If you put together your own controller, it is you who can decide what parts are important to include and what parts can be skipped because you will not be using them.  You can decide how much memory you want your controller to have, how many bits will be handled/processed at the same time, how much current your output buffer stages will source or sink, and the speed at which everything will occur. You would probably want to use readily available memory chips, but parts of your design like the input/output buffering could be individual transistor circuits to get the versatility of increased output current, for example.  If you decided to have comparator inputs, you could use already available comparator Op-Amp chips for those inputs, or wire those inputs up using transistor comparator circuits at your option.

That is what I mean by customization. You decide what parts or options you would like to see in a microcontroller and build your circuitry to fit that design.

Who knows? If other robot-builders like the way you have combined the features, they might want to purchase clones of your main board for their own projects.

 

What I can’t get my head around is how Createmc is going to program this scratch built microcontroller. How will the ALU be built?
He states that “I have coded before in plenty of languages so programming is definitely not a problem too.”, but that’s not the problem. If your building your own microcontroller then you have to build in the instruction set into the hardware somehow. You don’t even have an assembly level to program against.

I think that OddBot’s suggestion makes more sense and still by using a regular microprocessor there will be tons of issues to figure out. But here at least you have a set of commands enabling you to actually program it.

Quite so.  I built my own computer from scratch back around 1978-1980; etched the boards, etc. (Was not a pretty sight - ha ha) but it worked. I built in a "tiny basic" interpreter as well as an "editor" program (very basic word processor).  I actually built it to help me with my writing, since I did not like having to retype things much and using an old typewriter to generate manuscripts, when I made changes, it meant I had to retype a lot. The main thrust of that first computer was having a keyboard and a printer, plus a way to save the stories. (I did that but writing my own routines to send or receive signals from cassette tape at 1550 baud -an arbitrary number. It just worked out that way with the hardware I was using.)

Anyway, as you say, the biggest problem was getting all the right logic levels at the right spots and making the thing actually accept commands. It took me maybe 6 months to get it worked out. I used a lot of 7400 series logic gates, with 8-bit latches and 2102 static ram memory chips.  Once the hardware was working, I set up the programming in octal. Was originally going to use hex, but the keypad I had available didn't have enough keys, so octal it was. (Just a matter of bringing in each entry and storing it in a register until it had all 8 bits it needed for a "word").  I also displayed it on 7-segment LEDs so I could read back what I had entered or make changes if necessary. I also bought four 2716 EEPROM chips to store my programming; (those were $50 each at that time, and I was trying to raise a family). By the time I had it working, it had cost me quite a bit in both time and money.

But it worked and I used it quite a while, thus giving me the satisfaction of being able to say I built my own computer from scratch, not from someone else's boards.

So, bottom line: It is possible, but is a lot of work.

You say that you scratch built your computer, but that was built around an existing microprocessor, -right?
If not, where did you get your basic interpreter and editor program from and how did that work?
Another thing I don’t understand is why you had a basic interpreter when you did your programming in octal on a numeric pad?

I wrote the basic interpreter and editor programs myself. Existing microprocessors were quite expensive and I could not afford to buy one, so I built one from 8-bit latches (ie registers), "and", "or", "nand", "nor", "eor", hex inverters gates, etc., so I had a good sized circuit board that could have been all in one chip, but wasn't. The most expensive things I bought was the 2716 eeproms. (Memory was on a different boards.) Now they are so cheap, I threw out several dozen of them about a year or so ago, but at the time they were $50 each.

From my prior work I was well acquainted with discrete-component processors. I learned electronics, including transistor theory at a time before microprocessors were first invented.  In fact when I first saw articles in EDN magazine about the new processor-on-a-chip (4004s and later 8008s) I was totally amazed that they could take a processor board and turn it into a processor chip. Then from 1978-1979 I worked in a shop making circuit boards. At work, I made one that was later used in the space shuttles, and another I did at work was the guidance board for a cruise missile. -But my home efforts were a bit more modest... as I said earlier, not professional quality, but they worked. - ha ha

As to basic versus octal...   The initial programming was done at a machine level, which I entered as octal code. The reason for the tiny basic interpreter was so I would have a higher level language to work with and not forever be entering everything as octal... (a pain in the rear but a necessary evil). Once the Basic was working, I could enter programs from the keyboard and ignore the octal keypad with a few exceptions as follows:

Because my computer was slightly different from those on the market, When I tried different programs, like from magazines, etc., I did still have to enter some parts as octal code, but mostly I could emulate the basic they were using. I wrote the programming with that in mind.

I think you should learn the basics of fpga programming and take it one step at a time... eventually you can implement basic uarts, display drivers, digital signal processing, etc! Awesome stuff

Thanks for the comments everyone. Rogue's comments put me on the right track and now i know what i'm doing. No 'from scratch' headaches for now :) Instead i'll do what Rogue suggested and go from there.