Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

why we use memory in controller?

Status
Not open for further replies.

Parth86

Member
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

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?
 
why we use memory in microcontroller?
What type of memory?
You answered you question about ROM. ---code
You also answered you question on RAM ---data
>also variables
>>read motor speed and store in memory.
>>convert to RPM and store in memory.
>>compare to old motor speed to see if it is increasing or decreasing. store delta in memory
>>read motor temperature store in memory.
>> is motor running forward or backward (stored in memory)
>>TIMER how long has motor has motor been running? (in memory)
>>etc.
 
sorry but you did not understand what I am asking In old day we used simple analog circuit If we want to run motor then we use some transistor and make analog circuit. after that we used Ic, we use Ic and ,not, nor, .... then we developed new hardware called micro controller but here I am confuse I Know why we use processor , I/o device but I don't know basic concept about memory mainly there are two type of memory firs is rom that is used to write code and second is ram that is used to save the address but can anyone tell me the reason why we used memory in controller sorry for my bad english ......!
 
Last edited by a moderator:
There's some memory needed to store the program.

Then, if your program needs to remember something, it needs memory. Say, it needs to remember which direction you want the motor to spin.
 
mainly there are two type of memory firs is rom that is used to write code and second is ram that is used to save the address but can anyone tell me the reason why we used memory in controller
I do not understand.
You said "ram that is used to save the address" I think you are talking about "stack" which is where address and data is stored. This is a special part of RAM.
 
I do not understand.
You said "ram that is used to save the address" I think you are talking about "stack" which is where address and data is stored. This is a special part of RAM.
ok I explain I want to run motor with two switches ok I can do with Ic so I used And gate ICs.
table for I/O
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 can done in another way using micro controller
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

we will write instruction in rom like when motor is on, off what is input /what is output or you can say code now the address will be store in ram I just want idea why we add memory in conreoller why we need .I am just asking for my understanding can you explain in my example what will be the address
 
another example I have typed some code on ram its total software section how the hardware (ram) identify that what is address for data simple I am confuse how hardware work with software
 
Could you rephrase that? Maybe youse a bit of puctuation and divide it into sentences, I have really no idea what it is that you're asking.
The more effort you spend on asking a question the better answers will you get.
 
Last edited:
vead,

If I understand your question:

This is a simple description of the basic operations of a microprocessor:

Memory (either RAM or ROM) is considered "storage". As you have pointed out, you
...write some code on ram...
, that is, you have "stored" (in ROM) some instructions for the proessor to perform. These instructions not only contain the rules for the processor to follow in performing the task you have assigned, but ALSO what name has been assigned to the DATA that is being collected (and stored in RAM).

The hardware (the actual microprocessor device) knows what "addresses" are assigned to the "storage" spaces within the RAM and the ROM.

When your code (in ROM, and the processor knows its address) calls for (in this case) the voltage reading from a particular ADC, the hardware knows what address in RAM to use to find that data.

Now, if what you want to know is how the processor performs these tasks, you're going to need to do some serious research. Processors have built-in instruction sets for every function they can perform. The actual mechanics of how these instruction sets work is an extemely complex routine that I suspect is beyond the scope of the knowledge you need to make a processor work.

It's sort of like a watch: while it's entertaining to know HOW they keep the time, that knowledge is not necessary for being able use it to read the time.
 
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?
 
Last edited by a moderator:
ALU reads commands from program bus, fetches data from the data bus using address bus and writes the results of its operation to the data bus using the address bus.

ROM (or RAM) supplies information to the program bus so that ALU could get its commands.

RAM uses data bus for communications if the address requested by ALU matches any real memory address

I/O uses data bus when the address requested by ALU matches any of I/O addresses. Or I/O may have its own bus.
 
ALU reads commands from program bus, fetches data from the data bus using address bus and writes the results of its operation to the data bus using the address bus.

ROM (or RAM) supplies information to the program bus so that ALU could get its commands.

RAM uses data bus for communications if the address requested by ALU matches any real memory address

I/O uses data bus when the address requested by ALU matches any of I/O addresses. Or I/O may have its own bus.
ok I want to understand with little example
I have controller one switch , one LED
when switch is off LED is off
when switch is on LED is on

controller take input from switch and store it into RAM memory ,
decoder is used to decode the instruction,
that mean control unit tell the ALU do this, when switch is off LED is off when switch is on LED is on And ALU perform this operation when switch is off LED is off when switch is on LED is on
operation of result store into RAM
output device take the information from RAM
IS this correct?
I know we use rom to write code but what actually use related to hardware?
 
Hey, if you did not have RAM, nested subroutine calls would not work. Usually two things have to placed on the stack. The Processor Status Word (Condition codes, etc) and the return address. You would not have a stack either.
 
Last edited:
switch bit is at address [1], LED bit is at address [2] - these are I/O addresses.

We also use RAM at addrsss [3]. It'll store state of the switch and LED respectively.

Every time switch goes from high to low we toggle LED.

The program might look like this:

0: mov [1],[3]
1: cmp [3],[1]
2: jmpe 1
3: mov [1],[3]
4: test [3]
5: jmpne 1
6: not [2],[2]
7: jmp 1

For this we'll use 4-bit program address bus, 8-bit command size, 2-bit data address bus and 1-bit data bus.

ALU maintains command pointer - 4 bit and has an internal flag, which could be set to 0 or 1.

We can have command format as follow - 4-bit - opcode; 2-bit - first operand; 2-bit second operand.

Say, mov will have code 1, so the first line becomes:

o: mov[1],[3] - 0001 0111 - this moves something from data address [1] to data address [3] - we remember switch state

At the beginnig command pointer is set to 0000, so ALU fetches the 0001 (mov) command from this address and parses it.
It then issueas a read request on data bus for address [1] - first argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Then ALU posts the state it have just read back to data bus and issues write request for address [3] - second argument.
RAM module recognizes [3] as its address and stores the data from the data bus.
ALU increments its program pointer, so it now 0001.

As a result, the switch state is stored in RAM at address [3]

1: cmp [3],[1] - 0011 1101 - I used ooo2 as a code for compare (cmp command).

ALU fetches the 0011 (cmp) command from the 0001 (current pointer).
It then issueas a read request on data bus for address [3] - first argument.
RAM module recognizes [3] as its address and posts data from this address to the data bus.
ALU reads data from the data bus and stores it in its register
ALU issueas a read request on data bus for address [1] - second argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Now ALU performs the compare operation. It compares the data from the bus with the value stored in the internal register (earlier this command). If they're equal, it sets internal register to 0, if different - to 1. It noe can be analized by the next command.
ALU increments its program pointer to 2.
2: jmpe 1 - 0011 0001 - Another opcode I made up - 0011 - Jump if equal. If internal register is 0 then load the last 4 bits of the code into command pointer

ALU fetches the 0011 (jmpe) command from the 0002 (current pointer).
If it is 0 in the internal register (meaning [1] was equal to [3]), it loads 0001 into the program pointer so the program loops back.
The program will continue to loop back until a difference between [1] and [3] will force internal register to 1 during the execution of previous command.

3: mov [1],[3] - 0001 0111 - same the command at address 0

And it does the same. Switch state changed, it it saves it into RAM

4: test [3] - 0100 1100 - Another opcode - 01oo - comapres first argument to the last bit of command (0 here)

Similar to cmp command, but the second argument is not fetched from the bus but is stored inside the command. This is called immediate addressing

5: jmpne 1 - 0101 0001 - Opcode 0101 - does the same as ooo3, but jumps when internal register is 1

This command will jump back to 1 if the value tested by the test command is not zero. This means that the switch is now high. We don't do anything and continue looping.
And if it is low then we want to switch LED, so we go to the next command

6: not [2],[2] - 0110 1010 - NOT opcode - 0110 - toggles. Note it both read and writes from the same address.

ALU fetches the 0110 (not) command from this address and parses it.
It then issueas a read request on data bus for address [2] - first argument.
The LED I/O module recognizes the address and posts the LED state to data bus
ALU reads the LED state from data bus, and inverts it.
Then ALU posts the new state to data bus and issues write request for address [2] - second argument.
LED I/O module recognizes [2] as its address and accepts the state from the data bus.
ALU increments its program pointer, so it now 7.
As a result, the LED is toggled.

7: jmp 1 - 0111 0001 - Unconditional jump to the address from the last 4 bits of the command.

We continue looping. monitoring switch changes and switching the LED accordingly.

Hope I didn't make too many typos in such a long text.
 
Before I2C came around, most peripherals were memory locations. So, your switch would have been a bit in memory and your led would have been a bit in memory.

Nowadays, it can be a port on a CPU which can have multiple functions (simple case: input or output)

Nowadays, reading and writing of bits might be done on the I2C bus.

So. maybe with your example you don't need RAM. RAM used to be called scratchpad memory when RAM was expensive and there was little of it in a small controller.
 
vead I have a couple of books from way back... "Art of Electronics" and more down your street "Art of Electronics Student Manual"

Available everywhere.... In the student book, they make a computer using logic chips.. Then they program it at the end.... On amazon you can preview the book...
 
switch bit is at address [1], LED bit is at address [2] - these are I/O addresses.

We also use RAM at addrsss [3]. It'll store state of the switch and LED respectively.

Every time switch goes from high to low we toggle LED.

The program might look like this:

0: mov [1],[3]
1: cmp [3],[1]
2: jmpe 1
3: mov [1],[3]
4: test [3]
5: jmpne 1
6: not [2],[2]
7: jmp 1

For this we'll use 4-bit program address bus, 8-bit command size, 2-bit data address bus and 1-bit data bus.

ALU maintains command pointer - 4 bit and has an internal flag, which could be set to 0 or 1.

We can have command format as follow - 4-bit - opcode; 2-bit - first operand; 2-bit second operand.

Say, mov will have code 1, so the first line becomes:

o: mov[1],[3] - 0001 0111 - this moves something from data address [1] to data address [3] - we remember switch state

At the beginnig command pointer is set to 0000, so ALU fetches the 0001 (mov) command from this address and parses it.
It then issueas a read request on data bus for address [1] - first argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Then ALU posts the state it have just read back to data bus and issues write request for address [3] - second argument.
RAM module recognizes [3] as its address and stores the data from the data bus.
ALU increments its program pointer, so it now 0001.

As a result, the switch state is stored in RAM at address [3]

1: cmp [3],[1] - 0011 1101 - I used ooo2 as a code for compare (cmp command).

ALU fetches the 0011 (cmp) command from the 0001 (current pointer).
It then issueas a read request on data bus for address [3] - first argument.
RAM module recognizes [3] as its address and posts data from this address to the data bus.
ALU reads data from the data bus and stores it in its register
ALU issueas a read request on data bus for address [1] - second argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Now ALU performs the compare operation. It compares the data from the bus with the value stored in the internal register (earlier this command). If they're equal, it sets internal register to 0, if different - to 1. It noe can be analized by the next command.
ALU increments its program pointer to 2.
2: jmpe 1 - 0011 0001 - Another opcode I made up - 0011 - Jump if equal. If internal register is 0 then load the last 4 bits of the code into command pointer

ALU fetches the 0011 (jmpe) command from the 0002 (current pointer).
If it is 0 in the internal register (meaning [1] was equal to [3]), it loads 0001 into the program pointer so the program loops back.
The program will continue to loop back until a difference between [1] and [3] will force internal register to 1 during the execution of previous command.

3: mov [1],[3] - 0001 0111 - same the command at address 0

And it does the same. Switch state changed, it it saves it into RAM

4: test [3] - 0100 1100 - Another opcode - 01oo - comapres first argument to the last bit of command (0 here)

Similar to cmp command, but the second argument is not fetched from the bus but is stored inside the command. This is called immediate addressing

5: jmpne 1 - 0101 0001 - Opcode 0101 - does the same as ooo3, but jumps when internal register is 1

This command will jump back to 1 if the value tested by the test command is not zero. This means that the switch is now high. We don't do anything and continue looping.
And if it is low then we want to switch LED, so we go to the next command

6: not [2],[2] - 0110 1010 - NOT opcode - 0110 - toggles. Note it both read and writes from the same address.

ALU fetches the 0110 (not) command from this address and parses it.
It then issueas a read request on data bus for address [2] - first argument.
The LED I/O module recognizes the address and posts the LED state to data bus
ALU reads the LED state from data bus, and inverts it.
Then ALU posts the new state to data bus and issues write request for address [2] - second argument.
LED I/O module recognizes [2] as its address and accepts the state from the data bus.
ALU increments its program pointer, so it now 7.
As a result, the LED is toggled.

7: jmp 1 - 0111 0001 - Unconditional jump to the address from the last 4 bits of the command.

We continue looping. monitoring switch changes and switching the LED accordingly.

Hope I didn't make too many typos in such a long text.
Its very detail Information and help me lot but I am little confused
controller take input from switch and store address in RAM memory
1) what will happen first processor will take information ROM or RAM memory ?
 
Its very detail Information and help me lot but I am little confused
controller take input from switch and store address in RAM memory
1) what will happen first processor will take information ROM or RAM memory ?

As I described. Take command code from ROM, decode it, then act according to what is decoded: take info from the switch (which is I/O port, not memory), store info in the RAM.
 
As I described. Take command code from ROM, decode it, then act according to what is decoded: take info from the switch (which is I/O port, not memory), store info in the RAM.
lets think I have micro controller 89c51 ,LED,switch,compiler(keil),programmer (flesh magic)
SWITCH is input device connected port pin P0.1
LED is output device connected port pin P1.1

I have written assembly code in keil software
Code:
ORG  OH
ON:
SETB P1.1   ; LED IS ON
OFF:
CLRB P1.1    ; LED IS OFF
LOOP:
JB P0.1         ; SWITCH ON
JNB P0.1        ; SWITCH OFF
SJMP LOOP
END
1)how the processor understand command setb P1.1 from rom memory ?
2)how the processor understand the address of data bit for RAM memory

LED on:lets say the P1.1 is data bit that means 0100 0000 and its address something like 0010 0000 stored into ram memory
LED off: lets say P1.1 is data bit that mean 0000 0000 and its address something like 0001 0000 stored into ram memory

3)how the processor fetch and execute the command SETB P1.1, CLR p1.1 ?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top