why we need memory in microcontroller?

Discussion in 'General Electronics Chat' started by vead, Mar 10, 2014.

  1. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    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?
     
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    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".
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,175
    1,798
    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.
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    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.
     
  5. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    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
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    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".
     
  7. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    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?
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,368
    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?
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    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.
     
  10. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  11. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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.
     
  12. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    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
     
  13. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    When I post that on http://www.smspower.org/forums/

    I'd say I'd attract a graphical reply.
     
  14. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  15. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    I said in my post its for learning purpose Its just example for my understanding
     
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    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.
     
  17. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    In simple word, I am confuse how the hardware and software work together we write code on software like keil in rom memory ,and the address of data will be store on ram memory but how the hardware and software work together?
     
  18. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  19. vead

    Thread Starter Active Member

    Nov 24, 2011
    621
    8
    ok I understood why rom is used , but what is the work of rom what does it do ?
     
  20. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
Loading...