Sie sind auf Seite 1von 52

MICROCONTROLLER

INTRODUCTION
Lecturer: Dr. Bui Ha Duc
Dept. of Mechatronics
Email: ducbh@hcmute.edu.vn

1
INSTRUCTOR INTRODUCTION
• Full Name: Bui Ha Duc
• From: Vung Tau City
• Bachelor: HCMC University of Technology
• Ph.D: National University of Singapore
(NUS)
• Research fellow / TA in NUS
• Join HCMUTE in 2015
• Lecturer in Department of Mechatronics –
FME
• Teaching: Microcontroller, Embedded
system, Digital signal processing.

2
COURSE OBJECTIVES
• Fundamental knowledge of microcontroller
• How to apply microcontroller to solve technical problems
• MCU: PIC 18F4550

4
ORDER OF INTRUCTION
 Overview about microcontroller and its architecture
o Computer architectures
o Memory organization and program space
o Compilers and simulation software
 Assembly language – brief introduction
 C Language ?
 Input and output of microcontroller – basic I/O, IO
expansion, LED, LCD

5
ORDER OF INTRUCTION (cnt.)
 Interrupt and its applications – very important, concern
with essential concepts such as
o Concurrency
o Polling
o Scheduling
 Timer
 Analog digital conversion – super important, required for
advance course
o Aliasing
o Data acquisition

6
ORDER OF INTRUCTION (cnt.)
 Capture/Compare/PWM module – need PWM for motor
control
 Interface microcontroller with other devices – important
for real applications
o Asynchronous UART
o Synchronous communication protocol
 Apply microcontroller in practical situations - students
present their project

7
COURSE LEARNING OUTCOMES
Upon completion of the course students will be able to
1. Given a simple program, students will be able to explain the
instruction execution and data flow of the microcontroller.
2. Design an interface that allows a microcontroller port pin to
control peripheral devices such as LED, LCD, motor.
3. Create an interrupt service routine that performs a prescribed
task
4. Compile C programs to continuous monitor the status of an
ongoing event when microcontroller is processing other
activities.
8
COURSE OBJECTIVES (cnt.)
Upon completion of the course students will be able to
5. Analyze the execution of ADC under different configurations.
6. Select the ADC sampling rate required based on input signal
characteristics.
7. Apply PWM to control DC motor and step motor.
8. Construct a connection between microcontroller and
peripheral devices under various situations.

9
ASSESSMENTS
• Assignments or Quizzes – 30%

• Group Project – 20%

• Final Exam – 50%

10
References
• Programming and Customizing the PIC Microcontroller,
3rd Ed, Mc Graw Hill, 2008.

• PIC Microcontroller Projects in C – Basic to advanced,


Dogan Ibrahim, Newes, 2014

• PIC 18f4550 datasheet


www.microchip.com/1632

• Microchip Webinar
http://www.microchip.com/wwwcategory/Webinarsearch.aspx/WebSemCHome.
aspx

11
Software
• MPLAB X
http://www.microchip.com/pagehandler/en-us/family/mplabx/

• MPLAB XC8 – C compiler


http://www.microchip.com/pagehandler/en-us/devtools/mplabxc/home.html

• Proteus 8 – simulation software

• CCS C Compiler – alternative to MPLAB


http://www.ccsinfo.com/content.php?page=compilers

12
Introduction to Microcontroller
• What can a microcontroller do?
 Pretty much everything as long as you can program it
E.g. control devices (LED, LCD, Motor…), read sensor (light,
temperature, encoder…), control processes, signal processing,…
 Some cool projects using microcontrollers:

Control artificial hand Flying robot Artificial taste


https://backyardbrains.com/experiments/RobotHand

13
AUTOMOBILE

http://libelium.com/es/smart_cars_m2m_accident_prevention

14
Introduction to Microcontroller
• Is microcontroller widely used in Industry?
 Yes, especially in robotics industry
 PLC versus Microcontroller

PLC Microcontroller
• Simple and easy to use • Require knowledge in
• Required less electronics and programming
knowledge • Fast
• Relatively slow • Can implement complex
• Can’t implement algorithm
complex algorithm • Cheap
• Expensive

15
Introduction to Microcontroller

http://www.edn.com/design/systems-design/4398891/Processor-
architectures--the-sweet-spot-spectrum

16
Introduction to Microcontroller
• What microcontrollers available in the market?
 Countless
E.g. Microchip (PIC, dsPIC), AVR (ATMEGA, XMEGA), TI (MSP,
TM), Freescale, ARM (M0, M3, M4), Holtek…
 There is no the best microcontroller.
 Microcontroller changes rapidly, you don't know what could be the
requirement of the product in your future company

http://www.edn.com/design/systems-design/4398891/Processor-
architectures--the-sweet-spot-spectrum
17
Introduction to Microcontroller
• How a microcontroller is made?
 https://www.youtube.com/watch?v=p4vZwycU4Cw
 Microcontroller vs Human

2015 Fastest MCU


A typical firing rate for a
Microchip Atmel S70/E70
neuron is around 100 spikes
can run at 300MHz
per second.
Operation in MCU is Operation in brain is
serial: One after another parallel: 1010 neurons
working simultaniously
strictly follows instructions !?
Microcontroller is very different from Human brain
18
Microcontroller vs Human
• Example: Sort these numbers in ascending order

5 1 6 2 4 3
• Discussion
 How to teach a microcontroller do this job?

19
What is Microcontroller?
Wiki definition:
• a small digital computer on a single integrated circuit
• Contain processor core(s), memory, I/O peripherals
• Programmable

20
How does microcontroller work?

Algorithm

PROBLEMS

Inputs Outputs
MCU

21
How does microcontroller work?
Algorithm

Code
(C / Assembly)
Compiler
List of Instructions

Inputs Outputs
MCU

• Instruction Fetch: get the instruction from memory into the processor
• Decode: decode the instruction to get the operation (what it has to do)
• Execute: Perform the operation
• Store: store the result back into another register
22
Example code in
Assembly

23
Inside a microcontroller

24
Central Processor Unit (CPU)
CPU monitors and controls all
processes within the microcontroller

• Instruction decoder

• Arithmetical Logical Unit (ALU)

• Accumulator

25
Pipelining
• Laundry analogy

Can we make the


whole process faster ?

http://www.ece.arizona.edu/~ece462/Lec03-pipe/

26
Pipelining

Significantly speedup the operation!

http://www.ece.arizona.edu/~ece462/Lec03-pipe/

27
Pipelining

Instruction Pipeline stage


1 IF D EX STR
2 IF D EX STR
3 IF D EX STR
4 IF D EX
5 IF D
Clock cycle 1 2 3 4 5 6

28
INSTRUCTION SET
RISC (Reduced instruction set
computers)
• 1 instruction = 1 operation
• all instructions execute in the same time
• more RAM is needed to store more line of
code
• Require less transistor on processor
• EX:
LOAD A, 2:3
LOAD B, 5:2
PRO A, B
STORE 2:3, A
29
INSTRUCTION SET
CISC (Complex instruction set
computers)
• complex instructions are built directly
into the hardware
• resembles a higher level language
• 1 instruction = many operations
• does not require the programmer to
explicitly call any loading or storing
functions
• More transistor on processor, less
RAM needed
• Ex:
MULT 2:3, 5:2

30
MEMORY
• Nonvolatile program memory
(ROM)
‒ store application software
‒ retain the information stored in
it even when power is removed
• Volatile variable memory
(RAM)
‒ Temporary storage of data
‒ Value will be lost when power is
removed
• Optional nonvolatile data
memory (EEPROM)
31
PROCESSOR ARCHITECTURES
• Von Neumann (Princeton) Computer Architecture

Program & data memory


32
PROCESSOR ARCHITECTURES
• Harvard Computer Architecture

Program memory Data memory


33
PIC18F2455/2550 (28-PIN) BLOCK DIAGRAM

34
Memory Organization

Program memory
35
Instruction in program memory

36
Special Function Register

37
Oscillator

• enable harmonic and synchronous


operation
• program instructions are slower than
oscillator rate

Why do we need oscillator


clock?
http://www.npeducations.com/2013/10/introduction-to-basics-of.html
How can microcontroller
know when an instruction
finish?
38
HOME WORK
• Read chapter 2 “OSCILLATOR CONFIGURATIONS” in
the datasheet and describe the oscillator sources of
PIC18F4550.

39
Microcontroller selection criteria
• Selecting the right microcontroller for a product is an
important task
• Criteria:
• Required hardware interfaces
• Architecture
• Memory needs
• Power constraints
• Availability
• Cost
• Packaging

40
Microcontroller selection criteria
• Required hardware interfaces
• Number of I/O requirements
• Features, communication interfaces
e.g. autonomous robot

Drivers Motors
2 PWM + 2 I/O

Minimum I/O
Encoders Requirements
4 I/O

• 12 I/O
2 I/O Ultrasonic
• 2 PWM
sensor
MCU • 1 UART
UART
Bluetooth
2 I/O 2 I/O

LEDs Buttons
41
Microcontroller selection criteria
• Architecture
• Processing power requirement – MCU speed
• 8 bit or 32 bit MCU?

• Memory needs
• Estimate how much program and data memory will be required

• Power constraints
• Operating voltage
• Power consumption

42
Microcontroller selection criteria
• Availability and cost
• Keep the cost as low as possible
• Select a popular MCU

• Packaging
• DIP or SMD
• Number of pins DIP package SMD package
How to know if a microcontroller meet the
requirements?
– Check the datasheet
– Ask local shops
Check the specification of microcontroller PIC
18F4550? 43
PIC 18F4550 Highlights
• Package: 40-pin DIP or 44-pin QFN (SMD)
• Oscillator: max 48 MHz
• Program memory: 32 KB
• Data memory: 2 KB + 256B EEPROM
• Number of I/O: 35
• ADC: 13 channels, 10-bit resolution
• PWM: 1 output
• Communication interfaces: SPI, I2C, UART, USB
• Timer: 1 x 8-bit timer, 3 x 16-bit timers
• Operating voltage: 2.0V to 5.5V

44
PIC 18F4550 Pin Diagram

45
PIC 18F4550 basic circuit

Reset
Circuit
I/O
Devices

Vdd
Power Voltage MCU
Vss
In Regulator 18F4550

OSC1
Oscillator OSC2

46
Reset Circuit
A Reset is generated by holding the MLCR
pin low.

An example of Reset circuit

47
Voltage regulator
• A voltage regulator is designed to automatically regulate a
constant voltage level.
• How Voltage regulator work:
http://www.analog.com/en/technical-articles/how-voltage-regulator-works.html

Regulator

L4931 AMS1117

7805 MAX603
48
Oscillator
• Oscillator Source: Ceramic
Crystal
capacitor
• Crystal Oscillator
• External Clock Input
• Internal Oscillator

• Crystal Oscillator Crystal Oscillator Circuit


• In this mode, a crystal or
ceramic resonator is
connected to the OSC1 and
OSC2 pins to establish
oscillation

49
Oscillator
• External Clock Input (EC)
• This Oscillator require an external clock source to be connected to
the OSC1 pin.

EXTERNAL CLOCK INPUT OPERATION

50
Oscillator
• Internal Oscillator
The PIC18F4550 device include an internal oscillator block
which generates two different clock signals
• The main output (INTOSC) is an 8 MHz clock source which can be
used to directly drive the device clock.
• the internal RC oscillator (INTRC) which provides a nominal 31 kHz
output.

51
Oscillator

PIC18F4550 CLOCK DIAGRAM 52


53

Das könnte Ihnen auch gefallen