Experiment 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

EXPERIMENT 2

Introduction to Microcontroller Architecture and Programming


Interface
Objectives:

 To learn about Arduino Mega 2560 hardware architecture


 To learn about programming interface for Arduino development boards

2.1 Arduino Mega 2560


2.1.1 Overview
The Arduino Mega 2560 is a microcontroller board based on the ATmega2560. It has 54 digital
input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs
(hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP
header, and a reset button. It contains everything needed to support the microcontroller; simply
connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started.

Fig 2.1 Arduino Mega 2560 development board


2.1.1 Technical Specifications

2.1.2 Schematics
Arduino Mega 2560 is open-source hardware! You can build your own board using the files
given in the documentation. Visit Arduino Mega 2560 documentation page for more details.

2.1.3 Arduino Memories


There are 3 types of memory in an Arduino:
 Flash or Program Memory
 SRAM
 EEPROM

2.1.3.1 Flash Memory


Flash memory is used to store your program image and any initialized data. You can execute
program code from flash, but you can't modify data in flash memory from your executing code.
To modify the data, it must first be copied into SRAM. Flash memory is the same technology
used for thumb-drives and SD cards. It is non-volatile, so your program will still be there when
the system is powered off. Flash memory has a finite lifetime of about 100,000 write cycles. So
if you upload 10 programs a day, every day for the next 27 years, you might wear it out.

2.1.3.2 SRAM
SRAM or Static Random Access Memory, can be read and written from your executing program.
SRAM memory is used for several purposes by a running program:

Static Data - This is a block of reserved space in SRAM for all the global and static variables
from your program. For variables with initial values, the runtime system copies the initial value
from Flash when the program starts.
Heap - The heap is for dynamically allocated data items. The heap grows from the top of the
static data area up as data items are allocated.
Stack - The stack is for local variables and for maintaining a record of interrupts and function
calls. The stack grows from the top of memory down towards the heap. Every interrupt, function
call and/or local variable allocation causes the stack to grow. Returning from an interrupt or
function call will reclaim all stack space used by that interrupt or function.

Fig 2.2 Memory Architecture of Arduino Mega 2560

Most memory problems occur when the stack and the heap collide. When this happens, one or
both of these memory areas will be corrupted with unpredictable results. In some cases, it will
cause an immediate crash. In others, the effects of the corruption may not be noticed until much
later.

2.1.3.3 EEPROM
EEPROM is another form of non-volatile memory that can be read or written from your
executing program. It can only be read byte-by-byte, so it can be a little awkward to use. It is
also slower than SRAM and has a finite lifetime of about 100,000 write cycles (you can read it as
many times as you want).
2.1.4 Bootloader
Microcontrollers are usually programmed through a programmer unless you have a piece of
firmware in your microcontroller that allows installing new firmware without the need of an
external programmer. This is called a bootloader.
If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you
can burn your sketches using an external programmer.

To burn the bootloader, you'll need to buy an AVR-ISP (in-system programmer), USBtinyISP or
build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3
pin header) - make sure you plug it in the right way. The board must be powered by an external
power supply or the USB port.

2.1.5 Communication Protocols


Arduino Mega supports UART, I2C and SPI communication protocols.
2.1.5.1 UART
The first communication protocol we’ll cover is Universal Asynchronous Receiver/Transmitter
(UART). UART is a form of serial communication because data is transmitted as sequential bits
(we’ll get to this in a bit). The wiring involved with setting up UART communication is very
simple: one line for transmitting data (TX) and one line for receiving data (RX). As you may
expect, the TX line is used to for the data to send device, and the RX line is used to receive data.
Together the TX and RX lines of a device using serial communication form a serial port through
which communication can occur.

Fig 2.3 Hardware connection diagram for UART

The term UART actually refers to the onboard hardware that manages the packaging and
translation of serial data. For a device to be able to communicate via the UART protocol, it must
have this hardware! On the Arduino Mega, there is one serial port dedicated for communication
with the computer the Arduino is connected to. That’s right! USB, which stands for Universal
Serial Bus, is a serial port! On the Arduino Mega, this USB connection is broken out through
onboard hardware into two digital pins, GPIO 0 and GPIO 1, which can be used in projects that
involve serial communication with electronics other than the computer.
UART is called asynchronous because the communication does not depend on a synchronized
clock signal between the two devices attempting to communicate with each other. Because the
communication speed is not defined via this steady signal, the “sender” device cannot be certain
that the “receiver” obtains the correct data. Therefore, the devices break data into fixed-size
chunks to ensure that the data received is the same as the data that was sent.

Fig 2.4 UART Data Packet Visualization

2.1.6 Digital and Analog Pins


2.1.6.1 Digital Pins
Digital is a way of representing voltage in 1 bit: either 0 or 1. Digital pins on the Arduino are
pins designed to be configured as inputs or outputs according to the needs of the user. Digital
pins are either on or off. When ON they are in a HIGH voltage state of 5V and when OFF they
are in a LOW voltage state of 0V.
On the Arduino, When the digital pins are configured as output, they are set to 0 or 5 volts.
When the digital pins are configured as input, the voltage is supplied from an external device.
This voltage can vary between 0-5 volts which is converted into digital representation (0 or 1).
To determine this, there are 2 thresholds:

● Below 0.8v - considered as 0.

● Above 2v - considered as 1.

When connecting a component to a digital pin, make sure that the logic levels match. If the
voltage is in between the thresholds, the returning value will be undefined.

2.1.6.2 Analog Pins


Arduino has analog pins, which utilize ADC (Analog to Digital converter). These pins serve as
analog inputs but can also function as digital inputs or digital outputs.
ADC stands for Analog to Digital Converter. ADC is an electronic circuit used to convert analog
signals into digital signals. This digital representation of analog signals allows the processor
(which is a digital device) to measure the analog signal and use it through its operation.
Arduino Analog Pins are capable of reading analog voltages. On Arduino the ADC has 10-bit
resolution, meaning it can represent analog voltage by 1,024 digital levels. The ADC converts
voltage into bits which the microprocessor can understand.
One common example of an ADC is Voice over IP (VoIP). Every smartphone has a microphone
that converts sound waves (voice) into analog voltage. This goes through the device’s ADC, gets
converted into digital data, which is transmitted to the receiving side over the internet.

2.1.7 Pulse Width Modulation


In general, Pulse Width Modulation (PWM) is a modulation technique used to encode a message
into a pulsing signal. A PWM is comprised of two key components: frequency and duty cycle.
The PWM frequency dictates how long it takes to complete a single cycle (period) and how
quickly the signal fluctuates from high to low. The duty cycle determines how long a signal stays
high out of the total period. Duty cycle is represented in percentage.

In Arduino, the PWM enabled pins produce a constant frequency of ~ 500Hz, while the duty
cycle changes according to the parameters set by the user. See the following illustration:

Fig 2.5 Different Duty Cycles for PWM

PWM signals are used for speed control of DC motors, dimming LEDs and more.

2.1.8 Software Interface


2.1.8.1 Arduino IDE
The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board.
It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on
Processing and other open-source software. This software can be used with any Arduino board.
Refer to the Getting Started page for Installation instructions.
Fig 2.6 Arduino IDE

Describe the difference between Flash Memory and SRAM of microcontroller. Write down
the items that you use in your daily life which utilizes Flash Memory.
What is the advantage of EEPROM? When you will use EEPROM in your
microcontroller?

What are the disadvantages of uploading code using Arduino Bootloader? How you can
avoid it?

Why ADC is used for Analog pins in microcontrollers?

How speed of DC motor is controlled by PWM technique?

You might also like