Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Introduction (Part 1)
Míriam Laliga Cervilla
[email protected]
2019-2020
Pere Tuset-Peiró
[email protected]
1
Introduction
Index of contents
1) Preliminary test results
2) Data representation and conversion
3) Data operations
2
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Preliminary test results
3
Preliminary test results
Mark distribution
4
0
0 1 2 3 4 5 6 7 8 9 10
4
Preliminary test results
Question distribution
16
14
12
10
0
1 2 3 4 5 6 7 8 9 10
Correcte Incorrecte NS/NC
5
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Data representation and conversion
6
Data representation and conversion
Number Base Notation
Decimal, Base 10 <num> or d’<num>’ or <num>d
Ex) 11 or d’11’ or 11d
Binary, Base 2 0b<num> or b’<num>’ or
<num>b
Ex) 0b1011 or b’1011’ or 1011b
Octal, Base 8 q’<num>’ or <num>q
Ex) q’13’ or 13q
Hexadecimal, Base 16 0x<num> or h’<num>’ or
<num>h
Ex) 0xBD or h’BD’ or BDh
7
Data representation and conversion
Binary to Decimal
• Each digit has a “weight” of 2n depending on the digit
position
• Multiply each digit by its “weight” and sum the resultant
products
• Convert b’1011’ to decimal
23 22 21 20 (weight)
% 1 0 1 1
= 1•(23) + 0• (22) + 1• (21) + 1• (20)
= 1•(8) + 0• (4) + 1• (2) + 1• (1)
= 8+ 0+2+1
= d’11’
8
Data representation and conversion
Binary to Decimal with Fractions
• The weight of the binary digits have negative positions
• Convert b’1011.101’ to decimal
23 22 21 20 2-1 2-2 2-3
1 0 1 1 . 1 0 1
= 1•(23) + 0• (22) + 1• (21) + 1• (20) + 1• (2-1) + 0• (2-2) + 1• (2-3)
= 1•(8) + 0• (4) + 1• (2) + 1• (1) + 1• (0.5) + 0• (0.25) + 1•
(0.125)
= 8 + 0 + 2 + 1 + 0.5 + 0 +
0.125
= d’11.625’
9
Data representation and conversion
Decimal to Binary
• The decimal number is divided by 2, the remainder is
recorded
• The quotient is then divided by 2, the remainder is
recorded
• The process is repeated until the quotient is zero
• Elements are collected in LIFO order
ex) Convert 11d to binary
Quotient Remainder
11/2 5 1 LSB
5/2 2 1
2/2 1 0
2/1 0 1 MSB 10
Data representation and conversion
Decimal to Binary with Fractions
• Fraction is converted to binary separately
• Fraction is multiplied by 2, the 0th digit is recorded
• Remaining fraction is multiplied by 2, the 0th digit is
recorded
• The process is repeated until the fractional part is zero
• Elements are collected in FILO order
ex) Convert 0.375 decimal to binary
Product 0th Digit
0.375•2 0.75 0 MSB
0.75•2 1.50 1
0.5•2 1.00 1 LSB
11
d’0.375’ = b’.011’
Data representation and conversion
Hexadecimal to Decimal
• Same process as “binary to decimal” except the weights
are now BASE 16
• Note: h’A’=d’10’, h’B’=d’11’, h’C’=d’12’, h’D’=d’13’,
h’E’=d’14’, h’F’=d’15’
ex) Convert h’2BC’ to decimal
162 161 160 (weight)
2 B C
= 2• (162) + B• (161) + C• (160)
= 2•(256) + 11• (16) + 12• (1)
= 512 + 176 + 12
= d’700’
12
Data representation and conversion
Hexadecimal to Decimal with Fractions
• Fractional digits have negative weights (BASE 16)
• Note: h’A’=d’10’, h’B’=d’11’, h’C’=d’12’, h’D’=d’13’,
h’E’=d’14’, h’F’=d’15’
ex) Convert h’2BC.F’ to decimal
162 161 160 16-1 (weight)
2 B C . F
= 2• (162) + B• (161) + C• (160) + F• (16-1)
= 2•(256) + 11• (16) + 12• (1) + 15• (0.0625)
= 512 + 176 + 12 + 0.938
= d’700.938’
13
Data representation and conversion
Decimal to Hexadecimal
• Same procedure but with BASE 16 as the
divisor/multiplier
ex) Convert 420.625 decimal to hex
1st, convert the integer part
Quotient Remainder
420/16 26 4 LSB
26/16 1 10
1/16 0 1 MSB
= h’1A4’
2nd, convert the fractional part
Product 0th Digit
0.625•16 10.00 10 MSB
= h’.A’
14
d’420.625’ = h’1A4.A’
Data representation and conversion
Decimal to Octal / Octal to Decimal
• The same procedure is used as before but with BASE 8
as the divisor/multiplier.
15
Data representation and conversion
Hexadecimal/Octal to Binary
• Each hexadecimal digit is made up of four binary bits
which represent 8, 4, 2, and 1
Ex) Convert h’ABC’ to binary
A B C
= 1010 1011 1100
= b’1010 1011 1100’
• Octal to binary works the same except using groups of
three binary bits which represent 4, 2, and 1
16
Data representation and conversion
Binary to Hexadecimal/Octal
• Pack 4 binary bits for one hexadecimal digit
• Begin the groups of four at the LSB
• If necessary, fill the leading bits with 0’s
ex) Convert b’1100101111’ to hex
= 0011 0010 1111
3 2 F
= h’32F’
• Binary to Octal is the same but using groups of 3 binary
bits
17
Data representation and conversion
Negative numbers
• Sign-Magnitude (historical): b’1111 1111’ = d’-127’
• 0 and -0 can be represented
• 8-bit range: -127 to 127
• Number line: 0,1,…,127,-0,-1,…,-127 <repeat>
• One’s Complement (historical): b’1111 1111’ = d’-0’
• 0 and -0 can be represented
• 8-bit range: -127 to 127
• Number line: 0,1,…,127,-127,-126,…,-0 <repeat>
• Two’s Complement (used today): b’1111 1111’ = d’-1’
• Only one 0 representation, always one more negative value than positive
• 8-bit range: -128 to 127
• Number line: 0,1,…,127,-128,-127,…-1 <repeat>
18
Data representation and conversion
Two’s Complement
• Encoding to represent negative numbers in modern
computers as it allows to use “adding” circuitry to perform
subtraction
• Since the number of bits we have is fixed use MSB as a
sign bit
Positive #’s : MSB = 0 (ex: b’0000 1111’ is positive number)
Negative #’s : MSB = 1 (ex: b’1000 1111’ is negative number)
• Range of #’s that a two’s complement code can represent
is:
(-2n-1) < N < (2n-1 – 1) : n = number of bits
ex) What is the range of #’s that an 8-bit two’s complement
code can represent?
(-28-1) < N < (28-1 – 1) 19
(-128) < N < (+127)
Data representation and conversion
Two’s Complement Negation
• How to find the negative equivalent of a positive number?
• Take the two’s complement of a positive
Nc = 2n – N
Nc = Two’s Complement
N = Original Positive Number
ex) Find the 8-bit two’s complement representation of –
52dec
N = 52dec
Nc = 28 – 52
= 256 – 52
= 204 = b’1100 1100’
Note the sign bit
20
Data representation and conversion
Two’s Complement Negation
• How to find the negative equivalent of a positive number?
• Invert all the bits of the original positive number (binary)
and add 1 to the result
ex) Find the 8-bit two’s complement representation of –52d
N = +52d = b’0011 0100’
Invert: = 1100 1011
Add 1 = 1100 1011
+ 1
--------------------
b’1100 1100’ (-52d)
Note the sign bit
21
Data representation and conversion
Binary Coded Decimal (BCD)
• Represent individual decimal digits as a binary
representation using 4 binary digits
Decimal BCD
0 0000
1 0001
2 0010 ex) Represent 17d
3 0011 Binary = 10001
4 0100 BCD = 0001 0111
5 0101
6 0110
7 0111
8 1000
9 1001
22
Data representation and conversion
ASCII
• American Standard Code for Information Interchange
• English alphanumeric characters represented with a 7-bit
code
23
Data representation and conversion
UNICODE
• Supports text expressed in most of the world’s writing
systems
• Characters represented by one or more bytes (variable
width character encoding)
• UTF-8 is ubiquitous to avoid byte-ordering problems
24
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Data operation
25
Data operation
Binary addition
• Same as BASE 10 addition
• Need to keep track of the carry bit
ex) Add b’1011’ and b’1001’
1 1
1011
1001
+______
1 0100
Carry bit
26
Data operation
Two’s Complement Addition
• Addition of two’s complement numbers is performed just
like standard binary addition, but carry bit is ignored
ex) Add b’1011’ and b’1001’
1 1
1011
1001
+______
1 0100
Carry bit (discard)
27
Data operation
Two’s Complement Subtraction
• Binary subtraction can now be done using addition
algorithm
ex) Subtract d’8’ from d’15’
d’15’ = b’0000 1111’
d’8’ = b’0000 1000’ -> two’s complement -> invert 1111 0111
add 1 1111 0111
+1
-----------------
1111 1000 = d’-8’
Now Add: 15 + (-8) = 0000 1111
Disregard Carry + 1111 1000
-----------------
1 0000 0111 = d’7’ 28
Data operation
Two’s Complement Overflow
• If a two’s complement subtraction results in a number
outside the range of representation (i.e., -128 < N <
+127), an overflow has occurred
ex) -100d – 100d = -200d (can’t represent)
• There are three cases when overflow occurs:
• Sum of like signs results in answer with opposite sign
• Negative – Positive = Positive
• Positive – Negative = Negative
• Boolean logic can be used to detect these situations.
29
Data operation
Logical operations
30
Data operation
Logical operations (examples)
31
Data operation
Masking operations
32
Data operation
Shift operations (logical)
Discarded
Added
33
Data operation
Shift operations (circular)
34
Data operation
Shift operations (arithmetic)
35
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Introduction (Part 2)
Míriam Laliga Cervilla
[email protected]
2019-2020
Pere Tuset-Peiró
[email protected]
36
Introduction
Index of contents
1) Introduction to Embedded Systems
2) Introduction to Microcontrollers
3) Microcontrollers history
4) MSP432P4111 Launchpad Development Kit
37
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Introduction to Embedded Systems
38
Introduction Embedded Systems
What is an Embedded System?
Execute an algorithm:
Sense information from • PID control
the physical world: • Etc.
• Temperature
• Pressure Actuate over the
• Position physical world:
• Velocity • Vehicle brakes
• Flux • Motor control
• Humidity • Etc.
• Sound
• Light
• Etc.
39
Introduction Embedded Systems
What is an Embedded System?
40
Introduction Embedded Systems
What is an Embedded System?
Embedded System
• System in which a computer
is built inside a product to
enable its operation, but that
fact not it is not obvious to the
user
Real-time Embedded
System
• System in which the
correctness of the operation
depends on the logical result
as well as the time at which
the results are produced
41
Introduction Embedded Systems
Embedded Systems requirements
Real time vs. reactive operation
• Systems must provide a timely response according to inputs and deadlines
Reliability and safety considerations
• Design must ensure safety and operation must meet reliability
Environmental regulations
• Integration of analog, digital and power must meet field regulations
Operation in harsh environments
• Component de-rating depends on operation conditions (heat, dust,
vibration)
Cost sensitivity
• Tradeoff between product robustness and cost optimization
42
Introduction Embedded Systems
Task classification (arrival)
Periodic
• The system is driven by
regular time intervals
• A car checking for a wall
every 0.1 seconds
Aperiodic
• The system is driven by
internal/external events
• A car having to react to a wall
it found
43
Introduction Embedded Systems
Task classification (deadline)
Soft real-time
• If there is no deadline or the
computation result is useful
even after the deadline
Firm real-time
• If the computation result is
not useful after the deadline
has passed
Hard real-time
• If missing the computation
deadline can result in a
catastrophe
44
Introduction Embedded Systems
Time definitions
Release time Execution time
• When the job becomes • Time difference between
available for execution scheduling time and
Scheduling time completion time
• When the job is ready to start Response time
its execution • Length of time from release
Completion time time to instant job completes
• When the job finishes its
execution
Absolute deadline
• Instant of time a job's
execution is required to be
completed
45
Introduction Embedded Systems
Embedded Systems share the same architecture but…
46
Introduction Embedded Systems
…not all Embedded Systems are the same
47
Introduction Embedded Systems
…not all Embedded Systems are the same
48
Introduction Embedded Systems
…not all Embedded Systems are the same
49
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Introduction to Microcontrollers
50
Introduction
What is a microcontroller?
What is the difference between:
• Microprocessor
• Microcontroller
• Both have a processor (CPU) to execute instructions but:
51
Introduction
What is a microcontroller?
Microprocessor
• Memory and peripherals in
separate chips
• Used for general purpose
applications, i.e. computer
Microcontroller
• Memory and peripherals in a
single chip
• Used for interfacing and
controlling the physical world,
i.e. embedded systems
52
Introduction
What is a microcontroller?
53
Introduction
Microprocessor vs. Microcontroller market
54
Introduction
What defines a microcontroller?
• Instruction set
• What kind of instructions are available?
• ALU/Registers/Instructions/Bus width
• What is the width of the ALU, registers,instructions and the bus that
connects it to memory?
• Memory organization
• How do we connect memory to the CPU?
• Data organization
• How do we store data in the memory?
55
Introduction
What defines a microcontroller?
CISC (Complex Instruction
Set Computing)
• Complex set of instructions that take
several cycles to execute
• Provides instructions that can
read/write directly to memory
RISC (Reduced Instruction
Set Computing)
• Simple instructions that execute
within a single clock at high speed
• Load-store architecture, processor
can only read/write from registers
56
Introduction
What defines a microcontroller?
Clock frequency
• The number of clock ticks per second
• Typical values range from 1 MHz to 1
GHz
ALU/Register/Instructions/Bus
width
• Number of bits that the CPU can
process in a single clock tick
• Number of bits that can be hold in a
CPU register
• Number of bits that can be transfered
from memory/register to CPU (and
viceversa) in a single clock tick
• Typical values are 8, 16 and 32 bits
57
Introduction
What defines a microcontroller?
Von Neumann Architecture
• Program and data memory
connected to CPU through a single
bus
Harvard Architecture
• Program and data memory
connected to CPU with separate
buses
Modified Harvard
Architecture
• Memory management unit provides
one logical memory space
58
Introduction
What defines a microcontroller?
59
Introduction
What defines a microcontroller?
Endianness
• Format in which data larger than a
single byte (1) is stored in a
computer’s memory
Big Endian Architecture
• Most significant byte is stored at
the lowest memory address
• Adopted by Motorola
Little Endian Architecture
• Most significant byte is stored at
the highest memory address
• Adopted by Intel
60
Introduction
What defines a microcontroller?
• Memory types
• Volatile: SRAM, DRAM
• Non-volatile: EEPROM, Flash
• Peripherals
• Timers: Watchdog, RTC
• Analog I/O: ADC, DAC
• Digital I/O: GPIO, PWM
• Communications: UART, SPI,
I2C
• Packaging / pin count
• DIP (Dual In-Line Package)
• QFP (Quad Flat Package)
• BGA (Ball-Grid Array)
61
Introduction
What defines a microcontroller?
62
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
Microcontroller history
63
Microcontroller history
Transistor
• Semiconductor device that can
switch or amplify electrical
signals
• Vacuum tubes (thermionic
diodes) were invented in 1907
• Allow to control electric currents
• Used in radio and telephony
• Bulky and large power consumption
• First semiconductor transistor
was built at AT&T Bell Labs in
1947
• Bardeen, Bratain & Schockley,
received the Nobel Price in 1956
64
Microcontroller history
Integrated circuit
• Set of electronic circuits
integrated on a small flat piece
of semiconductor material,
typically silicon
• First Integrated Circuit (IC) was
built at Texas Instruments in
1958
• Jack Kilby, received the Nobel Price
in 2000
• In 1969 Robert Noyce from Fairchild
Semiconductor developed a practical
IC
65
Microcontroller history
Intel MCS-48 (1976)
CPU
• 8-bits ALU, data bus and
address space
• Harvard architecture, 10 MHz
clock
• 70% instructions 1 clock, 30%
instructions 2+ clocks
• Performance 0.5-0.73 MIPS
Memory
• 64-128 bytes RAM
• 1-2k ROM (EPROM)
Peripherals
• 2x8-bit bi-directional I/O ports
• 2x 8-bit timers
66
Microcontroller history
Intel 8051 (1980)
CPU
• 8-bit ALU and data bus
• 16-bit address range
• Power saving modes
Memory
• 128 bytes RAM
• 4 kbytes ROM (EPROM)
Peripherals
• 4x8-bit bi-directional I/O ports
• UART interface
• 2x16-bit Timer/Counter
67
Microcontroller history
Texas Instruments MSP430 (1993)
CPU
• 16-bit ALU, data bus and address
range
• RISC instruction set, Von-
Neumann architecture
• Advanced power saving modes
Memory
• 128 bytes to 16 kbytes RAM
• 1 kbyte to 64 kbytes FLASH
Peripherals
• First mixed-signal microcontroller
• ADC (10/12 bits), DAC (12 bits)
• Analog/Digital comparator
68
Microcontroller history
What is happening to microcontrollers today?
Microcontrollers are getting powerful and low-power
• Processing power, memory & I/O in one package
• Floating-point and Digital Signal Processing instructions
Microcontrollers are getting cheap
• 32-bit microcontroller @ $1/1000pcs
• 8/16-bit microcontrollers sell <$0.5/1000pcs
Microcontrollers are getting interactive
• Sensors and actuators, Internet connectivity
• LCD & Display controllers
69
Microcontroller history
What is happening to microcontrollers today?
Moore’s Law: The number of transistors embedded in an integrated circuit doubles every 18
months. There is a trade-off between computing power, energy consumption and device cost.
70
Microcontroller history
What is happening to microcontrollers today?
Thanks to of Moore’s Law, each decade a new computer category is created,
establishing a new use paradigm and creating a new industry.
71
Microcontroller history
What is happening to microcontrollers today?
My current microcontroller is a:
72
Microcontroller history
What is happening to microcontrollers today?
73
Microcontroller history
ARM (Advanced RISC Machines)
• Technology developed at Acorn
Computer Limited in Cambridge
(UK) between 1983-1985, but
ARM founded in November 1990
• Today ARM designs 32-bit
processor cores and companion
technologies, but it does NOT
fabricate silicon
• Licensed to partners that develop
and fabricate microcontrollers
and microprocessors based on
the IP
74
Microcontroller history
ARM Cortex Processor family
ARM Cortex-A family (v7-A)
• Application processor for full
OS and 3rd party applications
ARM Cortex-R family (v7-R)
• Embedded processors for real-
time signal processing and
contol applications
ARM Cortex-M family (v7-M)
• Embedded processors for
MCU and SoC applications
75
Microcontroller history
ARM Cortex Processor family
76
Microcontroller history
ARM Cortex Processor family
77
Microcontroller history
ARM Cortex-M
CPU
• 32-bit ALU, data bus and addresses
• 16-bit instruction set (Thumb)
• Von Neumman (v6M) / Harvard
architecture (v7M)
• FPU (Floating Point Unit) and DSP
(Digital Signal Processor) extensions
• Shared ISA (Instrucion Set Architecture)
Several variants depending on
required performance
• Cortex-M3 (2006)
• Cortex-M0/M0+ (2009)
• Cortex-M4 (2010)
• Cortex-M7 (2015)
78
Microcontroller history
ARM Cortex-M family
79
Microcontroller history
ARM Cortex-M overview
80
Microcontroller history
ARM Cortex-M performance
81
Portada
DEGREE IN MECHATRONICS ENGINEERING
FACULTY OF SCIENCE AND TECHNOLOGY
Microcontrollers
MSP432P4111 Launchpad Development Kit
82
MSP432P4111 Launchpad Development
Kit
Overview
• MSP432P4111 MCU
• ARM Cortex-M4F, 32-bits, 48 MHz
• 256 kbytes RAM, 2 Mbytes FLASH
• 2 buttons/switch, 2 LEDs
• Segmented LCD
• Precision analog temperature
sensor
• XDS110-ET Debug Probe
• EnergyTrace+ Technology
• Backchannel UART through USB
• 40-pin BoosterPack connector
• External connectivity to other
BoosterPack boards
83
MSP432P4111 Launchpad Development
Kit
Overview
XDS110 On-board Debug MSP432P4111
Probe Microcontroller
84
MSP432P4111 Launchpad Development
Kit
Block diagram
85
MSP432P4111 Launchpad Development
Kit
Block diagram
86
MSP432P4111 Launchpad Development
Kit
Block diagram
87
MSP432P4111 Launchpad Development
Kit
Power domains
88
MSP432P4111 Launchpad Development
Kit
MSP432P4111 Pinout
89
MSP432P4111 Launchpad Development
Kit
Power domains
90
MSP432P4111 Launchpad Development
Kit
Onboard debugging
91
MSP432P4111 Launchpad Development
Kit
BoosterPack mapping
92
MSP432P4111 Launchpad Development
Kit
Schematics (1/6)
93
MSP432P4111 Launchpad Development
Kit
Schematics (2/6)
94
MSP432P4111 Launchpad Development
Kit
Schematics (3/6)
95
MSP432P4111 Launchpad Development
Kit
Schematics (4/6)
96
MSP432P4111 Launchpad Development
Kit
Schematics (5/6)
97
MSP432P4111 Launchpad Development
Kit
Schematics (6/6)
98
MSP432P4111 Launchpad Development
Kit
BoosterPacks interface
99
MSP432P4111 Launchpad Development
Kit
BoosterPack kits
100