why we need memory in microcontroller?

Thread Starter

vead

Joined Nov 24, 2011
629
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

example- I want to run dc motor with switches

I can do with three types
-analog circuit
-digital circuit
-micro controller

1)analog circuit-motor can run with switchs I can do with some transistor, resistor and other analog component

2)Digital circuit -there are two switches and one motor I can use AND Ic


A B c
0 0 0 when all switch are open motor is stop
0 1 0 when one switch is closed motor is stop
1 0 0 when one switch is closed motor is stop
1 1 1 when all switch is closed motor is run

3)microcontroller- I can also use use microcontroller and I can write code

processor-memory-I/o device

here I am confuse
processor- I know processor is use for all arithmetic and logical operations I used AND IC for motor in digital circuit I understood why we use processor

I/O device -switch is input device and motor is output device

memory - there are two type of memory code memory, data memory
code memory- we write code like c, assembly. Ram is used to store data

can anybody explain with basics why we use memory in microcontroller?
 

takao21203

Joined Apr 28, 2012
3,702
Compressing your post it is kinda "But why?".

Instead of asking questions in a complicate way, learn to apply abstraction. It is called "abstract thinking".

Basically, in order to become a programmer, you need to be good at it.

The problem often is, many design choices must be made and no spec. sheet like you requested in your recent post exists.

Or you should also study "Finite State Machines", there is a paper (PDF) from AMD about it.

Chances are you'd become confused about Mealy/Moore State machines- I used state machines without even knowing about these two types.

2

Now your question.

A processor, controller, uC, chip, you name it, is basically kind of a state machine.

2.1. It has a well defined starting state (for instance registers are reset).

2.2. It has a finite number of possible states

2.3. It progresses through various different states, of which each could be laid out on a big diagram on a wall.

This happens by stepping through a so called "program".
Internal states and external states of signals are queried, and processed often with the help of an ALU.

2.4. Thing is, even the simplest state machine has a memory.

Think just two states- "0", and "1". 1 bit memory!

Without memory, no state machine.

So in order to work with a state machine like a processor, and step through various different states, logically, you need some kind of memory.

2.5. There are more than 2 memories

-The internal state machine memory such as registers and program counter etc.

-The external memory, which in turn could be memory ICs, other processors, a punched tape, a DVD or a SD card or whatever.

2.6. When you turn on a computer, it does some well planned things automatically- the so called startup.

Even a digital wrist watch or calculator or remote control will "startup".

Without a memory- this would be impossible. It could not remember it's current state, and it could not access more program steps from external memory.

The fact microcontroller memory also is on chip is not important here.

Hope that will allow some light to light up in your consciousness- I have understanding for your questions. When I was young, television game console was just a black box, I was not even able to ask questions systematically.

Once you reach a threshold, and become able to apply som degree of abstract thinking, you have "learned how to learn".
 

Papabravo

Joined Feb 24, 2006
21,159
Without memory to store instructions there would be no program. The need for program memory should be self evident.

Data memory is used to store loop indexes and state variables and the need for some amount should be self evident as well.
 

takao21203

Joined Apr 28, 2012
3,702
yes but that's just a statement, that without memory it does not work, no detailed explanation why on earth memory is required for a processor.

Let's ssay, someone in science makes a postulate "processor needs memory"- proove WHY.

Just saying "Without memory it does not work" is not enough. Explain in detail why using memory is explicitely required.
 

Thread Starter

vead

Joined Nov 24, 2011
629
Without memory to store instructions there would be no program. The need for program memory should be self evident.

Data memory is used to store loop indexes and state variables and the need for some amount should be self evident as well.
that's my question why we need programming in Micro controller I know we use memory to write and store program but I don't know why we need I have spend lot of time to find answer but I did not find correct answer please anyone explain with example or tell me what I do to search the answer
 

takao21203

Joined Apr 28, 2012
3,702
Are you an automated software implementation, like for instance Eliza?

Because often with some variation you throw back what was just said to you, shifting away from the original question.

Now you ask "Why we need programming in micro controller".
 

Thread Starter

vead

Joined Nov 24, 2011
629
Compressing your post it is kinda "But why?".

Instead of asking questions in a complicate way, learn to apply abstraction. It is called "abstract thinking".

Basically, in order to become a programmer, you need to be good at it.

The problem often is, many design choices must be made and no spec. sheet like you requested in your recent post exists.

Or you should also study "Finite State Machines", there is a paper (PDF) from AMD about it.

Chances are you'd become confused about Mealy/Moore State machines- I used state machines without even knowing about these two types.

2

Now your question.

A processor, controller, uC, chip, you name it, is basically kind of a state machine.

2.1. It has a well defined starting state (for instance registers are reset).

2.2. It has a finite number of possible states

2.3. It progresses through various different states, of which each could be laid out on a big diagram on a wall.

This happens by stepping through a so called "program".
Internal states and external states of signals are queried, and processed often with the help of an ALU.

2.4. Thing is, even the simplest state machine has a memory.

Think just two states- "0", and "1". 1 bit memory!

Without memory, no state machine.

So in order to work with a state machine like a processor, and step through various different states, logically, you need some kind of memory.

2.5. There are more than 2 memories

-The internal state machine memory such as registers and program counter etc.

-The external memory, which in turn could be memory ICs, other processors, a punched tape, a DVD or a SD card or whatever.

2.6. When you turn on a computer, it does some well planned things automatically- the so called startup.

Even a digital wrist watch or calculator or remote control will "startup".

Without a memory- this would be impossible. It could not remember it's current state, and it could not access more program steps from external memory.

The fact microcontroller memory also is on chip is not important here.

Hope that will allow some light to light up in your consciousness- I have understanding for your questions. When I was young, television game console was just a black box, I was not even able to ask questions systematically.

Once you reach a threshold, and become able to apply som degree of abstract thinking, you have "learned how to learn".
I am asking about hardware side I have processor and the ALU in processor can do arithmetic ,logic operation so why we need memory I know we use memory but I don't know the reason why we use?
 

MrChips

Joined Oct 2, 2009
30,707
Have you ever walked into a grocery store with a list of items to buy in your head and then you forgot what you went to the store to buy?
 

takao21203

Joined Apr 28, 2012
3,702
I am asking about hardware side I have processor and the ALU in processor can do arithmetic ,logic operation so why we need memory I know we use memory but I don't know the reason why we use?
I suggest you read above reply 50 times or as many times until it looks reasonable to you.

If you look the 68000 manual you wont get very far if you question "Why do we need bus arbitration", or "why the designers did it that way, and what is the scheme to design a bus arbitration".

Consider something like the 68000 bus arbitration as something that just exists, and for the time being would be the way things are. And if you want to get along with it, read it as many times as required until it makes some sense.
 

kubeek

Joined Sep 20, 2005
5,794
I am asking about hardware side I have processor and the ALU in processor can do arithmetic ,logic operation so why we need memory I know we use memory but I don't know the reason why we use?
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.
 

sirch2

Joined Jan 21, 2013
1,037
I am asking about hardware side I have processor and the ALU in processor can do arithmetic ,logic operation so why we need memory I know we use memory but I don't know the reason why we use?
Because the processor has a limited set of registers. The example in your first post is too simple, most people wouldn't use an MCU just to switch a motor on and off.

Consider an something like running an air-conditioning unit. We want the unit to heat if it is too cold, cool if it is to hot. We want the user to be able to set the desired temperature and we need some hysteresis to stop the unit tripping on and off too rapidly.

So we need to compare the current temperature with the lower limit, compare the current temperature with the upper limit and decide what to do. So, very simplistically: load current temp and lower limit into the processor and compare, write result to memory. Then load the current temp and upper limit into the processor and compare, write the result to memory. Load the two results into the processor and decide whether to do nothing, cool or heat.

You could not do it without somewhere to store the results of each test. The results are all part of the State Machine that takao21203 was talking about.
 

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.
look at my first post

1)analog circuit-motor can run with switchs I can do with some transistor, resistor and other analog component

2)Digital circuit -there are two switches and one motor I can use AND Ic


A B c
0 0 0 when all switch are open motor is stop
0 1 0 when one switch is closed motor is stop
1 0 0 when one switch is closed motor is stop
1 1 1 when all switch is closed motor is run

I am doing here something stupid

as simple I can give all instruction when motor is on when motor is off in rom I can do it in code memory? I can write all instruction in form of code

and the address
this address will be store on ram memory ( its just example)

0 0 0 when all switch are open motor is stop
0 1 0 when one switch is closed motor is stop
1 0 0 when one switch is closed motor is stop
1 1 1 when all switch is closed motor is run

I think we give instruction in rom and that will be store on ram
 

kubeek

Joined Sep 20, 2005
5,794
I am not really sure what you meant by all that. You generally don't use a microcontroller to do such a primitive task. Yes you could write a code that doesn't need any sort of memory, but that is the one task out of million that is like that. For any practical alogrithm you need to store your intermediate results somewhere.
 

takao21203

Joined Apr 28, 2012
3,702
I'd like to see how it goes on SMS power if you can get some results over there.

There will be 10x to 50x as many members who know a lot about controllers and processors.
 

kubeek

Joined Sep 20, 2005
5,794
The software - instructions stored in ROM, tell the hardware what to do.
What address of data are you talking about? I think there lies the key to your confusion.
 

kubeek

Joined Sep 20, 2005
5,794
Did you mean what is the work of RAM? It is basically a free space where the program can store values if it wants to. It doesn´t do anything by itself.
 

kubeek

Joined Sep 20, 2005
5,794
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.
 
Top