Microcontroller Basics - A Comprehensive Guide For Beginners
Microcontroller Basics - A Comprehensive Guide For Beginners
Sharing is Caring!
What is a Microcontroller?
Components of Microcontroller
How Microcontroller Works?
Microcontroller Architecture
Microcontroller Peripherals
Difference between Microcontroller and Microprocessor
Microcontroller Applications
What is a Microcontroller
A “Microcontroller Unit” or “MCU” is an Integrated Circuit
(IC) that effectively controls electronic devices within a large
embedded system.
This does not mean that you try to control your Spouse using
a microcontroller. Well, even if you do, don’t hold me
responsible for any repercussions.
Microcontroller Basics
Microcontroller Components
Bus Bus
EEPROM/ DAC
Central Processing Unit (CPU)
FLASH
Arithmetic Logic Internal ADC
RAM Unit (ALU) Clock
Timers
External Crystal
Control Unit (CU) Registers
Oscillator (Clock) I/O Ports
Now is the right time to tell you about the components which
combine to form a full-fledged microcontroller. And more
importantly, how microcontrollers process instructions given
by a human-user?
Memory
Don’t even think about that! Both the instructions and data
are in binary format, so you need a binary storage device.
In technical terms, such a device is called MEMORY.
For three memory address lines, you can target 8 cells (0, 1,
2, 3, 4, 5, 6, 7) or store 8 bytes of data. If you are getting
along, you should be able to see another repetitive pattern.
Can you spot where have you seen such a pattern before?
Types of Memory
Flash Memory
Here we go then!
Instruction: b7 b6 b5 b4 b3 b2 b1 b0
I hope you are getting along! If not, you can throw in your
query in the comments section.
Now it’s your turn! Write the answer to the next question in
the comments:
Well, don’t get worried about that! You don’t need to do that,
as CPU has a dedicated Control Unit for this task.
But, Wait. If the Control unit can only fetch and decode the
instructions, who is going to perform the mathematical
operations? Is it again you who needs to get involved?
To get an answer, unlock the next sub-section. I am waiting
for you there…
Instruction Pipelining
Stack
For both the interrupt handler and the subroutine, the CPU
needs to go from the memory address of an instruction to
the memory address of the subroutine/interrupt handler.
One critical point is that the CPU should push the return
address of the next instruction than the one, which is being
interrupted or calling the sub-routine. This will prevent an
infinite instruction execution loop.
Registers
Stack Pointer
For the pop operation, Top element is retrieved first and then
stack pointer gets decremented
Now you also need to save your Link Register (LR) into the
stack, as LR will get updated with the new return address for
the nested subroutine/interrupt handler.
Once you get out of the nested subroutine, you need to pop
the value from stack into the LR. This will get you to the
starting point, the return address for the first sub-
routine/interrupt.
After having learned about the registers, you are now well-
in-shape to understand this cheeky concept.
Clock
Before moving onto the clock signal, I want you to imagine a
scenario!
I am pretty sure; you wouldn’t want that! So, how you can
prevent this?
If you already know the data for your instruction, you can
feed that into the memory directly and you are good to go.
For example, I/O Ports provide the user input data from
switches and keyboards to the CPU. Moreover, I/O Ports
output the desired information to the user by interfacing with
the LCD or LED display.
Bus
Microcontroller Architecture
Most of the women believe that “All men are the same”. This
thinking, however, does not apply in the context of the
microcontrollers. Microcontrollers differ greatly based on
their architecture, which I am going to discuss further:
External Memory vs Embedded Memory
Now you can see for yourself, it took only three cycles in
Harvard architecture to execute an instruction and fetch
the next instruction. While von Neumann architecture took
five clock cycles for the same task.
Bit Configuration
Let’s say you are a team of 4 friends, and you all have
decided to visit Disney Land during summer vacations. You
have two choices for your ride: a car or an empty bus. Which
one would you pick?
I knew you would go for the bus. After all, you would be able
to sleep in the empty space. However, once you become
aware of the difference between the fare, you will certainly
prefer a car over an empty bus. I have excluded two kinds of
humans in my speculation: firstly BILLIONAIRES, and
secondly those with a fresh salary check!
Timers/Counters:
Communication Interfaces
Have you ever transferred any data from your mobile phone
to a desktop computer? Okay, so which communication
interface did you use?
Interrupt Controllers
Let’s say you want to toggle the output state of Port A after
each second. What will you do?
You have now read almost 7000 words about the basics of
microcontroller, and understand microcontrollers from every
nook and angle. Understanding the difference between
microcontrollers and microprocessors is going to be a
piece of cake for you!
A Microprocessor!
How simple was that! I bet you did not have any problems
understanding that. People, however, make a mess of this
because they don’t comprehend microcontrollers in true
sense.
Again. A Microprocessor!
Microcontroller Applications
By now, you should have a fair idea of the applications which
can be implemented with the help of a microcontroller.
Baby Monitors
Fire Detection
Internet of Things
Home Automation
Light Sensing
LED Control
Low-Cost Wearables
Medical Equipment
Sub-Marines
Ships
Aerospace System
and many more…
This list will never end, even If I continued to write for the
next three days.
Sharing is Caring!