Microcontroller, Study notes of Embedded Systems

A microcontroller is a one-chip computer. In a single package, it has the computing core and memory (or various types) needed to store and run small programs.

Typology: Study notes

2022/2023

Uploaded on 03/01/2023

laksh
laksh 🇺🇸

5

(2)

223 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EE 285 Arduino – 1
Microcontroller
A microcontroller is a one-chip computer. In a single package, it has the
computing core and memory (or various types) needed to store and run
small programs. There will be connections for power (obviously) and a
serial communications channel for moving program information onto
the controller and receiving information from the program.
In addition a microcontroller has a number of other input and output
connections.
Digital inputs from external sources. These will detect whether the
voltage on the input is “high” or “low”, which correspond to logic
level 1 and logic level 0. The low voltage is usually 0 V and the high
either 3.3 V or 5 V, depending on the particular controller.
Digital outputs that drive external components. These can be set to
either a high or low voltage to activate (or de-activate) components
attached to the output.
Analog inputs that measure the measure voltage of a component
attached to the input. The voltage must be between 0 and 5 V,
typically.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Microcontroller and more Study notes Embedded Systems in PDF only on Docsity!

Microcontroller

A microcontroller is a one-chip computer. In a single package, it has the

computing core and memory (or various types) needed to store and run

small programs. There will be connections for power (obviously) and a

serial communications channel for moving program information onto

the controller and receiving information from the program.

In addition a microcontroller has a number of other input and output

connections.

  • (^) Digital inputs from external sources. These will detect whether the

voltage on the input is “high” or “low”, which correspond to logic

level 1 and logic level 0. The low voltage is usually 0 V and the high

either 3.3 V or 5 V, depending on the particular controller.

  • (^) Digital outputs that drive external components. These can be set to

either a high or low voltage to activate (or de-activate) components

attached to the output.

  • (^) Analog inputs that measure the measure voltage of a component

attached to the input. The voltage must be between 0 and 5 V,

typically.

Microcontroller

Other connections

  • (^) Analog outputs produce an analog voltage that can be applied to an

external component. (Not all controllers have these.)

  • (^) Pulse-width modulation (PWM) produces a high/low square-wave

signal where the ratio of the high time to the low time can be varied.

PWM is usually produced by digital output pin. PWM can be used

as a “fake” analog output for controllers that do not have real analog

outputs.

Many of the pins are multi-purpose and can configured to do different

jobs. For example, a digital pin can be configured to be either an input

or an output. The analog output pins can be set up to work in a digital

fashion if needed.

These various input / output connections provide an interface between

the digital core and the outside world, allowing for measurement of

external effects and allowing for the microcontroller to make changes in

response to external stimuli.

Analog vs. Digital

A key concept in beginning to design and use micro controllers in

embedded systems is understanding the difference between analog and

digital signals.

Analog - a continuously varying energy or quantity of material. Much of

how we interact with the surrounding physical world is analog in nature

  • sound, sight, smell, taste. We use sensors to convert physical analog

quantities to analog voltages or currents. (Microphones, photosensors,

temperature sensors, etc.) Just like the physical quantity, the voltage or

current is defined at every point in time. Detecting an analog voltage or

current requires requires precisely measuring the volts or amps at a

particular time. A reasonable example of an signal is a sine wave.

(Although there isn’t much information in a pure sine wave.)

Digital - The signal is either high or low (on/off or true/false or 0 /1).

There are not many digital signals in the physical world. However, in

terms of encoding information into signals, digital is much more robust.

There is more leeway in interpreting whether a voltage is high or low.

“High” means simply being “high enough” — above some threshold

level. “Low” means simply being “low enough” — below some

threshold level. Interpreting the information from a digital signal is less

susceptible to errors because the voltages don’t have to be known

precisely.

The systems that we have developed to collect information work best by

collecting the analog information from the surrounding physical

environment, converting it digital form, processing the information

digitally, and then converting back to analog (if needed).

Microcontrollers

  • (^) Microchip was the original microcontroller company. The first

controller was the PIC1650 in 1976. (The company at that time was

General Instruments. Microchip was spun out as a separate company

in the late 1980s.) PIC originally stood for Peripheral Instrumentation

Controller. Microchip sells more than 1 billion microcontrollers per

year.

  • (^) Atmel was founded in 1984, specifically to compete in the

microcontroller market. Their major product line is the AVR family of

controllers. Earlier this year Atmel was bought by Microchip.

  • (^) Texas Instruments (TI) is one of the original electronics companies. TI

engineer Jack Kilby was one of the co-inventors of the integrated

circuit. The MSP430 is one of their primary microcontroller products.

  • (^) Many other companies

ARM is separate microcontroller architecture owned by ARM Holdings

(from Great Britain) that is licensed by many companies. It is used in all

smartphones and finds increasing use elsewhere.

Microcontrollers

There are literally hundreds of microcontrollers available from the

various companies. The differ on the number of bits (8, 16, 32, 64),

memory (a few kilobytes to 1 gigabyte), clock speed (10s of kilohertz to

1 gigahertz), price (a few cents to 10s of dollars) and the number of

inputs and outputs (3 or 4 up to 100 or more).

Start with 1 example - the Atmega328 from Atmel. (This is what is in the

most popular Arduino.)

  • (^) 8-bit AVR architecture
  • (^) 8 – 20 MHz clock frequency (16 MHz is typical)
  • (^) 32 kbytes of flash memory (program storage)
  • (^) 2 kbytes of static memory
  • (^) 28-pin or 32-pin package
  • (^) 14 digital I/O
  • (^) 6 analog input (no analog out)
  • (^) 6 PWM outputs (part of the 14 digital I/0)

Developing embedded sytstems

What used to be needed to get started? (In the “old” days.)

  • (^) To make the hardware operational, the controller chip will need: a

power supply, a clock oscillator crystal, a serial communications

connection, and physical connections for all of the digital and analog

pins. Typically, this is provided by a prototyping platform available

from the microcontroller supplier. Of course, developers can also

build their own prototype hardware, but this is usually not an

effective use of resources.

  • (^) Integrated Development Environment (IDE). Software for the

controller must be written on a regular computer (Windows/MacOS/

Linux) and then transferred to the controller. Typically, the IDE is not

particularly user friendly — some prior software experience is

probably needed. Also, a special hardware dongle (a programmer) is

needed for the transfer.

Upshot: Developing embedded systems is only for “professionals”.

Hobbyists or “makers” need not apply.

Enter Arduino

In 2005, a group at the Interactive Design Institute Ivrea in Ivrea, Italy

put together a hardware / software platform that would make it much

easier to build embedded systems prototypes. (The titular leader of the

group was — and still is — Massimo Banzi, although there were four

other founders.) They named the platform Arduino , after a bar that they

frequented. They were focusing on making a system on which students

and hobbyists could learn easily and would affordable to non-

professionals. Their efforts unleashed the current “maker” movement.

There have been several iterations on the basic platform over the years.

The current standard hardware arrangement is the Arduino Uno.

Hardware expansion through “shields”

Ethernet WiFi Bluetooth

Touch display Motor

Arduino Uno software

  • (^) The IDE for the Arduino is a Java application (runs identically on

Windows / Mac / Linux).

  • (^) The programs (called sketches) are written in a subset of C. (Good for

us!) There some special commands for defining the operation of I/O

and for receiving/sending information to those pins.

  • (^) There is a USB interface to facilitate transferring programs from the IDE

on the computer to the controller. (No hardware dongle!) The USB

interface also conveniently provides power when connected to a

computer.

  • (^) There is an interface analogous to the console for sending information

and receiving information from the controller. (serial monitor)

  • (^) Note: The controller is meant to operate in a stand-alone mode. It is

not intended to be tethered to the host computer indefinitely. But

when developing the software, it is important to be able to “see” what

is happening with the program.

  • (^) Everything is open-source. (Including the hardware design.)

Structure of an Arduino program

An Arduino program (sketch) is slightly different from our typical C

program. In a microcontroller, there is no main function. Instead there

are two separate functions — one called setup() and a second called

loop() runs in a continuous loop.

  • (^) The setup function behaves just like a regular C program. Program

flow starts at the top and progresses through to the last line. (If there

are any loops, they behave according to the conditionals like we

would expect.) As the name implies, the purpose of setup is to define

variables, set the function of the pins, and take care of any

preliminary housekeeping. When setup() is complete, program flow

passes to loop().

  • (^) The program continues with the first line of loop and then progresses

through to the last line. But, as the name implies, the program goes

back to the first line of loop and runs again. And again and again.

Forever. (Or until the power is removed.) It is as there is an implied

while loop whose conditional is always true.

Once you have downloaded the Arduino software and installed it*.

When you launch it, you will get a blank, generic program. The setup

and loop functions are empty.

*MacOS does not have Java installed by default. When you try to run

the Arduino IDE for the first time, you will be asked if you want install

Java. Follow the instructions to do so.

There are many example programs that you can use to help in learning

the various commands. The simplest is a program called “Blink” that

will make one of the light-emitting diodes on the board blink on and off.

Choose it from the menu.

Note: A bunch of

comments at the top of

the program have been

removed to save space.

Inside setup(): The pin

mode command defines

the pin connected to the

built-in LED (also known

as pin 13) to be a digital

output.

Inside loop(): The first command sets the voltage of the LED pin to the

high value (5V), turning on the LED. The second command is a 1 s

(1000 ms) delay. (Basically, do nothing for 1 second.) The third

command sets the voltage of the LED to the LOW value (0 V), turning

off the LED. Then there is another 1000 ms delay. Then everything

repeats — the LED will repeatedly blink on and off.