Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Similar documents
MicroProcessor. MicroProcessor. MicroProcessor. MicroProcessor

ME 515 Mechatronics. A microprocessor

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Lecture (04) PIC 16F84A programming I

3. The MC6802 MICROPROCESSOR

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

ECE 372 Microcontroller Design

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Laboratory 10. Programming a PIC Microcontroller - Part II

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 1.

Flow Charts and Assembler Programs

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

Lecture (02) PIC16F84 (I)

Laboratory: Introduction to Mechatronics

Lecture (03) PIC16F84 (2)

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

MT2 Introduction Embedded Systems. MT2.1 Mechatronic systems

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

PIC 16F84A programming (II)

Professor E. Ambikairajah UNSW Sydney

8051 Microcontroller

Bolt 18F2550 System Hardware Manual

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

ELCT708 MicroLab Session #1 Introduction to Embedded Systems and Microcontrollers. Eng. Salma Hesham

MICROPROCESSOR AND MICROCONTROLLER BASED SYSTEMS

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

Robotic Systems ECE 401RB Fall 2006

PIC Microcontroller Introduction

Microcontroller Overview

DS1682 Total-Elapsed-Time Recorder with Alarm

Locktronics PICmicro getting started guide

Figure 1.1: Some embedded device. In this course we shall learn microcontroller and FPGA based embedded system.

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Input/Output Ports and Interfacing

8051 Microcontroller Interrupts

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Department of Electronics and Instrumentation Engineering Question Bank

CSE 466 Exam 1 Winter, 2010

Computer Hardware Requirements for Real-Time Applications

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Microcomputer Architecture and Programming

Microcontroller basics

DS WIRE INTERFACE 11 DECOUPLING CAP GND

EasyPIC5 Development System

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

SH69P55A EVB. Application Note for SH69P55A EVB SH69P55A EVB SH69V55A

PIC DESIGN (version 1) 2/11/2009

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

BL24C02/BL24C04/BL24C08/BL24C16

eip-10 Embedded TCP/IP 10-BaseT Network Module Features Description Applications

Microprocessors/Microcontrollers

Introduction to general architectures of 8 and 16 bit micro-processor and micro-controllers

Summer 2003 Lecture 18 07/09/03

DS1306. Serial Alarm Real Time Clock (RTC)

Address connections Data connections Selection connections

Laboratory 9. Programming a PIC Microcontroller - Part I

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Embedded Systems and Software

How to Implement I 2 C Serial Communication Using Intel MCS-51 Microcontrollers

CONNECT TO THE PIC. A Simple Development Board

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

Lecture (01) Introducing Embedded Systems and the Microcontrollers By: Dr. Ahmed ElShafee

Learning Objectives:

Introduction to Microcontrollers

CORRIGENDUM ISSUED FOR NATIONAL COMPETITIVE BIDDING UNDER TEQIP PHASE-II

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Figure 1: Pushbutton without Pull-up.

C H A P T E R 1 INTRODUCTION

DEV-1 HamStack Development Board

_ V Intel 8085 Family In-Circuit Emulation. Contents. Technical Notes

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

PROGRAMMABLE POWER SUPPLY

Chapter 1: Basics of Microprocessor [08 M]

512K bitstwo-wire Serial EEPROM

SH69P48A EVB. Application Notes for SH69P48A EVB SH69V48A JP2 J4(ICE_J4) S1 IDD TEST JP1 74HC273 JP4 JP3 74HC273 JP6 STKOVE JP7 SW1 J5(ICE_J5)

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

Microprocessors and Microcontrollers Prof. Santanu Chattopadhyay Department of E & EC Engineering Indian Institute of Technology, Kharagpur

EEE111A/B Microprocessors

EMBEDDED SYSTEMS COURSE CURRICULUM


DS2401 Silicon Serial Number

CREATED BY M BILAL & Arslan Ahmad Shaad Visit:

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Chapter 11: Interrupt On Change

ME 6405 Introduction to Mechatronics

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

POWER SAVER METER USING MICROCONTROLLER TO SAVE ELECTRICITY UPTO 30-40%

Z8 Encore! XP F1680 Series 8-Bit Flash Solution with Extended Peripherals

Introduction to 8051 microcontrollers

DS2223/DS2224. EconoRAM FEATURES PACKAGE OUTLINE. PIN CONNECTIONS Pin 1 GND Ground Pin 2 DQ Data In/Out Pin 3 V CC Supply Pin 4 GND Ground

Clear code memory to all ones. The successful operation of this function is not automatically verified. Program from File

Transcription:

Mechatronics and Measurement Lecturer:Dung-An Wang Lecture 6

Lecture outline Reading:Ch7 of text Today s lecture: Microcontroller 2

7.1 MICROPROCESSORS Hardware solution: consists of a selection of specific ICs, which when hardwired on a circuit board, carry out predefined functions. Software solution: consisting of a set of instructions to execute logic and arithmetic functions and to access input signals and control output signals. A microprocessor is a single, very-large-scaleintegration (VLSI) chip that contains many digital circuits that perform arithmetic, logic, communication, and control functions. 3

4

The instructions that can be executed by the CPU are defined by a binary code called machine code. The instructions and corresponding codes are microprocessor dependent. Microprocessors can be programmed using assembly language, which has a mnemonic command corresponding to each instruction (e.g., ADD to add a number to a register and MOV to move a register s value to a memory location). Assembly language must be converted to machine code, using software called an assembler, before it can be executed on the microprocessor. 5

7.2 MICROCONTROLLERS 6

7.3 THE PIC16F84 MICROCONTROLLER 7

The PIC16F84 is an 8-bit CMOS microcontroller with 1792 bytes of flash EEPROM program memory, 68 bytes of RAM data memory, and 64 bytes of nonvolatile EEPROM data memory. The 1792 bytes of program memory are subdivided into 14-bit words, because machine code instructions are 14 bits wide. Therefore, the EEPROM can hold up to 1024 (1 k) instructions. With a clock speed of 4 MHz, an instruction is executed every microsecond and 1 million instructions can be executed every second. The microcontroller is referred to as 8-bit, because the data bus is 8 bits wide, and all data processing and storage and retrieval occur using bytes. 8

The PIC16F84 can be driven at a clock speed up to 10 MHz but is typically driven at 4 MHz. PORTA: RA0-RA4 PRRTB: RB0-RB7 13 I/O lines : bidirectional 9

Active low: pull them down to reset the IC, grounding this pin causes the PIC to reset and restart the program stored in EEPROM. 10

This pin (pin 4) must be held high during normal program execution. This is accomplished with the pullup resistor. The PIC clock frequency can be controlled using different methods, including an external RC circuit, an external clock source, or a clock crystal. The use of a clock crystal to provide an accurate and stable clock frequency at relatively low cost. The clock frequency is set by connecting a 4-MHz crystal across the OSC1 and OSC2 pins with the 22 pf capacitors grounded 11

The value for capacitors C1 and C2 must be chosen so that the series combination: (C1*C2) / (C1+C2) gives a value close to the load capacitance, CL, specified by the crystal manufacturer. From the crystal's point of view, C1 and C2 are in series, so the total that the crystal sees is 11 pf. Stray capacitance and input capacitance on the pins may account for 8-10 pf. Cl = ((C1 * C2) / (C1 + C2)) + Cs Where Cl is load capacitance, C1 and C2 are the capacitor values, and Cs is the stray capacitance of the board. the crystal is designed for a 20pf load capacitance 12

Decoupling capacitor (0.1 µf) Power supplies are slow...they take roughly 10 us to respond (i.e. bandwidth up to 100 khz). So when your big, bad, multi-mhz microcontroller switches a bunch of outputs from high to low, it will draw charge from the power supply (current draw), causing the voltage to start drooping until it realizes (10 us later!) that it needs to do something to correct the drooping voltage. When you draw high currents from your power supply (like when digital logic switches state) you will see a change in supply voltage. Switching tries to draw large instantaneous currents and produces a voltage drop due to the impedance of the voltage source and the connection between the voltage source and the IC. A decoupling capacitor will help to maintain the supply voltage at the device. Placing this storage element close to the IC reduces the change in voltage at the IC. 13

To compensate for slow power supplies, we use decoupling capacitors. Decoupling capacitors add fast "charge storage" near the IC. So when your micro switches the outputs, instead of drawing charge from the power supply, it will first draw from the capacitors. This will buy the power supply some time to adjust to the changing demands. The "speed" of capacitors varies. Basically, smaller capacitors are faster; inductance tends to be the limiting factor, which is why everyone recommends putting the caps as close as possible to VCC/GND with the shortest, widest leads that are practical. So pick the largest capacitance in the smallest package, and they will provide the most charge as fast as possible. 14

7.4 PROGRAMMING A PIC To use a microcontroller in mechatronic system design, software must be written, tested, and stored in the ROM of the microcontroller. Usually, the software is written and compiled using a personal computer (PC) and then downloaded to the microcontroller ROM as machine code. If the program is written in assembly language, the PC must have software called a cross-assembler that generates machine code for the microcontroller. 15

16

17

Assembly Language Instruction Details 18

19

20

21

22

The first four active lines ( list... target ) are assembler directives that designate the processor and define constants that can be used in the remaining code. Defining constants (with the equ directive) Assemblylanguage constants such as addresses and values are written in hexadecimal, denoted with a 0x prefix. 23

movlw, move the literal constant target into the W register and then from the W register into the count address location in memory. The target value (0x05) will be decremented until it reaches 0x00 24

initializes the special function registers PORTA and TRISA to allow output to pins RA0 and RA1, which drive the LEDs. These registers are located in different banks of memory, hence the need for the bsf and bcf statements in the program. All capitalized words in the program are constant addresses or values predefined in the processordependent include file (p16f84.inc). The function of the TRISA register is discussed more later; but by clearing the bits in the register, the PORTA pins are configured as outputs. 25

26

Flowcode High-level language compilers are available that allow us to program a PIC at a more user-friendly level 27

Lab 9 wiring circuits to a PIC entering and compiling flowcode programs downloading executable code from a PC to the flash memory on the PIC. 28

Example Program to turn on an LED every time a pushbutton switch is pressed, and turn on a second LED once it has been pressed a specified number of times 29

Design ex 7.1 Drive the seven LED segments directly from seven output pins of a PIC Input a number in program and run your program. 30

Design ex 7.1 An alternative design that requires fewer output pins uses a seven-segment decoder IC (e.g., 7447). Here, only four I/O pins are required. 31

Lab 10 32

7.6 USING INTERRUPTS Polling: program includes a check of the sensor inputs within a loop to update the output accordingly Interrupt: some inputs are connected to special input lines, designated as interrupts. When one or more of these lines changes level, the microcontroller temporarily suspends normal program execution while the change is acted on by a subprogram or function called an interrupt service routine. At the end of the service routine, control is returned to the main program at the point where the interrupt occurred 33

Example This program turns on an LED and waits for an interrupt on PORTB.0. When RB0 changes state, the program turns the LED off for 0.5 seconds and then resumes normal execution. 34

Program flow (Lab 9) 35

7.7 INTERFACING PIC PERIPHERALS 36

7.7.2 LCD Display 37

38

Threaded design ex C.2 EDE1144 keypad decoder is used to monitor keypresses on the keypad and transmit them to the PIC via a serial interface. 39

40

7.9 METHOD TO DESIGN A MICROCONTROLLER-BASED SYSTEM 1. Define the problem 2. Draw a functional diagram 3. Identify I/O requirements 4. Select appropriate microcontroller models 5. Identify necessary interface circuits 6. Decide on a programming language 7. Draw the schematic 8. Draw a program flowchart 9. Write the code 10. Build and test the system 41

DESIGN EXAMPLE 7.2 PIC Solution to an Actuated Security Device 42

43

44

45

46

47

48

49

50

Design Example Power amp motor driver controlled by a potentiometer A potentiometer is attached to an A/D input in the PIC. The PIC outputs the corresponding voltage as a digital word to a TI TLC7524 external D/A converter, which is attached to a TI OPA547 power-op-amp circuit. The amplifier circuit can provide up to 500 ma of current to a DC motor (e.g., R179-6V-ENC-MOTOR) 51

52

53

DC motor position and speed controller 54

55

Lab 10 Lab 11 56