micrcontroller Archives - Electronic Guidebook https://electronicguidebook.com/tag/micrcontroller/ A place to help you with your electronic needs Sat, 11 Jul 2020 03:17:18 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://electronicguidebook.com/wp-content/uploads/2020/02/cropped-electronicGuidebookLogoTransparent-1-32x32.png micrcontroller Archives - Electronic Guidebook https://electronicguidebook.com/tag/micrcontroller/ 32 32 230945861 What are microcontroller peripherals? https://electronicguidebook.com/what-are-microcontroller-peripherals/?utm_source=rss&utm_medium=rss&utm_campaign=what-are-microcontroller-peripherals Mon, 06 Jul 2020 00:18:18 +0000 https://electronicguidebook.com/?p=298 A microcontroller is a versatile device capable of many things. It is essentially a mini computer on a single semiconductor integrated circuit chip. It can be found in many different applications that range from consumer electronics, medical, marine, automotive, aviation and many more. A microcontroller has many features that make it the choice for hobbyists […]

The post What are microcontroller peripherals? appeared first on Electronic Guidebook.

]]>
A microcontroller is a versatile device capable of many things.

It is essentially a mini computer on a single semiconductor integrated circuit chip.

It can be found in many different applications that range from consumer electronics, medical, marine, automotive, aviation and many more.

A microcontroller has many features that make it the choice for hobbyists working in their garage, and engineers working in the industry.

Microcontrollers have many features which include something known as peripherals.

But, what are microcontroller peripherals?

Microcontroller peripherals are parts of the device that serve a specific purpose which help the microcontroller achieve a certain task. Some common microcontroller peripherals are Timers, Analog to Digital converters (ADC), Serial Peripheral Interfaces (SPI), Pulse Width Modulation and 2 wire interfaces (I2C). 

These common peripherals are built into the microcontroller and is one distinguishing difference between it and the microprocessor.

Peripherals that come stock with the microcontroller are known as on-chip peripherals, and ones that you add and interface separately are known as off-chip peripherals. 

What is the main purpose of microcontroller peripherals?

As you briefly saw above, microcontroller peripherals serve a specific purpose that help the microcontroller with a given task.

Let’s take the Analog to Digital Converter (also better known as the ADC) peripheral as an example. 

The ADC has one specific task, which is to take analog data it receives from a sensor (or other any device that outputs analog data), and convert it to digital values that the microcontroller can then process. 

This opens up many possibilities for applications. 

Here is a simple example.

Say you want to turn on a fan when it gets too hot.

The temperature sensor reads the physical temperature of the environment in analog form. 

But, the microcontroller cannot process this information as it is in analog form. 

This is where the ADC lends its helping hand. 

It converts this analog data to digital which the microcontroller can then process accordingly. 

As you can see, the ADC helps the microcontroller with a specific task.

All the other microcontroller peripherals have different functions, but just like the ADC, help the microcontroller with a specific task.

Why use microcontroller peripherals?

The simple answer is to let you perform the task the peripheral was designed to do.

The ADC has the ability to convert analog data to digital.

From the example you saw above, without the ADC, the microcontroller would not be able to do anything with the data it receives from the temperature sensor.

The project specifications will determine what peripherals are needed or not needed. 

Different microcontroller peripherals examples

Microcontroller’s have many peripherals available for different applications.

Listing all of them might take some time, so I will list the peripherals that are most commonly used by a microcontroller.

These peripherals are always found embedded in the microcontroller.

The most common microcontroller peripherals are:

  • Timers
  • Analog to Digital Converter
  • Digital to Analog Converter
  • Serial Communication (SPI, I2C, and UART)
  • General Purpose Input/Output registers
  • Memory (FLASH, SRAM, EEPROM)
  • Pulse Width Modulation

Microcontroller Peripheral #1 : TIMER

The first peripheral that is always found in a microcontroller is the Timer.

Think of your daily life.

Everything you do is determined by a start time, duration and finish time.

You get up at 8am, get to work by 9am, work till 5pm, go to the gym at 6pm etc.

A microcontroller is very similar in the sense that it has operations which have starting times, durations and end times.

So, it needs some way of keeping track of all these events.

That is where the Timer comes in!

The Timer is an important part of a microcontroller as it maintains the timing of operations and keeps it in-sync with the system clock of the microcontroller.

A simple example of this is blinking an LED.

This might seem like not a great feat, but without the capabilities of the Timer you would not be able to do something as simple as turning an LED on and off.

Microcontroller Peripheral #2 : Analog to Digital Converter 

I mentioned the Analog to Digital Converter (ADC) earlier and its ability to convert analog data to a digital form.

This is one of the reasons the ADC is such a common peripheral in microcontrollers.

Sensors are devices that sense the physical world.

There are sensors available that can sense temperature, humidity, light, altitude, force and many more.

However, most if not all these sensors output values that are in an analog format.

As you saw earlier, the microcontroller can only process digital data (0’s and 1’s) and that is where the ADC bridges that gap. 

Microcontroller Peripheral #3 : Digital to Analog Converter

So, the microcontroller can convert analog data to digital using the ADC.

Can it reverse the process and covert digital data to analog?

Yes, absolutely!

Thanks to the Digital to Analog Converter (also known as DAC) peripheral.

The DAC peripheral gives the microcontroller the ability to reverse the process and convert digital to analog.

One of the many examples where this comes handy is playing audio from the micrcontroller’s memory.

You know now that the microcontroller only deals with digital values.

Say a piece of audio is recorded using a microphone and converted to digital data using the ADC and stored in the micrcontroller’s memory in a digital format.

To be able to recreate this audio and play it through a speaker, you will need the help of the DAC.

The DAC converts the digital values into an analog form that can then be played through a speaker.

Microcontroller Peripheral #4 : Serial Communication

Communication is an essential part in everyday life.

We communicate to each other visually, and orally to argue a point , to socialize, teach, learn etc.

Imagine a world where you weren’t able to communicate to your loved ones or anybody at all.

That world would suck!

In the world of microcontrollers, communication is also a crucial element. 

Microcontrollers have a range of serial communication peripherals which include:

  • Serial Peripheral Interface (SPI)
  • Two Wire Interface (I2C)
  • Universal Asynchronous Receiver /Transmitter (UART)

Serial communication allows a microcontroller to ‘talk’ to another microcontroller, computer or external peripheral devices.  

Communication allows the exchange of data which can be information like status updates, or sensor data.

Microcontroller Peripheral #5 : General Purpose Input/Output

Number 5 on the list of common microcontroller peripherals are input and output pins or GPIO’s.

Without the GPIO peripheral the microcontroller would not be able to interface with the other devices.

Devices such as:

  • Motors (Servos, stepper motors, DC brushless motors)
  • Sensors
  • LED’s
  • Buttons
  • Switches

Turning on a LED, reading a button press, connecting a sensor, etc, all requires input and output registers.

A microcontroller pin can be programmed either as an input or output.

Microcontroller Peripheral #6 : Memory

Remember what you did yesterday? (hopefully you do!)

That’s thanks to your memory! 

Our memory lets us remember important life events, things we have learnt, skills we have practiced, habits etc.

A microcontroller has memory for similar purposes.

It also has short term and long term memory just like we do.

A microcontroller memory peripheral typically has 3 types of data storage”

  • Static Random Access Memory (SRAM)
  • FLASH
  • Electrically Erasable Programmable Read Only Memory (EEPROM)

The short term memory (SRAM)  is used to store constants and variables that are used by the microcontroller during normal program execution. 

When the power is removed, all memory in RAM is lost.

Long term memory (FLASH) is where things like the program the software designer has written gets stored. 

Even when power is turned off, this memory remains. 

Microcontroller Peripheral #7 : Pulse Width Modulation

Last but not least of common microcontroller peripherals is Pulse Width Modulation (PWM).

The PWM peripheral works in conjunction with the timer peripherals of a microcontroller. 

What is PWM used for?

Say you have a motor connected to one of the output pins of the microcontroller. 

The speed of that motor can either be 0v or maximum voltage that the microcontroller is operating at (let’s say 5V).

But, you want to be able run that motor at a range of voltages from 0V to 5V that will alter its speed accordingly. 

That is where the PWM peripheral works its magic.

By connecting the motor to a PWM enabled pin you can vary the speed of the motor. 

Maybe you want to dim an LED, again PWM is what is needed. 

Do all microcontrollers have peripherals?

Microcontrollers come in a range of sizes, speeds, architectures, and manufacture families.

The most common microcontrollers available and used are Atmel AVR, 8051, and PIC.

While microcontrollers vary in specifications mentioned above, they all come with a set of peripherals.

However, a larger microcontroller might have more peripherals compared to a smaller microcontroller.

I covered the most common peripherals that are found in microcontrollers earlier. These peripherals can be found in most if not all microcontrollers regardless of size.

Other microcontroller peripherals (which are a bit more unique) might only be available to chips with higher specifications. 

Where are microcontroller peripherals located?

The standard peripherals like Memory, GPIO, ADC, DAC, Serial Communication and Timers are located internally in the microcontroller. 

However, there are peripherals that are available as separate modules and can be interfaced with the microcontroller externally. 

Maybe you want to add bluetooth capability to your next project. 

To do so, you will need to add an external bluetooth peripheral and interface it with the microcontroller. 

Can a microcontroller function without peripherals?

There is no specific answer for this question as it all depends on the specifications and complexity of the application.

While there are some peripherals that the microcontroller can function without, there are certain peripherals that it relies on.

These peripherals include Memory and Timers.

It requires memory to store the main program, as well as constants and variables during runtime. 

And it needs the Timer to ensure operations are run in sync with the system clock and on schedule. 

When is the best time to use microcontroller peripherals?

Knowing when to use a microcontroller peripheral all depends on the needs of the project.

When writing the program code, you as the designer will have to know when you will need to call on the functions of the ADC, or Serial Communication or Timers etc.

It might be right at the start of the program, or you might have to call on them depending on external factors.

By knowing the needs of your projects will determine when you use a particular microcontroller peripheral

Final Thoughts

A microcontroller is a great piece of engineering, that enables us to achieve many things and has been found in many applications.

Applications in Medical, Automotive, Aviation, Consumer Electronics and many more. 

But, sometimes a microcontroller by itself can be quite redundant.

That is where peripherals come to the rescue.

Microcontroller peripherals are parts modules of a microcontroller (internal or external) that serve a specific task.They help the microcontroller perform operations that it would not be able to do by itself. 

Much like a mouse and keyboard of a computer. 

The computer is capable of so many things, but remove simple peripherals like the mouse and keyboard and the computer is rendered useless. 

The mouse and keyboard serve specific tasks that help you and the computer.

The post What are microcontroller peripherals? appeared first on Electronic Guidebook.

]]>
298
Why a microcontroller is used in an embedded system https://electronicguidebook.com/why-a-microcontroller-is-used-in-an-embedded-system/?utm_source=rss&utm_medium=rss&utm_campaign=why-a-microcontroller-is-used-in-an-embedded-system Wed, 20 May 2020 23:44:08 +0000 https://electronicguidebook.com/?p=271 Think of the human body as an embedded system. It has inputs in the form of our 5 senses (Sight, Hearing, Touch, Taste, Smell), outputs like our fingers, hands, toes, legs and communication means like speech.  However, all these abilities that we possess are useless without one vital human anatomy, the Brain. The Brain has […]

The post Why a microcontroller is used in an embedded system appeared first on Electronic Guidebook.

]]>
Think of the human body as an embedded system.

It has inputs in the form of our 5 senses (Sight, Hearing, Touch, Taste, Smell), outputs like our fingers, hands, toes, legs and communication means like speech. 

However, all these abilities that we possess are useless without one vital human anatomy, the Brain.

The Brain has the task of processing all information it receives from inputs, as well as telling the outputs what to do, and has its own memory where it can store data.

The microcontroller is essentially the brain of an embedded system. 

So, why is a microcontroller used in an embedded system?

A microcontroller is used in an embedded system because it is tasked with processing the flow of data that comes in and goes out. It makes decisions according to code which are written by a developer. It performs operations based on data it obtains via inputs and sends data telling outputs what actions to perform. It also stores information onboard its inbuilt memory.

Just like a human body without a brain, an embedded system without a microcontroller would be redundant.

Embedded systems range in complexity, and specifications, but one thing that is certain is that at the center of it all is a microcontroller controlling all operations.

What is a Microcontroller?

A microcontroller is an Integrated Chip (IC) which includes onboard memory, programmable peripheral Inputs and Outputs, Timers, Serial Communication and many more features that I will cover below.

It is essentially a small computer on a single chip.

While computers come with an Operating System (program that tells the computer what actions to perform), Micrcontrollers do not come installed with an Operating System.

The operating system or program code needs to be written by a developer (in a programming language like C, C++, or Java) and then loaded onto the microcontroller.

Main purpose 

As we saw earlier, the main purpose of a microcontroller is to process data and perform operations based on its program code as well as information received via inputs or serial communication.

It is the main component in an embedded system.

Basic structure

The microcontroller is a very versatile device that has many features depending on the needs of an embedded system.

They range in physical size, memory, speed, and other features.

Below are the features of a common used (by me as well) microcontroller, the AT Mega 8 from the AVR family of microcontrollers produced by Microchip:

  • 8 Kbytes in-system, self programmable Flash program memory
  • 512 Bytes EEPROM
  • 1 Kbyte Internal SRAM
  • Two 8-bit Timer/Counters
  • One 16-bit Timer/Counter
  • Three PWM channels
  • Six 10-bit ADC channels
  • Two-wire serial interface
  • SPI Serial Interface
  • 3 x 8 programmable input/output ports

These are just some of the features. For a full list of features consult the AT Mega 8 datasheet

There are many other microcontrollers from the AVR family which are produced by Microchip.

Microchip isn’t the only manufacturer of microcontrollers. There are many companies that produce microcontrollers built on different architectures. 

However, they all share similar specifications and features. 

The other common microcontrollers available are the PIC, 8051, and ARM.

Difference between Microprocessor and Microcontroller?

Microcontrollers aren’t the only type of processor used in embedded systems.

Microprocessors are very similar to microcontrollers but have their differences.

Both are at the center of an embedded system and are responsible for controlling operations.

Microcontrollers can be seen as stand alone devices that contain memory, timers etc.

While microprocessors do not have their own memory and require extra memory modules to be interfaced.

For an in-depth look at the differences, check this article

What is an Embedded System?

I gave the example of the human body as an embedded system earlier. 

But, what does an electronic embedded system look like? 

What does it consist of? 

Basics of an Embedded System

The basic definition of an electronic embedded system is a system that contains a combination of hardware and software. 

Hardware includes the processing unit (microcontroller or microprocessor), inputs and outputs. 

The software which is loaded onto a microcontroller is a set of instructions that govern how the system runs.

An embedded system is designed for a specific function or functions of a self contained system or part of a larger subset of systems.

An example of an electronic embedded system is a desktop computer.

The computer has software (its operating system) which governs how it operates. This operating system is loaded onto the microprocessor.

It has hardware which include a central processing unit (CPU), inputs (keyboard, mouse, usb ports, HDMI etc) and outputs (computer screen, speakers, printers etc).

Different components of an Embedded System

We now know that an Embedded system consists of Hardware and Software.

I gave a simple example of what an embedded system consists of above. 

But, there are many more components within the Hardware and Software. 

Let’s take a quick look at what they are.

Hardware

Power Supply 

I know I said an embedded system would be redundant without a microcontroller. 

But, it would be utterly useless without a power supply. 

The power supply supplies the entire system with electricity which is needed for all parts of the embedded system to operate.

The voltage requirements of the embedded system all depends on the voltage specifications of devices being used.

The maximum voltage rating of any device should never be exceeded.

Processor

As I have discussed earlier, the processor (either a Microcontroller or Microprocessor) is a vital part of an embedded system.

It gets programmed with all instructions on how the embedded system should operate. 

It has the job of communicating with other components of the system and controlling the flow of data.

Memory

Memory is needed to store the program code (set of instructions which determines how the embedded system functions), and data like variables and constants .

There are three types of memory:

  • Random Access Memory (RAM)
  • Read Only Memory (ROM)
  • Electrically Erasable Programmable Read-Only Memory (EEPROM)

Each memory type plays a specific role when the embedded system is running.

RAM is a volatile type of memory, which means when power is removed from the system, all data in RAM is erased. It is used to store temporary data.

ROM is memory where the program code is stored.

EEPROM is a memory where variables can be stored and once power is removed, does not get erased making it non-volatile.

Microcontrollers have the advantage of having memory in-built on their chips. 

Timer/Counters

Timers and counters are needed when you need to generate a delay, count time between two specific events, and generate pulse-width-modulation (PWM).

Communication 

In order to talk with other devices in an embedded system, it will require some means of communication.

Below are some of the communication methods available:

  • UART
  • SPI
  • I2C
  • USB
  • ETHERNET
  • RS-232
  • RS-485

Input and Outputs

Inputs provide information to the embedded system from the external world.

This can be in the form of a button press, or sensors sensing changes in temperature.

Outputs allow the embedded system display information via LED screens or rotate a motor like in a car.

Software

The next ingredient that will complete our embedded system is software. 

Software is a set of instructions (program code) that can be written in a programming language.

Programming languages can range from C, C++, Java, and Python.

But, the programming language is only one part of the Software component.

Other components include:

  • Integrated Development Environment (IDE)– is a software where the developer can write code in a specific language. 
  • Compiler– converts the code that has been written in an IDE  into machine code which is then loaded onto the microcontroller

Choosing the right Microcontroller for an Embedded system

While microcontrollers are different in size, specification, and complexity, it can’t be said that one microcontroller is better than another. 

It all depends on the specifications of the embedded system. 

If your system needs to process and calculate information at high speeds, you will need to pick a microcontroller with high processing speeds.

If, however, speed is not of concern, but you need a lot of input and output ports, then you will pick a microcontroller with lower processing speeds and more input and output ports.  

So, defining the needs of your embedded system will allow you to make the right choices when picking a microcontroller. m

Example of Embedded Systems that use a Microcontroller

There are many applications where an embedded device uses a Microcontroller as the processing unit.

Below are some examples (this is just some of the common ones. There are many more):

  • Electronic Development boards (Ardunio, AVR Dragon)
  • Automobile
  • Consumer Electronics (mobile phones, Laptops, gaming systems)
  • Household appliances (washing machines, toaster, microwaves)
  • Medical
  • Aviation

The post Why a microcontroller is used in an embedded system appeared first on Electronic Guidebook.

]]>
271