Microprocessors B (17.384) Spring 2013 Lecture...

63
1 Microprocessors B (17.384) Spring 2013 Lecture Outline Class # 10 April 16, 2013 Dohn Bowden

Transcript of Microprocessors B (17.384) Spring 2013 Lecture...

Page 1: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

1

Microprocessors B (17.384)

Spring 2013

Lecture Outline

Class # 10

April 16, 2013

Dohn Bowden

Page 2: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

2

Today’s Lecture

• Administrative

• Microcontroller Hardware and/or Interface– Advanced Hardware Topics

• Programming/Software– Programming Techniques

• Lab

• Homework

Page 3: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

3

Course Admin

Page 4: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

4

Administrative

• Admin for tonight …

– Syllabus Highlights

• Lab #3 due date … Tuesday (April 30th)

• No Lab #4 due to time constraints

• Next class --- Friday April 19th -MAKE-UP Class

– PLEASE let me know WELL PRIOR TO class …» If you will not be in attendance

• Exam #2 … next week (April 23rd)

• May 7th … Course Projects Briefs/Demonstrations/Reports

Page 5: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

5

Syllabus ReviewWeek Date Topics Lab Lab Report Due

1 01/22/13 PIC pin out, General-purpose IO, C programming

2 01/29/13 LED/Switch Input / Output and Power Saving Modes 1

3 02/05/13 Lab 1 con’t

4 02/12/13 Timers, Interrupts, interrupt-driven IO 2

X 02/19/13 No Class – Monday Class Schedule

5 02/26/13 Lab 2 con’t 1

6 03/05/13 Asynchronous/Synchronous Serial IO (UART, I2C, SPI) 3

X 03/12/13 No Class – Spring Break

X 03/19/13 No Class – cancellation due to snow

7 03/26/13 Examination 1

8 04/02/13 Lab 3 con’t 2

9 04/09/13 Pulse Width Modulation and DC motor control 3 con’t

10 04/16/13 Advanced Hardware Topics 4

11 04/19/13 FRIDAY CLASS --- Lab Project

12 04/23/13 Examination 2

13 04/30/13 Work on Course Project Project 3, deleted 4

14 05/07/13 Final Exam/Course Project Brief and Demonstration Demo

Page 6: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Exam #2

• You may utilize any reference materials during the conduct of the Exam …

– Notes– Books– Class Web page material– Etc.

• The exam will conclude promptly at 9:30 PM

6

Page 7: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

7

MicrocontrollerHardwareand / or

Interfaces

Page 8: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

8

Other Features / Peripherals …

Page 9: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

9

Direct memory Access …

Page 10: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Direct memory Access (DMA)

• Direct Memory Access … DMA …

– A feature that allows certain hardware subsystems to access system memory for reading and/or writing independently of the CPU

– Hardware assisted data transfers between memory and peripherals

• Minimal CPU intervention

– Reduces CPU overhead

10

Page 11: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Direct memory Access (DMA)

• Without DMA … using programmed input/output (PIO) mode for communication with peripheral devices …

– The CPU is typically fully occupied for the entire duration of the read or write operation, and is thus unavailable to perform other work

– With DMA … the CPU would initiate the transfer … do other operations while the transfer is in progress … and …

• Receive an interrupt from the DMA controller once the operation has been done

11

Page 12: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

12

I2C …

Page 13: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

PIC24 as an I2C Slave

• The PIC24 can also function as an I2C Slave

– Useful when embedding within a product that requires an I2C interface

13

Page 14: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Bus Arbitration for the I2C Bus

• The I2C bus supports multiple bus masters

– Any I2C device can initiate a transaction

• Therefore there must be a bus arbitration mechanism that decides which device assumes control

14

Page 15: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

15

Controller Area Network …

Page 16: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Controller Area Network (CAN)

• Controller Area Network … CAN …

– Is an half-duplex serial bus designed as a communication mechanism for intelligent peripherals within an automotive system

– An automobile is a harsh environment

• Electrical noise• Electrical systems throughout the vehicle• Communications in meters

16

Page 17: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Controller Area Network (CAN)

• CAN buses …

– Uses only two wires for communications

• Keeps cabling sizes to a minimum

17

Page 18: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

18

Universal Serial Bus …

Page 19: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Universal Serial Bus (USB)

• The Universal Serial Bus … USB …

– High speed serial protocol

• Largely replaced the RS-232

– Some PIC24 microcontrollers has USB interface

• PIC24FJ256GB110 … for example

19

Page 20: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

20

Real-Time Clocks …

Page 21: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Real-Time Clocks

• External

• Internal

21

Page 22: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

22

Analog Interface …

Page 23: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Analog Interface

• Analog to Digital Conversions

• Interfacing with and External ADC

• Comparator Module …– Contains two independent comparators

• Temperature Sensors

• Light Sensors

• Accelerometer

• Pressure Sensors

23

Page 24: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

24

Other Interfaces …

Page 25: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Other Interfaces

• Liquid Crystal Displays

• Touch Screens

• Motors

• Stepper Motors

• Data Loggers

• PC interface

25

Page 26: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

26

Selecting Your Microcontroller …

Page 27: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Product Selector Tool

• Microchip’s Home Page …

– Product Selector Tool …

• Web address

• http://www.microchip.com/maps/main.aspx

• http://www.microchip.com/maps/microcontroller.aspx

27

Page 28: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

28

Page 29: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

29

Page 30: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

30

Page 31: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

31

Programming/Software

Page 32: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

32

Software enhancements …

Page 33: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

33

Assembly Language …

Page 34: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Assembly Language

• PIC24 instruction set defines 71 distinct instructions

• Assembly language is more primitive … operations less powerful … than C

• It can … however … be used when C cannot perform the required task

• Can also embed assembly within C

34

Page 35: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

35

C …

Page 36: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

C

• Pointers and subroutines

• Indirect addressing

• Subroutines

36

Page 37: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

37

Math Routines …

Page 38: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Math Routines

• Multiplication

• Division

• Floating Point Numbers

• Solving equations

38

Page 39: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

39

Optimization Techniques …

Page 40: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Optimization Techniques

• Increase Code Efficiency

• Decreasing Code Size

• Reducing Memory Usage

• Power-Saving Techniques

40

Page 41: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

41

Increasing Code Efficiency …

Page 42: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Increasing Code Efficiency

• Inline functions

• Table lookups

• Hand-coded assembly– Some software modules are best written in assembly language– This gives the programmer an opportunity to make them as

efficient as possible• Though most C compilers produce much better machine code

than the average programmer … – A skilled and experienced assembly programmer might

do better work than the compiler for a given function

42

Page 43: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Increasing Code Efficiency

• Register variables

– The keyword register can be used when declaring local variables …

• This asks the compiler to place the variable into a general-purpose register rather than on the stack

• Global variables

– It is sometimes more efficient to use a global variable than to pass a parameter to a function

43

Page 44: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Increasing Code Efficiency

• Fixed-point arithmetic

– Unless your target platform features a floating-point processor …

• You'll pay a very large penalty for manipulating float data in your program

44

Page 45: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Increasing Code Efficiency

• Variable size

– It is typically best to use the processor's native register width for variables whenever possible … whether it is 8, 16, or 32 bits

– This allows the compiler to produce code that takes advantage of the fast registers built into the processor's machine opcodes

• For example … if you need a count that goes from 0 to 512 … you can't use an 8-bit variable

45

Page 46: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

46

Decreasing Code Size …

Page 47: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Decreasing Code Size

• Avoid standard library routines

– Avoid using large standard library routines

• They try to handle all possible cases

• It might be possible to implement a subset of the functionality yourself with significantly less code

47

Page 48: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Decreasing Code Size

• Use goto statements

– Good software engineering practice dictates against the use of this technique … But …

• In a pinch …goto statements …

– Can be used to remove complicated control structures

48

Page 49: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

49

Power-Saving Techniques …

Page 50: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Power-Saving Techniques

• A major concern in battery-powered embedded systems design is power consumption

• There are several methods to conserve power in an embedded system … including …

– Clock control– Power-sensitive processors– Low-voltage ICs

• Some power-saving techniques are under software control.

50

Page 51: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Power-Saving Techniques

• It might seem ideal to select the fastest and most powerful processor available for a particular embedded system …

– However, one of the tasks of the hardware designer is to use …

• Just enough processing power to enable the device to get its job done

– This helps reduce the power consumed by the device

51

Page 52: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Power-Saving Techniques

• Processor Modes

• Clock Frequency

– Reduce the clock speed to save power during the execution of noncritical tasks … and …

– Increase the clock speed when processing demands are high

52

Page 53: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

53

Lab

Page 54: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

54

Peer Review of Software …

Page 55: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Peer Review of Software Developed

• How did you write your code?

• What problems did you encountered?

• Any questions that you need resolved?

55

Page 56: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

56

Next Class

Page 57: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

57

Next Class Topics

• Next class --- Friday April 19th -MAKE-UP Class

– PLEASE let me know WELL PRIOR TO class …• If you will not be in attendance

• April 23rd … Exam #2 … no lecture or lab scheduled

• April 30th … Work on projects

• May 7th … Course Projects Briefs/Demonstrations/Reports

Page 58: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

58

Homework

Page 59: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Homework

• Study for exam #2 … next week … April 23rd

• Labs …– Lab #3 Report … due April 30th

– Lab #4 … no report required … lab is for your information only

59

Page 60: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

60

Time to start the lab …

Page 61: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

Lab

• Finish up Lab #3

• Work on Course Projects

61

Page 62: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

62

References

Page 63: Microprocessors B (17.384) Spring 2013 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2013_Spring_DPAN/17-384/Ref...• Interfacing with and External ADC ... – Some software modules

63

References

1. None