Everyday Electronics Part #4: Microcontrollers

in #stemng7 years ago

Welcome to this exciting series of everyday electronics and I am happy to let you guys know that this is now a collaborative work between I and one of our own @thestronics, he contributed immensely to the success of today's version of everyday electronics and will be the main author of part #5 of this series. Please do check out his wonderful blog about electronics.

10998435603_6ebfaf3a28_o.jpg
[credit: flickr]

Ehen, back to the topic, microcontrollers. If you're an enthusiast in the field of electronics and you have not come in contact with a microcontroller, then it is either you've not carried out a good DIY project or you're watching the discipline from a distance, either way, I bring to you guys, microcontrollers. Microcontrollers are big part of electronics and a friend of anyone that wants to try out a new circuit, design a project, implement project or just have fun.

If you don't want to build a working electronic circuit from the first principle, then this guy is your best bet as it simplifies electronic processes to the point that anyone could work with it and realize very cool stuffs. It is a core component of IoT circuits and are fully programmable using either high level programing languages like the python, C++ or low level programing language like the micro C.

History of Microcontrollers


For a better appreciation of this subject and to differentiate it from other electronic components and devices, I would love to take us down the memory lane of its development. The first move in the history of development of computer was the abacus and it could perform basic arithmetic, then came vacuum tubes which was the major component of the first generation computers. Vacuum tubes were quickly replaced by transistors which paved way for the second generation computers. Then the integrated circuits which powered the third generation computers. The integrated circuits gave rise to the microprocessors which are the main component of every computer and performs all the "thinking" for the computer.


The demand for devices that control certain processes reduced with time and demand for computer was exponentially increasing. We needed computer to perform most of our duties in the home, offices and even industrial processes. The development of computer was followed up with miniaturization and with it, most heavy controllers were integrated into chips. This process was more like developing a computers in layers of semiconductor materials like germanium and silicon. These chips that were designed and built with specific purpose in mind were termed Microcontrollers. Now, question like, what is then the difference between a microprocessor and microcontroller would arise, hence the next section.

How microcontrollers differs from microprocessors

If I am to be quick with this section, I would say that a microcontroller is a computer while a microprocessor is not a computer. A microcontroller is a complete computer with an integrated circuit working like a microprocessor, inbuilt random access memory (RAM), fully functional input and output system, a clocking element, read only memory (ROM), fast processor memory like the register, and many other components that makes up a computer.

A microprocessor is not a computer but when the components listed above like the RAM, ROM, etc. are provided for it, the setup can then be called a computer. From the history section above, microcontrollers evolved from the need for a computer that can perform specific tasks and that is exactly what microcontrollers do. When a microprocessor is built into a computer, it becomes a general purpose computer while the microcontroller is an application specific computer.

Working principle


The microcontroller relies on semiconductor components that are designed into a sequential and combinational logic. When a functional microcontroller receives power and comes up, it is preconfigured to first make trips to some memory location(s) and execute instructions stored therein. Once it finds an instruction in the memory, it goes ahead to execute these instructions and perform necessary calculations as required by the instructions and if need be, store the results of such executions.


[designed by me using MS paint ]

Some of these memory locations were designed not only for storage purposes but also to control the I/O mechanisms of the device. Such memory location are usually very small in capacity and are termed peripheral registers due to their function of reading and writing to the control register peripheral circuitry.

The CPU is not designed to carry out calculations on the main memory itself (the RAM) but can do so with registers and the arithmetic logic unit. The microcontroller maintains many different registers like the program counters, general purpose registers, peripheral registers, etc.

The peripheral registers are of utmost importance as it not only store data but is actively controlling the microcontroller peripherals like the serial peripheral interfaces, general purpose input and output pins, etc. Hence, by sending read/write signals to this register, the CPU can interact with its environment.

On a simpler term, a computer accepts inputs, process and or store these inputs and finally return the result as an output. The same goes for the microcontroller. A microcontroller takes input either as a specific command from a user or as an output of a sensor. Microcontrollers are mostly used for automation projects and to carry out most automation projects, sensors are used as inputs to the microcontrollers.

Memory


One of the major factors limiting the functionality of microcontrollers is its memory. I used two Arduino (more on that later) microcontrollers for my first-degree project and I must say I did not totally realize my objectives and the project requirements limited me to only a maximum of two microcontrollers. The various types of memories available in the microcontrollers are used as containers for programs and instructions. A typical memory found in all microcontroller is the Read Only Memory. This type of memory can only be read by applications and programs but its content can never be changed. Many types of microcontroller come with only the ROM and are always low in price, examples of such microcontrollers are the type found in microwave ovens, the PIC16CR65, microcontrollers found in calculators. Their purpose has been defined at the manufacturing time and no room for further changes are provided.


[common memories found in microcontrollers. credit: wikimedia]

Early microcontrollers came with what is called EPROM (erasable programmable read only memory). This type of memory are erasable but requires rigorous steps which involves exposing the microcontroller to UV light. The UV light enters the ROM through a quartz window and depending on the intensity of the ultraviolet light, the time required to erase the memory might vary between 300 seconds to 1800 seconds and when the process successfully completes, the ROM can be programed again. Microcontrollers with this type of memory are obsolete and very costly because of the cost of the light sensitive window.

Another type of memory found in microcontrollers is the EEPROM (electrically erasable programmable read only memory). This type is very common in modern microcontrollers and as the name implies, it can be erased electrically. Some of our modern calculators come with an opening at the back of the device, this opening is usually labelled “reset” and when the calculator performs abnormally or hangs on an operation, we can restore the calculator back to normal by pressing and holding the reset open using a tiny broomstick. By pressing and holding many reset buttons, we either stop the flow of electric current to the memory or we activated a sequence that will allow the flow of current to the memory which will perform a resetting action. For microcontrollers with EEPROM, they can be programed and reprogramed as many times as possible.

Pins


Microcontrollers just like computers, have input and output system. The input and out to the microcontrollers are provided as set of pins usually projecting from the edges of its packaging. Microcontroller pins usually ranges from 6 pins to 70 pins with each pin capable of performing more than a function. There are four basic pins available in most microcontrollers, these are:
  • Digital/Analog input/output pins
  • Power supply pins and
  • PWM pins
  • Interrupts
  • Digital/Analog input/output pins

    Digital pins accept or interpret voltage values as either on or off that is to say that they only detect the presence or absence of voltage. The availability of analog pins means that the microcontroller spots an analog to digital converter and the analog pins are connected to these converters. These pins require a reference point (always labelled "Ref") and acts to inform the microcontroller the default high voltage of the analog to digital converter.

    Power supply pins

    Every computer requires power to operate and so do microcontrollers. Power pins include the Vcc (positive voltage supply) pins and the GND (negative voltage supply) pins. Some microcontrollers like the Atmel microcontrollers comes in modules and these modules includes functionality like voltage regulators and many other enhancements.

    PWM pins

    Do you desire to build sound systems or lighting systems that comes on gradually till it reaches maximum and goes off gradually till it reaches minimum value? Then connection to these pins holds the success to such projects. Digital signals are either on or off, nothing more, and nothing less.

    PWM stands for pulse width modulations and digital signals appears in form of pulses with widths denoting the period of occurrence of each pulse. Pulse width modulation helps us produce analog signals through digital means.

    In most microcontroller system, a full "on" condition equals to 5 volts and this corresponds to the analog value of 255 while a completely "off" condition equals 0 volts and corresponds to the analog value of0. Digital voltage signals shuttles only between these two values but by changing the amount of time the signal stays in the "on" state or in the "off" state, we can arrive at any value between 0 and 5 volts and this is called pulse width modulation.

    Interrupt Pins

    Some of us are good leaving our duties half way to catch up with our favorite show in the television or football match highlight and after this, we never pick up from where we left off. This is not so for computers unless it was told to do so. Microcontrollers are used mainly for automation projects and must be good in handling interrupts. Interrupts are disruption in the normal sequence of program execution, initiated by another program that needs attention. Processes that can trigger interrupt routine includes timer overflow, arithmetic operation that resulted in infinite result, battery power system, etc.


    [a hardware interrupt path showing interrupt service routing (ISR) and interrupt request (IRQ) movement from hardware to CPU for a PIC microcontroller. credit: wikimedia]

    Most microcontrollers connected some of its general purpose input and output pins to the interrupt circuits. Whenever these pins changes state (changes in their voltage level), a pause signal is generated which interrupts every currently executing program and this allow us to make decisions at this point, decision like powering off the whole system due to low batter, switching on of cooling systems when certain temperature range has been exceeded, etc.

    Classifications and Types


    Classifications of microcontrollers is a bit complex and diverse but I will try and simplify these classifications as much as I can. Microcontrollers are classified according to;
  • Instruction Set
  • Architecture
  • Bus width
  • Programming language
  • Memory etc.

  • [original image by wikimedia]

    Based on instruction sets, microcontrollers are classified considering their hardware instructions which are commands which their hardware understands. These commands can then be invoked and manipulated using software. These commands include but not limited to LOAD, ADD, SHIFT, SUBTRACT, and many more. These instructions sets are of two types which are:

    CISC: CISC stands for complex instruction set computing and implies the use of micro codes to control the processor. These micro codes are stored in the read only memory and are answerable to the software system. Modern computers use this type of instruction set and lives up to its name; complex. CISC instruction sets are very complex and costly to implement because of its heavy memory operation requirements though they are dynamic and fast (not faster than RISC).

    RISC: RISC stands for reduced instruction set computing and came up as a substitute for simpler instruction set. As microcontrollers develops, more functionalities were added to its processor each requiring more micro code which increases the complexity of the instruction set prompting processor designers to venture into designing instruction sets with reduced data cycles and this resulted to instruction sets with even shorter execution time. Many argues about which instruction set is better, but at the moment, there is no clear line between which instruction set is better.

    Classification based on the conceptual design and the structural functioning of the microcontroller is said to be based on the architecture of the microcontroller. Based on this, we have Von Neumann architecture and Harvard architecture. This classification specifies how different microcontrollers stores and access data. Von Neumann architecture was initially designed and requires that data be either read or written to memory one step at a time because of availability of a one physical memory and one bus connecting it to the processor.

    Harvard architecture was later introduced to solve the bottleneck issues encountered in the Von Neumann architecture. This was achieved by providing separate memories with buses connecting these memories to the processor allowing for both read and write operation to occur at the same time if required.

    No doubt, this is the mostly used architecture in today's microcontrollers though we might still find microcontrollers using this architecture today since microcontrollers are created with a purpose in mind, and cost is always considered before development.

    Types of Microcontroller


    Just like there various classifications of microcontrollers, there are also many types of microcontrollers. Almost all microprocessor manufacturers have their own microcontroller, Intel, Atmel (AVR), Motorola, Cisco, Hitachi, and so much more. I will only discuss the most commonly used type for basic electronic projects, these are the PIC by Microchip Technology and the Atmel.

    PIC

    PIC microcontroller was developed in late 1993 by the GIM (general instruments microcontrollers). PIC microcontrollers can be programmed and reprogrammed at will by the user which means its memory is of the type EEPROM (described above) and be made to perform wide variety of tasks. PIC microcontrollers are designed with the reduced instruction set computing instruction set alongside the Harvard architecture.

    The PIC has very limited data memory with about 400bytes of random access memory and 256 bytes of electrically erasable memory. Most PIC microcontrollers also spots three circuit timers which provides clocking for all of its operations. The first and the last timers are always 8-bit timers while the second timer is a 16-bit timer used also as a counter. PIC microcontrollers have PWM capabilities and awesome interrupt system.

    Electronic circuits featuring PIC microcontrollers can be designed using Proteus system tool. With the help of a programmer module, its EEPROM can be programmed using an integrated development environment tool called Micro C pc software.

    AVR

    Have you used Arduino microcontroller before? If so, then you have used an AVR family of microcontroller. AVR family of microcontrollers started rolling out around middle of 1996 and was the first microcontroller to introduce a flash memory as a program memory instead of the legacy erasable memory which uses ultraviolet light.

    AVR microcontrollers comes in different flavors starting from the little TinyAVR which has about 16 kilobyte of programmable memory and an average of 20 pins, the MegaAVR usually called "ATmega" which has programmable memory of about 256 kilobyte and an average of 80 pins, Xmega also called ATxmega which has about 385 kilobytes of programmable memory and up 100 pins on chip, etc.

    The Proteus can also be used to develop circuits based on this type of microcontrollers. One of the major vendor of the AVR microcontroller is the Arduino and markets this product in modules which provides easier form of communication and easier development.

    Applications and Summary


    Microcontrollers have gained popularity since the first microcontroller, the TMS 1000, was built in the year 1971 by team of engineers led by Michael Cochran. It is not applied as a standalone device but mostly as an embedded device. Microcontrollers are found all around us, in most car electronics, home appliances like the microwave, television, door security, in our phones, automation projects, the list is endless.

    Microcontrollers can be regarded as a Computer on Chip (CoC) though this sound too encompassing as some CoC might contain more than on microcontroller. The Arduino modules found in most electronic projects and PIC are some of the commonly used microcontrollers for personal projects.


    Reference


    1. Microcontroller -wikipedia
    2. how microcontrollers works -howstuffworks
    3. Microcontroller memory -microcontrollerslab
    4. Atmel AVR -wikipedia
    5. Microcontroller application and how it works -apogeeweb


    If you write STEM (Science, Technology, Engineering, and Mathematics) related posts, consider joining #steemSTEM on steemit chat or discord here. If you are from Nigeria, you may want to include the #stemng tag in your post. You can visit this blog by @stemng for more details. You can also check this blog post by @steemstem here and this guidelines here for help on how to be a member of @steemstem.

    DQmeqXkd5iiKxkeTXDhAX3MW7V8bL59TF28pTtf57toNvDz.gif

    DQmRhDtjokAZnGKi4QwheqksKTFo6m4fsjMYsNNrsitC1xk.gif

    Sort:  

    @chidiebere the techy guru

    boss you flatter me, lol

    Microcontrollers are fun to work with. I used to buy microcontrollers and try out USB interfacing etc. That was a PIC18F series I guess. Then AVR came. AVR was great. Atmega8,16,32,ATTiny... Now I own a Arduino Uno. You reminded me my engineering days :) where we used to design line following robot and maze solver etc. :)

    Wow that was advanced. I used it for my project as I stated in the post but it was mainly Internet of things. Thanks for stopping by

    I have a friend that uses Sprint layout software, which is similar to the Proteus you mentioned here, to design a printed circuit board. I wrote about it here.

    Read that your awesome post about PCB design then. For ms, proteus performs the magic for me though I take a different path when making PCB for my projects though I don't dp solid state electronics again but I can still contribute immensely in the field. Thanks buddy. (edited)

    I guess your caps lock got broken. You are welcome.

    Lol, yes but now fixed. Thanks again