why we need memory in microcontroller?

Thread Starter

vead

Joined Nov 24, 2011
629
The programmer decides what he wants to do with the RAM, it basically is not necessary for a cpu to work, think of it just like any other peripheral.

Have you ever written a program for PC? In any program you will have some variables, and the content of those variables is stored at some address in the RAM. The compiler decides what those addresses are and writes these addresses directly into the code. So when a line of code says i=i+1; the compiler rewrites it to Read data from address 123456, Add 1 to it, Store the result to address 123456.
ok data is stored at some address in the ram but why we are doing this?
 

kubeek

Joined Sep 20, 2005
5,794
Because we NEED to store it SOMEWHERE. Almost any algorithm needs some memory to keep track of what it is doing.

For example: you have 10 numbers stored in ROM along with the program, and you want your program to find the biggest of those 10 numbers.
You then go through all of them one by one, and if you find a bigger number you forget the last biggest one and remember the new bigger number. Since the cpu doesn't have any space where you could store that biggest number you store the biggest number in RAM.
 

kubeek

Joined Sep 20, 2005
5,794
Read-only data is stored in ROM - program memory, and variables are stored in RAM - data memory. Let's keep these words like this for better understanding.

Address of those variables will be stored in program memory - i.e. hardcoded into the instructions of the program. Of course you can also have other adresses of other things that are in RAM stored in RAM, but you generally wouldn't store in RAM adresses of things that are in ROM. Those can be happily hardcoded and don't need to occupy RAM space, as the address of stuff that is in ROM will never change.
 

ScottWang

Joined Aug 23, 2012
7,397
Would that regression actually be far enough?

I could also recommend the 4004 and the 8008 for an alternate trip down memory lane preceding the 8051 by a mere seven years.
If the people want to study the very basic hardware and software, 4004 and 8008 are too complicated, why i suggest the 74LS181, because through it we can see how the instruction code working on a hardware very directly, but 4004 and 8008 couldn't reach that, why is that, because the 4004 and 8008 are the CPU not the ALU.

If anyone already knew the ALU and memory, and then introducing 4004 and 8008 to them are the good chips to know.
 

Papabravo

Joined Feb 24, 2006
21,158
Yes but the 74181 (preceeded the LS181) is only a 4 bit slice and it takes a leap of imagination and abstract thinking to see how it works in the broader context. The 8008 and 4004 have the advantage of not having any onboard memory which is where this whole discussion started. The 7489 is also a register slice 16x4 if I recall correctly and again it takes a leap of imagination to see how it fits into an overall design. The OP has show absolutely no ability to look at a part and form a mental picture of how it operates.

Like at least one other member I think we're being spoofed by a BOT. No matter what we say there is no understanding and a following sequence of repeated questions.
 

takao21203

Joined Apr 28, 2012
3,702
Yes but the 74181 (preceeded the LS181) is only a 4 bit slice and it takes a leap of imagination and abstract thinking to see how it works in the broader context. The 8008 and 4004 have the advantage of not having any onboard memory which is where this whole discussion started. The 7489 is also a register slice 16x4 if I recall correctly and again it takes a leap of imagination to see how it fits into an overall design. The OP has show absolutely no ability to look at a part and form a mental picture of how it operates.

Like at least one other member I think we're being spoofed by a BOT. No matter what we say there is no understanding and a following sequence of repeated questions.
4004 is not so good when you cant distinguish ram rom and itsy bitsy spider.

Let's see what goes on SMS power. Seriously its a good forom for asking tech questions about processor and stuff.
 

ScottWang

Joined Aug 23, 2012
7,397
Yes but the 74181 (preceeded the LS181) is only a 4 bit slice and it takes a leap of imagination and abstract thinking to see how it works in the broader context. The 8008 and 4004 have the advantage of not having any onboard memory which is where this whole discussion started. The 7489 is also a register slice 16x4 if I recall correctly and again it takes a leap of imagination to see how it fits into an overall design. The OP has show absolutely no ability to look at a part and form a mental picture of how it operates.

Like at least one other member I think we're being spoofed by a BOT. No matter what we say there is no understanding and a following sequence of repeated questions.
As the OP asking that he want to know how a software working on a hardware, the 74181 can easily to creat the conception, you just prepare some dip switches, some resistors and some LED, and then a easy and simple demo board is done, the switches inputs as the instruction code of software, and you can see the results from LED.

Do you think that the 4004 or 8008 can do that?

The important thing is how to create the conception of the basic hardware and software working together.
 

takao21203

Joined Apr 28, 2012
3,702
Mixing terms a lot hardware software not clear, ram rom not clear, and: Why do we need memory and he said he created UART with verilog.

Didn't click "thank you" for mentioing bus arbitration (educationally), but wrote replay "thank you very much"

Agreed to try SMS power.

2


I suggest to buy this:

4.5 volt dry battary
Switch
Bell wire
Sccrew driver
Bulb socket
Bulb

Wire it! And wonder why... And ask: Why does the bulb light up?

because you operated the switch.

Yes but why does it light up...big question.
 

Thread Starter

vead

Joined Nov 24, 2011
629
Mixing terms a lot hardware software not clear, ram rom not clear, and: Why do we need memory and he said he created UART with verilog.

Didn't click "thank you" for mentioing bus arbitration (educationally), but wrote replay "thank you very much"

Agreed to try SMS power.

2


I suggest to buy this:

4.5 volt dry battary
Switch
Bell wire
Sccrew driver
Bulb socket
Bulb

Wire it! And wonder why... And ask: Why does the bulb light up?

because you operated the switch.

Yes but why does it light up...big question.
I said thanks for explationations about ram and rom memory
 

takao21203

Joined Apr 28, 2012
3,702
I said thanks for explationations about ram and rom memory
Sure. There is a button "Thanks". that's what most use here.

Also, of course you are free to write explicit thank you declarations.

What kind of computer do you use?

-Laptop
-Desktop
-Tablet
-Tower PC
-Phone
-Netbook
 

spinnaker

Joined Oct 29, 2009
7,830
I need some help I am confuse, can anybody explain with basics why we use memory in microcontroller.
I am trying to understand with following example

can anybody explain with basics why we use memory in microcontroller?
This from the person that wants to design their own CPU? Why do I get the feeling that we are being played here?
 

takao21203

Joined Apr 28, 2012
3,702
When I was 15 I wrote "chained list" functions to display a menu.

For instance, add new topic with a function call.

I was thinking of myself as a big *programmer*

I never wondered: Why there is memory inside the IBM PC?

A controller is nothing but a small computer and therefore, nothing but a small IBM PC.

Somehow, I was taking the fact there is memory for granted- for instance, I had to allocate some from the heap.

As a *programmer*, after a while, you stop wondering about 9 in 10 things, or you stop being a programmer.

Oh yes, today, it's all done with scripts.

Another thing, as a a *programmer*, if you are tempted to wonder about "why something", you have to learn how immediately to consider "why not", or you never become a programmer.

So, concept 1 I introduced to OP was "Abstraction".
And now, concept 2: "Negation".

Really, why not? When we have memory in controller we can sell memory, eh? Even if we don't really need it we can still $ell it.

But, I forget, OP mentioned, he's asking all this for educational reasons. And maybe, for esoteric reasons too. Start wondering why memory is used in controller, really.

OP could ask: Why an engine is used in car. Well, why not? It's quite handy to be able to drive on the road.
 

GopherT

Joined Nov 23, 2012
8,009
Why do micros have memory, because developers found it quite a useful feature when developing a program when on-board memory was available. Because it was useful and offered at a reasonable price, people found it to be a good value and bought more of them. Eventually, nobody considered buying one without.
 

Thread Starter

vead

Joined Nov 24, 2011
629
Well lets say you use the ALU to calculate something, like a sum of numbers. What do you do with the result? Either you keep on doing calculations with it, or you put it somewhere in storage so that you can use the result at a later time. Almost allways you need to calculate multiple different things, and since you don't want to just throw away those results you need some form of memory to store them.
How the ALU , Control Unit , ROM , RAM and I/O device work together ?

Microcontroller take input from sensor and store it somewhere in RAM memory .
Control unit or decoder decode the instruction from memory it direct
thus data and instruction moved from RAM to ALU
ALU perform arithmetic and logic operation
ALU store result of this operation in RAM memory

1)How the ALU , Control Unit , ROM , RAM and I/O device work together ?
2)how data and Instruction get from input device into RAM memory?
3) where we used rom during all process?
 

kubeek

Joined Sep 20, 2005
5,794
Microcontroller take input from sensor and store it somewhere in RAM memory .
it is quite a lot more complicated than that. The case you mentioned is a bit too hard to explain, so lets try a different approach. The data from the sensor are stored somewhere, and you have a special instruction to read and write to a specific sensor, let´s call them IN and OUT. Let´s not go into detail about that right now.

1)How the ALU , Control Unit , ROM , RAM and I/O device work together ?
2)how data and Instruction get from input device into RAM memory?
3) where we used rom during all process?
Control unit controls everything. Alu for example adds two numbers and stores the result somewhere.

Lets focus on the main cycle of a CPU.
Any CPU allways has a register called Program Counter (PC for short), which holds the address of the next instruction to be executed.

First, the controller reads the ROM from that address the PC is pointing to.
Second, it decodes the instruction - deciphers what is to be done.
Third, it executes the instruction - sets the control wires to tell alu what to do and where to store the result.
Fourth, it increments the PC by one instruction so that in the next cycle the next instruction in row will be executed. (unless the last instruction was to jump somewhere else in the code, then PC would be changed to point to that new address)

Now none of these steps need to involve RAM, everything is only between ROM where the instructions are stored and the CPU.
Many processors have only for example 32 8bit registers, to which you can store your variables and results. An addition to that is RAM, which is basically just a lot more registers you can write and read.

Ask if you don´t understand anything.
 

takao21203

Joined Apr 28, 2012
3,702
Turing (Alan Turing) some day built a model of a computer with pieces of toilet paper, and small stones.

OP can look it up on wikipedia.

In principle, a modern computer/controller/CPU work like that.

That said, his personal life was a bit sad, maybe you don't want to know at the end of the day.

In theory, a Turing machine (an arrangement of toilet paper pieces) can emulate all other turing machines, even if that maybe will be very slow.

If OP has not yet learned "Turing machine", frankly, forget about the rest. Just ditch it, and learn the fundamentals first.
 
Top