Mechatronics WIB

Embed Size (px)

Citation preview

  • 8/2/2019 Mechatronics WIB

    1/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 1

    MechatronicsWorkshop-in-a-Box

    Welcome Everybody

    (If you are presenting this Workshop to a group of people, the Presenter Notes initalics contain special instructions or information for you).

    Dear Presenter,

    We are pleased that you are taking the time to teach this WIB to others. AtMicrochip Technology we are excited about the abundant opportunities forincorporating PICmicrocontrollers into mechanical applications. Thank you for

    joining us in introducing others to this exciting technological frontier.

    The following presentation includes speaker notes that you can refer to during yourpresentation. Please pay special attention to the TRANSISTION sentences called

    out at the end of many of the slide notes. Using these transition sentences willallow the presentation to flow much smoother.

    We hope you enjoy teaching the class as much as we enjoyed creating it. Have funwith it!

  • 8/2/2019 Mechatronics WIB

    2/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 2

    When you walk out of here todayyou will know

    Why designing a PICmicrocontroller into a

    mechanical system is beneficial to you

    How easyit is to get started with Microchipand PICmicrocontrollers

    How to use Microchips low-cost tools tochange, adaptand add featuresto a design

    How to perform basic mechatronic tasksusing a PICmicrocontroller

    The purpose of the slide is to peak the audiences curiosity. Start off early with whatthey will learn today.

    There must be a compelling reason for the audience to want to migrate from amechanical to a mechatronic solution. Well take a look at the benefits ofMechatronics at the beginning of this lecture.

    We will show you how easy it is to get started with Microchips products withminimal financial and time investment.

    The reality is that for any engineering project, the requirements will change.Those darn Marketing folks can never make up their mind and will always wantsomething else halfway through the project. One of the biggest advantages ofMicrochips products is that we offer you a wealth of options and make it easy foryou to change and adapt to changing requirements. The consistency in tools andproducts allow you to add features without starting over every time things change.

    This is a workshop so that means you get to play! During a large part of this classyou will be working on labs that will show you how to make a PIC microcontrollerdo simple tasks.

  • 8/2/2019 Mechatronics WIB

    3/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 3

    Agenda

    Introduction to Microchip Technology Inc.

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Go through the basic agenda. There will be a break in the middle

  • 8/2/2019 Mechatronics WIB

    4/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 4

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Lets first take a brief look at who Microchip is and what products they make.

  • 8/2/2019 Mechatronics WIB

    5/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 5

    Microchip Technology Inc.

    Leading semiconductor manufacturer:- of high-performance, field-programmable, 8-bit &

    16-bit RISC Microcontrollers

    - of Analog & Interface products

    - of related Memory products

    - for high-volume Embedded Control applications

    $847M in net sales in FY05

    More than 3,800 employees

    #1 Unit shipments of 8-bit Microcontrollers*

    * Gartner Dataquest, 2003 Microcontroller Market Share & Unit Shipments, Tom Starnes, June 2003.

    Introduce Microchip Technology Ask Who knows Microchip?

    Microchip entered this 8-bit microcontroller market back in 1990 as avirtually unknown company, with a non-standard product architecture andin a market crowded by the worlds largest competitors in the U.S., Europe,Asia and Japan.

    1990 rank of #20 achieved with a handful of products. Company was stillprivate until March 1993.

    Our market share has gone up every year. We are currently at the #2position, behind the long term industry leader Motorola.

    I would say that such marketshare gains have never been accomplished ina highly competitive field of well entrenched competitors. And while doingthis, we have not lost money in a single quarter in the last 12 years, noteven in the recessionary years of 1991, 1996, 1998 and 2001.

    Currently #1 supplier of 8-bit Microcontrollers in the world by Units shipped

    Most important aspect:

    Microchip has had phenomenal growth over the last 15 years.

    We grow because customers buy our products We have no internal consumption

    People buy our products, because it makes them successful in business If ourcustomers are not successful, we are not successful.

    Transition Question: Lead in to next slide is asking How do we do it? Why dopeople buy our products?

  • 8/2/2019 Mechatronics WIB

    6/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 6

    Microchip Delivers Solutions

    Low-risk product development

    Lower total system cost

    Faster time to market

    Dependable delivery

    High-quality devices

    Outstanding support through all phases

    Risk free development environmentSeamless Flash program size expansion -Allows for product feature changes without loss of

    work already completed

    Pinout compatibility - Consistent by package, Similar throughout

    Software development environment consistency

    Proven Libraries, reference designs and application notes

    Lower total system solution costAppropriate level of integration - From simple digital to high level of analog on board

    Vast array of hardware and software peripherals

    Lower cost of ownership - System level development assistance and optimization

    Faster time to marketOne consistent hardware and software development environment

    Seamless migration allows for no lost time due to end product feature creep

    All platform technologies available from one source - Micro, Analog, Memory, RF

    Dependable delivery

    Consistently short lead times

    High-Quality

    Decade+ of product lifetime, In house manufacturing, World class quality, QS9000 - Best in classFlash reliability - Customer recognized quality

    Outstanding SupportProven Libraries, reference designs and application notes - 25 technical support centers worldwide

    Global, real-time technical phone and e-mail support - Free On-line product samples

    Worldwide MASTERS conferences - Technical seminars - Web based technical support

    Highly consultative sales team

  • 8/2/2019 Mechatronics WIB

    7/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 7

    High Performance10 MIPs, Up to 64k

    Instructions, 18-84 pins

    Baseline5 MIPs, up to 2k

    Instructions, 6-40 pins

    The PICMicrocontroller Family

    Pins

    Memory(kBytes)

    6 8 14 18 28 40 64 84

    1

    256

    128

    64

    32

    16

    8

    4

    2

    Mid-Range5 MIPs, Up to 8k

    Instructions, 8-64 pins

    dsPICDigital Signal Controller (DSC)

    30 MIPs, Up to 48kInstructions, 18-84 pins

    Microchips PIC microcontroller family currently consist of 4 Families or Architectures

    Baseline

    Mid-Range

    High Performance

    dsPIC digital signal controllers

    Baseline Products

    12-bit Instruction set covering 6-40-Pin and up to 3kByte Program Memory or 2k Instructions Up to 5 MIPS Performance

    Basic Peripheral set including comparators and A/D

    Mid-Range Products

    14-bit Instruction set covering 8-64-Pin and up to 14kByte Program Memory or 8k Instructions

    Up to 5 MIPS Performance

    More Advanced Peripheral set including Serial Communications, Capture/Compare/PWM, LCD, EEPROM, 10-bit A/D

    Part numbers begin with PIC12, PIC16

    High Performance Products

    16-bit Instruction set covering 18-84-Pin and up to 128kByte Program Memory or 64k Instructions

    Up to 10 MIPS Performance with hardware multiply

    Very Advanced Peripheral set including Advanced Serial Communications (CAN, USB), Capture/Compare/PWM, LCD,EEPROM, 10-bit A/D

    dsPIC 16-bit Digital Signal Controller Products

    24-bit Instruction set covering 18-84-Pin and up to 144kByte Program Memory

    Up to 30 MIPS Performance with Digital Signal Processing Capability

    Very Advanced 16-bit Peripheral set including Motor Control, Faster A/D, Serial Communications

    Extensive Software Library available

    Point to overlap that allows for migration between different families

  • 8/2/2019 Mechatronics WIB

    8/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 8

    Migration between Different ProductsExample: Mid-Range Parts

    Pin Compatible

    within specificpinouts

    Code Compatible

    PeripheralConsistency

    8-P

    in

    14-P

    in

    VDD

    RA5

    RA4

    RA3

    VSS

    RA0

    RA1

    RA2

    RC0

    RC1

    RC2RC3

    RC4

    RC5

    RB4

    RB5

    RB6RB7

    RC7

    RC6

    20-P

    in

    Seamless Migrationacross more than

    200 Products

    Many of the new microcontrollers in the Baseline and Mid-Range families allow youto easily migrate between devices with different number of pins. This means if youstart development with one part, and the requirements for your project changeduring development or between product revisions, you can easily change to a partthat meets your new requirements. This slide shows the migration from 8 to 14 to

    20 pins in Microchips Mid-Range family. As you can see the I/O pins and powerand ground pins are consistent throughout.

  • 8/2/2019 Mechatronics WIB

    9/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 9

    Complete Signal Chain Solutionsfrom Microchip

    Performance:Low Power, High Precision

    Low Cost:System Cost, Low Component count

    Size:Small Packaging SC70, SOT23, DFN

    SensorOpAmp

    Ref

    Mux Filter

    Digital

    Pot

    A/DPIC

    microcontroller

    Microchip makes more that just PIC Microcontrollers. Microchip offers a wholerange of products in the signal chain that offer:

    High performance - our op amp performance (GBWP) to current consumptionratio is industry-leading (as good or better than the more well-known analogsuppliers)

    Low Cost Low component count, high integration - The PGA and Digitalpotentiometers are a good example

    In very small packages - examples include LDOs, op amps, comparators,supervisors, etc. in SC-70 (~1/2 the size of SOT-23), 12-bit ADCs in SOT23, 2LDOs + 1 supervisor in one MSOP package, etc.

  • 8/2/2019 Mechatronics WIB

    10/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 10

    Linear Regulators CAN Peripherals

    Fan Speed ControllersFan Fault Detectors

    SwitchingRegulators/Controllers

    Charge PumpDC/DC Converters

    SAR/Delta-SigmaA/D Converters

    VoltageReferences

    Display A/DConverters

    CPU/SystemSupervisors

    SystemD/A Converters

    Voltage Detectors

    Power MOSFETDrivers

    Battery Management

    PowerManagement

    ThermalManagement

    MixedSignal

    InterfaceProducts

    V/F and F/VConverters

    Digital Potentiometers

    TemperatureSensors

    Dual Slope A/DConverters

    Infrared Peripherals

    Single SupplyCMOS Op Amps

    Comparators

    LinearProducts

    Linear Integrated

    Devices

    LIN Transceivers

    Serial Peripherals

    Programmable GainAmplifiers

    Analog & Interface Products

    PWM Controller

    Shown here are the 5 major product lines in Microchip's stand-alone analogportfolio. They are Power Management, Thermal Management, Linear,Mixed-Signal, and Interface products. The main attribute of these productlines is their excellent performance while focusing on low power (low voltage,low current consumption).

  • 8/2/2019 Mechatronics WIB

    11/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 11

    Overview of Memory Products

    MicrochipSerial

    EEPROMProducts

    Wide

    OperatingVoltage

    1.8V 5.5V

    HighEndurance

    1M Erase/WriteCycles

    SupportsMajor Busses

    Microwire,I2C,SPI

    High Density128 1 Mbits

    SmallPackaging

    DFN, SOT-23TSSOP,MSOP

    Microchip also offers exceptional memory products

  • 8/2/2019 Mechatronics WIB

    12/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 12

    Proven Quality Record across allProduct Families

    ISO9001 Certification

    QS9000 Certification

    Quality Awards fromnumerous Fortune 100customers

    PPM levels consistentlybelow 10

    Field Failures for

    PICmicrocontrollersvirtually non-existent

    Accolades from customers for quality.

    Microchip engages the automotive business.

    DNV comes annually to audit Microchip for quality

    We are in the process of qualifying for the TS16949 certification and expect

    to finalize the audit process in August of this year (CY2003)

  • 8/2/2019 Mechatronics WIB

    13/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 13

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Now we are going to talk a little about mechatronics and how it benefits you.

    Pose Question: What is Mechatronics?

  • 8/2/2019 Mechatronics WIB

    14/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 14

    Mechatronics is:

    Implementingelectronic controls in amechanical system

    Enhancingexisting mechanical designs withintelligent controls

    Replacingmechanical components with anelectronic solution

    A perfect system for a PIC

    microcontroller!!

    Mechatronics can be defined in several ways.

    Mechatronics is implementing electronic control in a mechanical system. Acomputer controlled irrigation valve would be an example of this.

    Second, mechatronics refers to enhancing existing mechanical designs with

    intelligent controls. An example of this would be the power seats in a high endcar. The car remembers the preferred position of the seats for a given key fob.

    Third, mechatronics is also replacing mechanical components with an electronicsolution. The thermometer you have at home for taking a childs temperature isand example of this. The old mercury thermometers have been replaced with anelectronic solution.

    TRANSITION: In order to grasp in more detail what Mechatronics is and whymechatronics benefits you as both a consumer and a manufacturer, we will takea look a three examples in the next few slides.

  • 8/2/2019 Mechatronics WIB

    15/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 15

    Example 1: Flashlight Switch

    Traditional Flashlight: On or Off

    Hybrid Flashlights: Mode selector

    LEDs

    Xenon Bulb

    The first example we will be looking at is a flashlight switch.

    In the traditional flashlight, the switch either slides or is pushed. Contact is beingphysically broken and made to turn the flashlight off and on.

    Many new flashlight are hybrids with a xenon bulb for bright spotting applicationsand white LEDs for a longer-lasting flood light. The switch in these flashlights istypically a tactile switch integrated with a microcontroller that acts as a modeselector.

  • 8/2/2019 Mechatronics WIB

    16/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 16

    Intelligent Switch

    Modes:

    Xenon bulb on

    LEDs on (dim)

    LEDs on (bright)

    PICMicrocontrollerPush Button/

    Tactile Switch

    Xenon

    Bulb

    LED

    Strobe LEDs

    Flashlight off

    A microcontroller switches on the different lighting elements based on the mode ofthe system. This slide shows some of the possible modes:

    1. Turn on the xenon bulb

    2. Turn on the LEDs at half power

    3. Turn on the LEDs at full power4. Strobe the LEDs for to indicate an emergency situation

    5. Turn off the flashlight

    Other possible advanced features:

    The microcontroller can do things like sequence through the modes when the buttonin pressed in rapid succession. After a mode is selected and has been used awhile the next button press results in the flashlight turning off. The switch canremember the users favorite position an default to that when the flashlight is first

    turned on. As you can see the design is very flexible! The same switch can beprogrammed to do any number of things.

  • 8/2/2019 Mechatronics WIB

    17/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 17

    Switch Comparison

    YES!NO!Adaptable

    YesNoStrobe Capable

    YesNoLow BatteryDetect

    YesNoProgrammable

    YesNoCurrent Control

    YesNoHybrid Control

    IntelligentMechanical

    Here is a comparison between the mechanical and intelligent switch. Clearly thebiggest advantage to the Intelligent switch is that it is adaptable. Changing thefirmware in the microcontroller can make the same hardware do something elseentirely. This flexibility also allows you as the manufacturer add features andoptions that will make your product stand out on the shelf when the consumer is

    looking at a row of similar products.

  • 8/2/2019 Mechatronics WIB

    18/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 18

    Possible Solution: PIC10F20x

    SOT-23 package 6 pins:

    - 3 Input/Output pins- 1 Input only- 1 Power, 1 Ground

    4 MHz internal oscillator- 2% accuracy over voltage and

    temperature

    one analog comparator- internal voltage reference

    Ultra-low sleep current

    8-bit timer 2V to 5V operating range

    Actual Size

    So what microcontroller would be a good candidate for a design like this. Microchiprecently introduced the worlds smallest microcontroller the 6-pin PIC10F20xfamily. These parts are small really small. The PIC10F20x parts are enclosed ina SOT-23 package, include a 4Mhz internal oscillator, and have an onboardcomparator.

  • 8/2/2019 Mechatronics WIB

    19/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 19

    Example 2:Household Thermostat

    The next example Ill be discussing in detail is the household thermostat.You may have now, or had growing up, the mechanical thermostat on theleft. Modern thermostats are an excellent example of mechatronics. Thesethermostats perform the same job of the mechanical thermostat but offermany advantages over its predecessor.

    In the next few slides were going to dissect each of these thermostats andtalk about the process of migrating from the mechanical solution to themechatronic solution.

  • 8/2/2019 Mechatronics WIB

    20/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 20

    Example Application:Thermostat

    6070

    80

    50

    40

    DesiredTemperature

    CurrentTemperature

    Dial

    To HeatingUnit

    60

    70

    80

    50

    40

    Heres a look a the mechanical thermostat. The thermostat allows the userto set the desired temperature by turning a dial. The current temperature ofthe room is fed back to the user by a thermometer of some kind.

  • 8/2/2019 Mechatronics WIB

    21/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 21

    Example Application:Thermostat

    6070

    80

    50

    40

    DesiredTemperature

    CurrentTemperature

    To HeatingUnit

    60

    70

    80

    50

    40

    Sensor/Switch

    If we remove the dial we find a metal coil. This coil expands and contractswith temperature it is the temperature sensor for this system. The coilmakes contact with a switch that turns the heating unit on and off.

    Disadvantages:

    The thermostat has to be calibrated at the factory. Even after beingcalibrated the unit typically has plus/minus two or three degrees of error.

    The resolution of the dial is very poor its user is essentiallyguesstimating what temperature he or she is setting the dial to.

    Toxic materials, such as mercury, are used to make the thermostat.

    The only way for a user to change the temperature of the room is to walkover to the thermostat and turn the dial. No programmability on theusers part is available.

    If we were going to design a mechatronic version of this thermostat howwould we go about doing that? I propose we first break the thermostatdown into its components at the system level.

  • 8/2/2019 Mechatronics WIB

    22/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 22

    Breakdown of Thermostat

    TemperatureSensor

    Switch toturn on Heater

    User Input

    60

    70

    80

    50

    40

    User Feedback

    User Feedback60

    70

    80

    50

    40

    Heres a breakdown of the thermostat. There are several sources of userfeedback. First, the dial position tells the user what the desired temperaturesetpoint is. Secondly, the current temperature is conveyed to the user bythe thermometer. User inputs are introduced to the system by the turning ofthe dial. Temperature information for the system is gathered by the

    mechanical coil. Finally, the output from the system, namely, turning on andoff the heater, is handled by the thermal switch.

    In our mechatronic solution we would like to eliminate some of thedisadvantages discussed in the previous slide. This will mean replacingthese components. So what are some of the electronic equivalents of thesecomponents?

  • 8/2/2019 Mechatronics WIB

    23/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 23

    Conversion to Mechatronic Design

    User FeedbackLCD

    TemperatureSensor

    Small IC

    Control

    PICMicrocontroller

    User InputTactile Switches

    Switch toturn on Heater

    MOSFET

    Power

    Regulator

    Here they are. In the mechatronic solution, feedback to the user, both thedesired temperature and current temperature, can be displayed on an LiquidCrystal Display (or LCD).

    Temperature information can be gathered from a solid-state temperaturesensor. Here, weve chosen small IC temperature sensor that varies itsanalog voltage output proportional to temperature. A microcontroller with a10-bit ADC can interpret this voltage into tenths of degrees. This is muchhigher precision than the mechanical thermostat.

    A MOSFET, controlled by the microcontroller, will switch the heater on anoff.

    User inputs are entered into the system using several tactile switches. Moreswitches can be added for increased functionally. For a direct comparison,Im just showing the two switches.

    At the center of the system is a microcontroller. Its job is read user inputs

    from the tactile switches and gather temperature information from thetemperature sensor. This information is then displayed on the LCD as thedesired temperature and the current temperature. This same information isinterpreted by the microcontroller into an output to the MOSFET.

    One other component remains. A regulator is needed to provide theappropriate DC voltage to the microcontroller, LCD, and temperature sensor.

  • 8/2/2019 Mechatronics WIB

    24/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 24

    Finished Design

    DesiredDesiredTemperatureTemperature

    CurrentCurrentTemperatureTemperature

    74oF 70oF

    Higher resolution and accuracy

    Reduces household heating costs

    Self calibrating Flexible Design

    Environmentally Friendly

    Heres the finished product!

    Benefits:

    This solution will provide higher accuracy due to the precision of the

    temperature sensor and A/D converter on the PIC microcontroller. The unit can offer a feature that will allow the user to program the unit to

    automatically lower the temperature setpoint when he or she is awayduring the day. This offers significant energy savings to the user.

    The microcontroller can automatically calibrate the sensor input, saving themanufacturer valuable time during the manufacturing process. One ofbiggest benefits to the manufacturer is that the design is very flexible.Changes to the design can be made by simply reprogramming themicrocontroller. This avoids costly design changes should the designparameters change at some point. In addition, the same hardware can be

    used for models that are produced for countries that use degrees Celsiusor degrees Fahrenheit.

    The mechatronic design is environmentally friendly as it does not employthe use of hazardous materials in its makeup.

  • 8/2/2019 Mechatronics WIB

    25/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 25

    Possible Solution: PIC16F917

    10-bitADC

    LCDModule

    Internal

    Oscillator

    FLASH

    CCPs

    AUSART

    EEPROM

    I2C/SSP

    Comp-

    arators

    PIC16F917

    A suggested PIC microcontroller product for this type of application is thePIC16F91x family of parts. Some key features for these parts are:

    Drive up to 98 LCD segments

    8 MHz internal oscillator

    1 or 2 PWM modules Flash program memory (reprogrammable)

    Wider operating voltage range: 2V - 5.5V

    We will be using the PIC16F917 during the Labs in this class.

  • 8/2/2019 Mechatronics WIB

    26/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 26

    Temperature Sensing Optionsfrom Microchip

    Logic Output

    TC6501/2/3/4

    Voltage Output Serial Output

    TC620/1/2/3/4

    TC1046

    TC1047/47A

    TC72

    TC77

    TC74

    TCN75A

    SPI

    MCP9800/1/2/3

    MCP9700/1

    TemperatureSensors

    SMBus/I2C

    Microchip also offers an assortment of temperature sensors. These sensorscan be interfaced to a PIC microcontroller in a number of ways:

    The first is a logic output You can use a standard I/O to interface to thistemp sensors. Logic output temp sensors are 'temp switches'. Theyprovide a logic output (like a fault indication) when an event is detected

    The second is a voltage output. This can be digitized with a A/D typicallyfound on a microcontroller This is the temperature sensor found on yourPICDEM Mechatronics Board in the upper left-hand corner

    The last way is to have a Serial Output temp sensor Here you can readthe temperature value though SMBUS, I2C or SPI.

  • 8/2/2019 Mechatronics WIB

    27/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 27

    Temperature Sensing Optionsfrom Microchip

    Logic Output

    TC6501/2/3/4

    Voltage Output Serial Output

    TC620/1/2/3/4

    TC1046

    TC1047/47A

    TC72

    TC77

    TC74

    TCN75A

    SPI

    MCP9800/1/2/3

    MCP9700/1

    TemperatureSensors

    SMBus/I2C

    Lets take a look at the TC1047A for a moment as this is the temperaturesensor used on the PICDEM Mechatronics board.

  • 8/2/2019 Mechatronics WIB

    28/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 28

    Linear OutputTC1047A Temperature Sensor

    Linear Slope

    - 10 mV/C

    -40 to 125CTemperatureRange

    2C Accurate

    Low CurrentConsumption

    Small Package

    - SOT-23

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    1.6

    1.8

    2

    -40 -20 0 20 40 60 80 100 120

    Temperature (deg C)

    VoltageOut(V)

    The voltage output of the TC1047A changes linearly with corresponding changes intemperature. The TC1047A transfer function have a slope of 10 mV for every degCchange and can detect a range of -40 to 125 degC. It gives you +/- 2% accuracyand consumes very little current. It is also a nice small package that does not takeup a lot of board space (check it out.) Microchip has developed an even smaller

    analog-out temperature sensor the MCP9700 .

  • 8/2/2019 Mechatronics WIB

    29/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 29

    Example 3:Washing Machine

    AC Induction MotorControl

    User interface

    Sensors (door closed,water level, balancesensor)

    In our final example we are going to look at a mechatronic example thatincorporates several microcontrollers in its makeup. In large appliances like awashing machine, the user interface and motor control circuits are isolated from oneanother in order to meet safety standards. In this example a central microcontrollertakes user inputs from the cycle select, water level, water temperature, extra rinse,

    and cycle buzzer buttons and dials. The microcontroller also reads the varioussensors: water level sensor, balance sensor, turbidity sensor, door sensor. Anothermicrocontroller controls the AC induction motor and changing between the spin andagitate cycles. The motor control microcontroller takes commands from the centralmicrocontroller.

  • 8/2/2019 Mechatronics WIB

    30/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 30

    User Interface Improvements

    Use standard dials and knobs

    Same knobs used on different models

    Reprogramming microcontroller givesknobs different functionality

    Switches less prone to wear compared tomechanical washing machine

    One of the biggest areas of improvement on the washing machine is the user interface. Inmechanical washing machines the cycle knob actually had plastic bumps on the back of the dial thatacted like the software of the system. The user would turn the dial and a mechanical timer wouldstart running, slowly turning the dial to the off position. As the dial turned the bumps on the back ofthe dial would come in contact with various switches that would turn on the spin cycle, fill the washer,or any number of other functions. This system worked but it had several drawbacks. First, the dial

    had to be fabricated for just one washer. When the timing of one of the cycles changed, for instance,a new dial had to be made. Secondly, the plastic bumps would eventually wear down or themechanical timer would go bad. This meant the knob would have to be replaced. In modernwashers, the same knob can be used on different washer models. Instead of configuring a physicalknob for a certain washer, now the firmware in the microcontroller is configured for that washer. Thisstandardizes parts and keeps inventory low.

    Lowering Cost:

    Cost is an important consideration in all design, however, in the world of appliances, designers willgive up almost anything (including their first-born) to shave a penny off of the cost of a product. Oneof the reasons mechatronic designs are on the rise for appliances is that total system cost is beingreduced. In some cases, converting a design to a mechatronic solution may appear to be more

    expensive on just a part-by-part basis. However, when the whole product solution is considered(including inventory, warranty repairs, customer support, and quantity pricing over all products) themechatronic solution becomes the more-cost effective solution while making your product moredesirable to customers (compared to competitors.)

  • 8/2/2019 Mechatronics WIB

    31/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 31

    Benefits of Modern Sensors

    Turbidity sensor*: How much dirt is in the water?

    Door position sensor**: Is the door ajar?

    Balance sensor**: Is the machine unbalanced?

    Water Level sensor*: Determined by size of load.

    Benefits:

    * More efficient washing

    - Energy efficient

    - Water efficient** Make washing safer (for people and the machine)

    With a microcontroller in the system a whole array of sensors can be incorporatedinto the product to make it safer and more efficient.

    Turbidity sensor measures how much particles are in the water. These meansinstead of running a set time in order to clean the closes, the washer now cleansthe clothes until there are clean. It also rinses the clothes until all soaps arerinsed from the clothes.

    The door position sensor ensures the machine will not enter the spin cycle withthe door open. This prevents a child from getting harmed by sticking his arm inthe machine while it is spinning.

    A balance sensor monitors the balance of the machine. Should the machine startoscillating violently, the machine shuts itself off in order to prevent harm to themachine and its surroundings.

    Water level sensor allows the user to set a load size, furthering the waterefficiency of the machine.

    With the addition of sensors, modern high-tech washers use half the energy andwater of older machines, in addition to getting clothes cleaner than before.

  • 8/2/2019 Mechatronics WIB

    32/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 32

    AC Induction Motor Control

    Benefits to Microcontroller-based speed

    control:

    Smaller motor

    Standardized motor

    Higher efficiency

    Consistency over varying load conditions

    Precision speed-control (more speedspossible)

    History:

    Mechanical washing machines typically use a two speed motor to spin the drum andagitator. Depending on the durability of the load, the motor may run at low speed(for delicates) or high speed (for blue-jeans and towels.) The two speeds areachieved by the number of windings turned on in the motor. In a two winding motor,one winding is turned on for low speed, two are turned on for high speed.

    Comparison to Modern designs:

    In a mechatronic washing machine, this two-speed motor is replaced with astandard smaller motor. This motor produces the same power as the two speeddesign, but because it doesnt have the complexity of the two-speed motor it issmaller. A microcontroller is used to control the speed of this motor by modulatingthe windings. Compared to the two-speed system, the motor in the modernmachine has a far greater number of speed settings. This means the speed of the

    motor can be set for individual load types (perma-press, delicates, cotton, wool,etc.) In addition, feedback in the system allows the motor to provide a consistentspeed independent of the weight of the load. Finally, because more control over thepower usage of the motor is now available, the motor can be run at its optimumsetting for a given load in order to optimize efficiency.

  • 8/2/2019 Mechatronics WIB

    33/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 33

    Possible Solution: PIC18F4431

    PWM Output: 8 independent channels

    - Up to 14-bit resolution

    - Edge and center-aligned

    - Programmable dead-time

    3-ch Quadrature Encoder Interface

    10-bit High-Speed A/D Converter

    Created from the ground upfor precision motor control!

    Lets take a look at what Microchip products are being used in these newmechatronic marvels. On the motor control side of the things, MicrochipsPIC16F4431 microcontroller is an excellent candidate for Brushless DC and ACinduction motor control systems. Some of its motor-control specific features arelisted on this slide. Basically, what you need to know is that for high-end motor

    control applications, this is a microcontroller that was built from the ground up totarget those applications.

  • 8/2/2019 Mechatronics WIB

    34/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 34

    Microchip MOSFET DriverSolutions

    Power MOSFET Drivers

    0.5A Peak Output

    TC1410/Nsingle

    TC1411/Nsingle

    1A Peak Output

    1.2A Peak Output

    TC1426/7/8dual

    TC4467/8/9quad

    1.5A Peak Output

    Single

    TC4626/7voltage boost

    TC4431/230V high/low

    TC4403floating load

    Dual

    TC4x6/7/8Enhanced

    TC442xAmatched delay

    TC4404/5split out, open drain

    2A Peak Output

    TC1412/Nsingle

    TC1413/Nsingle

    TC4423/4/5dual

    TC429 TC4420/9single

    TC4421/2single

    6A Peak Output

    3A Peak Output 9A Peak Output

    Microchip is one of the first and leading suppliers of MOSFT Drivers. Ourportfolio consists of a wide range of products that can deliver up to 9A peakoutput current and come in several configurations (single/dual/quad andinverting/non-inverting). Our solutions are very robust: they lead the industryin latch-up immunity/stability. (They are used to drive the high-power

    devices, like IGBTs, MOSFETs, and Bipolar transistors.)

  • 8/2/2019 Mechatronics WIB

    35/195

    2005 Microchip Technology Incorporated . All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 35

    Mechatronics Review

    Mechatronics is _________________. What are the benefits to mechatronics?

    - How does the consumer benefit?

    - How does the manufacturer benefit?

    What is the worlds smallest microcontroller?

    What microcontroller can directly drive a

    LCD?

    Review mechatronics with the students:

    Answers:

    Mechatronics is implementing electronic control in a mechanical system. Itis also replacing mechanical components in a system with electrical

    components. Benefits:

    Consumer: more features, more user friendly, more reliable, lowercost, safer, environmentally friendly, more efficient

    Manufacturer: flexible, lower cost, more market appear, higherresolution, less warranty repairs

    PIC10F20x family

    Hint: Its the microcontroller on the PICDEM Mechatronics board thePIC16F91x family

  • 8/2/2019 Mechatronics WIB

    36/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 36

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    In this next section we will be taking a introductory look at PIC microcontrollers.Rather than just telling you about how a PIC microcontroller works, you will be ableto experience the PIC microcontroller working yourself with the tools provided forthis class. The knowledge you learn in this section will be tested during the Labsthat follow this section.

  • 8/2/2019 Mechatronics WIB

    37/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 37

    Objectives of PICMicrocontrollerBasics

    We will learn how to:

    Create code

    Compile

    Test and debug

    Use MPLAB Integrated Development

    Environment (IDE)

    . . . all with a focus on learning about PIC microcontroller

    architecture and terms

    These are the objectives for the PIC Microcontroller Basics section:

    Create code

    Compile source code

    Test and Debug code

    Use MPLAB Integrated Development Environment (IDE)

    While we are creating, compiling and testing code you will be becomingfamiliar with PIC microcontroller architecture and terms

  • 8/2/2019 Mechatronics WIB

    38/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 38

    What is MPLAB IDE?

    MPLAB

    IDE is the name of Microchips freeIntegrated Development Environment

    Software that runs on your PC

    Complete development environment for your

    embedded system

    Our basic tool for the rest of this class

    I just mentioned we are going to learn how to use MPLAB IDE. What is MPLABIDE? Microchips Free MPLAB IDE is downloadable from Microchips website,www.microchip.com. MPLAB IDE is a Windowsprogram that runs on your PC. Asyoull soon see, the software is fairly easy to use.

  • 8/2/2019 Mechatronics WIB

    39/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 39

    Embedded Software DesignCycle

    Write Code

    Build CodeRun Code

    Debug Code

    This slide shows the embedded software design cycle. Embedded refers tocreating software for a microcontroller or other programmable integrated controller.This Cycle begins with you brainstorming the design at a high level. You maycreate flowcharts, outlines, or storyboards for the program flow. Next youll writesource code. Then youll build the code using MPLAB IDE (or check for errors.)

    Next you will run the code either in a simulator or on the part using a debugger.Finally, youll test or debug the code. Does the code do what it is supposed to. Ifthe answer is no, then the cycle continues until you have a finished piece of code.

  • 8/2/2019 Mechatronics WIB

    40/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 40

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Cycle #1

    We will be going through several hands-on learning cycles. These cycleswill begin with me explaining a piece of PIC microcontroller architecture.Well then write some instructions together to create an application. Finally,well test the application. We will now begin learning cycle #1.

  • 8/2/2019 Mechatronics WIB

    41/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 41

    Architecture: Overview

    SpecialFeatures

    Input /OutputPorts

    ProgramMemory

    DataMemory

    This is a simplified look at PIC microcontroller architecture. There are four majorcomponents to the PIC microcontroller architecture:

    Program memory

    Data memory

    Input/Output Ports and Special Features

  • 8/2/2019 Mechatronics WIB

    42/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 42

    Architecture: Overview

    SpecialFeatures

    I/OPorts

    ProgramMemory

    DataMemory

    We are going to first look at the memory on a PIC microcontroller.

  • 8/2/2019 Mechatronics WIB

    43/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 43

    Architecture: PIC16F917

    ProgramMemory

    14 bits wide

    8192 words

    HardDrive

    The part that we will be using on the PICDEM Mechatronics board is thePIC16F917. Therefore, well be discussing all these architecture componentsspecifically for the PIC16F917. The first component is program memory. Think ofprogram memory as your hard disk drive. The drive contains all the programs yourun on your PC. On the PIC16F917 the program memory is 14 bits wide by 8192

    words. Commit these numbers to memory for a few moments.

  • 8/2/2019 Mechatronics WIB

    44/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 44

    Architecture: PIC16F917

    DataMemory

    8 bits wide

    512 bytes

    FloppyDisk

    A microcontroller also has data memory. This memory is memory that is constantlychanging. You may think of it as a floppy disk. The data memory is 8 bits wide by512 bytes. Commit these numbers to memory as well.

  • 8/2/2019 Mechatronics WIB

    45/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 45

    Hands-on with MPLABIDE

    MPLAB IDEMPLAB IDE

    Lets look at both of these memory types on the PIC16F917. Open MPLAB IDE byclicking on these ICON on your desktop.

  • 8/2/2019 Mechatronics WIB

    46/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 46

    Configure Select Device

    Choose Configure -> Select Device.

  • 8/2/2019 Mechatronics WIB

    47/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 47

    Selecting PIC16F917

    Choose the PIC16F917.

  • 8/2/2019 Mechatronics WIB

    48/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 48

    Program Memory View

    We have just set up MPLAB IDE to develop code for the PIC16F917. Do you stillremember those numbers I had you commit to memory?

    Question to Pose: How many bits wide is the Program memory? How many

    words?

    Lets look at the program memory.

    Choose View -> Program Memory

  • 8/2/2019 Mechatronics WIB

    49/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 49

    Program Memory View

    A window showing the program memory will appear.

    Near the bottom of the window click on the Machine tab.

    Scroll to the last memory location

    What line is this? Does this number look familiar?

    Look at the Opcode column. Can anybody tell by how many bits long theopcode is? (Answer: 14)

  • 8/2/2019 Mechatronics WIB

    50/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 50

    Hexadecimal to Binary

    3FFF

    11111111111111

    If youre unfamiliar with hexadecimal numbers bring up the calculator in Windows:

    Start -> All Programs -> Accessories -> Calculator

    In Calculator click View -> Scientific

    Select the Hex radio button near the top left of the window

    Type in 3FFF

    Select the Bin radio button

    How many 1s are in the window? There are 14.

  • 8/2/2019 Mechatronics WIB

    51/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 51

    Data Memory (File) View

    Now, lets take a look at the data memory. Data memory is also called fileregisters.

    Choose View -> File Registers

  • 8/2/2019 Mechatronics WIB

    52/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 52

    Data Memory (File) View

    8 bits

    In the File Registers window, click on the symbolic Tab.

    Scroll to the end of the memory.

    The last address is 01FF. What is the number in decimal? (Answer 512.) Usethe calculator to show the audience if necessary.

    How long is each register? Look at binary column. Each 0 represents a bit.

  • 8/2/2019 Mechatronics WIB

    53/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 53

    Special Function Registers

    Open your window wide enough so that you can see the symbol name column.

    Scroll back to the top of the file registers.

    You can see that some for the data memory has already been assigned a symbol

    name. These registers are called Special Function Registers or SFRs. Youdont need to understand what these registers are yet, however, just rememberthat they exist because well be learning more about these registers later.

  • 8/2/2019 Mechatronics WIB

    54/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 54

    Separate Program & Data

    ProgramMemory

    DataMemory

    Program and Data memory

    are separate entities

    Why separate?

    As you can see program and data memory are separate entities. Why? Whatpurpose do these different memory entities serve?

    Answer:

    Program Memory This is the memory that contains the source code. Its actuallythe numerical equivalence of source code. This memory is fixed once it isprogrammed into a PIC microcontroller.

    Data Memory This memory is dynamic. It is constantly changing. This memorycontains variables and information about the current state of input/output pins on thePIC microcontroller.

  • 8/2/2019 Mechatronics WIB

    55/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 55

    Cycle #1: What Did I Learn?

    I learned how to select my target device

    Program memory is ___ bits by ___ words

    Data memory is ___ bits by ___ words

    A file register is just another name for ___

    Program and data memory are separate

    Certain file registers are special function

    Lets review Cycle #1.

    You learned how to select a device in MPLAB

    Program memory is 14 bits by 8192 words

    Data memory is 8 bits by 512 words

    A file register is just another name for Data memory.

    Program and data memory are separate

    Certain file registers are Special function registers

  • 8/2/2019 Mechatronics WIB

    56/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 56

    Cycle #2

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    We are now ready for hand-on learning cycle #2.

  • 8/2/2019 Mechatronics WIB

    57/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 57

    Architecture: Overview

    SpecialFeatures

    I/OPorts

    ProgramMemory

    DataMemory

    In this cycle we will be learning about one of the PIC microcontrollers specialfeatures.

  • 8/2/2019 Mechatronics WIB

    58/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 58

    Architecture: W Register

    SpecialFeatures

    W register is an

    8-bit temporary

    working register

    W register is

    used in many

    instructions

    The W register is an 8-bit temporary working register. The W register is used inmany instructions. If you want to add two numbers together, for instance, you willmove one number into the W register, then add the other number to W.

  • 8/2/2019 Mechatronics WIB

    59/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 59

    Hands-on with MPLABIDE

    MPLAB IDEMPLAB IDE

    The best way to understand the W register is to use it. Were going to do that nowby writing your first PIC microcontroller source code.

  • 8/2/2019 Mechatronics WIB

    60/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 60

    MPLABSimulator

    Lets begin by opening the MPLAB Simulator. The MPLAB Simulator simulateswhat the PIC16F917 will do on your PC. Its a great tool for learning and trying outnew instructions. Its possible to use the simulator to debug a piece of code withoutever programming a PIC microcontroller.

    Choose Debugger -> Select Tool -> MPLAB SIM

  • 8/2/2019 Mechatronics WIB

    61/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 61

    Creating My First Program

    Click on File New

    Enter the four lines of code below:

    addlw 1

    movwf 0x20

    goto 0end

    We have to write some code for the simulator to simulate. To do this:

    Choose File -> New

    Enter the four lines of code below

    This four lines are included in the Hands-on Guide hand-out. In the Hands-onGuide, each line is commented to tell you how each instruction works.

  • 8/2/2019 Mechatronics WIB

    62/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 62

    Creating Your First Program

    Click on File Save As

    c:\h1.asm

    Project Quickbuild h1.asm

    Look in the Output Window for

    BUILD SUCCEEDED

    Save the file as h1.asm under C:\

    Build the project using Project -> Quickbuild h1.asm

    Verify that the build was successful in the output window

  • 8/2/2019 Mechatronics WIB

    63/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 63

    Running Your First Program

    Have the students cursor over the simulator buttons and explain how run, halt,animate, single step, and reset work.

    Explain the status bar:

    MPLAB SIM this location shows the tool MPLAB is currently configured for PIC16F917 this location shows the processor MPLAB is currently configured for

    PC Program Counter This shows the code line of code you are currentlyexecuted.

    W The value of the W register

    Have the students single-step through that code. What happens to W and PC?

  • 8/2/2019 Mechatronics WIB

    64/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 64

    Adding a Watch Window

    Click onView Watch

    0x20

    We are moving W to address 0x20. Wed like to see the current state of address0x20. This can be done by creating a watch window.

    Create a watch window:

    Choose View -> Watch In the address column type in 0x20

    Optional: In the symbol name column type WREG

    Let the students single step through the code and see how the instructions work.Show them what happens when they click animate.

  • 8/2/2019 Mechatronics WIB

    65/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 65

    Cycle #2: What Did I Learn?

    W Register

    Create a .asm file

    Quickbuild

    MPLABSIM step, animate

    Watch window

    Status bar

    Three instructions One assembler directive

    In Cycle #2 you learned:

    About the working register

    How to create and .asm file

    How to quickbuild

    How to use Simulator

    What a watch window is

    What the status bar tells you

    Three instructions movwf, addlw, goto

    One assembler directive end

  • 8/2/2019 Mechatronics WIB

    66/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 66

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Cycle #3

    Now for cycle #3.

  • 8/2/2019 Mechatronics WIB

    67/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 67

    Architecture: Overview

    SpecialFeatures

    I/OPorts

    ProgramMemory

    DataMemory

    The Input/Output ports are what enable the microcontroller to receive inputs andoutput signals. These ports are how the microcontroller interacts with the worldaround it.

  • 8/2/2019 Mechatronics WIB

    68/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 68

    I/O Ports: PORTA Register

    PORTA 0x05

    RA0RA7

    PORTA is an 8-bit register that controls the state of pins RA0 through RA7. Look atthe PICDEM Mechatronics board. Near the top left corner of the PIC16F917 youllsee pins labeled RA0, RA1, etc. The state of these pins is controlled by PORTA.On this slide everything in the dashed box is inside the PIC microcontroller.Everything outside this box represents what is outside the microcontroller, namely

    the pins.

    PORTA is memory location 0x05.

  • 8/2/2019 Mechatronics WIB

    69/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 69

    I/O Ports: PORTA Register

    1 0 0 0 0 1 1 1

    5V

    0V

    R

    A7

    R

    A0

    This slide shows the state of RA7 through RA0. Starting with RA7 the pins are at5V, 0V, 0V, 0V, 0V, 5V, 5V, and 5V. As you can see PORTA is equal to a binarynumber: 10000111.

  • 8/2/2019 Mechatronics WIB

    70/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 70

    I/O Ports: TRISA Register

    RA0RA7

    TRISA 0x85

    TRISA is an 8-bit register (memory location 0x85) that controls the direction of eachpin in Port A. In other words, TRISA determines whether a pin is either an output oran input. A pin is an input if the corresponding bit in TRISA is a 1. A pin is anoutput if the corresponding bit in TRISA is a 0. This is easy to remember because0 looks like O for output. 1 looks like I for input.

    If a pin is an output then you have control over the state of the pin by setting orclearing the corresponding bit in PORTA.

    If a pin is an input then you can only read the state of the pin in PORTA.Manipulating a input pin is not possible.

  • 8/2/2019 Mechatronics WIB

    71/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 71

    I/O Ports: TRISA Register

    RA0RA7

    0 0 0 1 0 1 1 0

    This slide shows the TRISA register and the correlation to an input or output pin.

    If TRISA is set as show here which pins do you have control over?

  • 8/2/2019 Mechatronics WIB

    72/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 72

    I/O Ports: Port D

    PORTD: 8-bit I/O port PORTD is actually data memory 0x08

    TRISD: 8-bit direction control register

    TRISD is actually data memory 0x88

    Weve talked about Port A. As you can see there are more Ports on thePIC16F917, according to the labels next to microcontroller on the PICDEMMechatronics Board. PORT D is another 8-bit I/O port. PORTD is memory location0x08. The direction control register is TRISD and it is data memory 0x88.

  • 8/2/2019 Mechatronics WIB

    73/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 73

    Hands-on with MPLABIDE

    MPLAB IDEMPLAB IDE

    Lets do another hand-on. In this hands-on we will write code to make PORT D alloutputs and turn on and off all the pins in this port. Well use the simulator and awatch window to check to see if our source code is actually doing what it should.

  • 8/2/2019 Mechatronics WIB

    74/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 74

    Code Round 3

    Change your code to

    Quickbuild

    Change the Watch address to 8

    movlw b00000000

    movwf 0x08

    movlw b11111111

    movwf 0x08

    goto 0

    Change the code in h1.asm to this. Dont forget the end directive at the end ofthe code.

    Choose Project -> Quickbuild

    Change the Watch address to 8 (Note the symbol name shown next to the

    address)

  • 8/2/2019 Mechatronics WIB

    75/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 75

    Stepping Through the Code

    Do aWindow Tile Horizontally

    Use F7 to Single-Step through the code

    movlw b00000000

    movwf 0x08

    movlw b11111111

    movwf 0x08

    goto 0

    Tile the Windows horizontally by choosing Window -> Tile horizontally

    Single step through the code using F7.

    What should the code be doing? (Loading PORTD with 0 and then loading PORTD

    with 0xFF)What is the code doing? (PORTD never changes.)

    Why isnt the code doing what it is supposed to?

  • 8/2/2019 Mechatronics WIB

    76/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 76

    PORTD Direction Control

    Add TRISD (0x88) to your Watch

    PORTD is all inputs!

    Set TRISD to all outputs (zeros)

    Lets take a look at the Direction control register, TRISD. Add TRISD to your watchwindow. What is it. TRISD is all 1s.

    Remember a binary 1 means a pin in an input. PORTD is all inputs according to theTRISD register.

    We have to make TRISD all outputs (zeros). Lets do that in the code.

  • 8/2/2019 Mechatronics WIB

    77/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 77

    TRISD - Direction Control

    Add this line to the top of your code

    Build, single-step

    Can you see TRISD being cleared?

    clrf 0x88 ; clear TRISD

    Add the line of code to the top of you code. Any guesses as to what the clrf (clearfile) command does?

    Our intention is to make all the 1s in TRISD all 0s. We could use the movlw

    command to move 0 into W and then the movwf to move W into TRISD. However,the clrf (clear file) register allows us to do this in one instruction rather than two.

    Build, single-step

    Is TRISD all zeros? (No.)

  • 8/2/2019 Mechatronics WIB

    78/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 78

    Why doesnt TRISD clear?

    Lets revisit data memory

    Why doesnt TRISD clear?

    TRANSTITION: The reason TRISD is not being cleared requires us to learn alittle more about PIC microcontroller architecture.

  • 8/2/2019 Mechatronics WIB

    79/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 79

    Architecture: Overview

    SpecialFeatures

    I/OPorts

    ProgramMemory

    DataMemory

    Lets look more closely at how instructions operate on data memory.

  • 8/2/2019 Mechatronics WIB

    80/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 80

    Accessing Data Memory

    DataMemory

    clrf 0x88

    Again, our intention is to clear data memory location 0x88 or the TRISD register.

  • 8/2/2019 Mechatronics WIB

    81/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 81

    Architecture: Data Memory

    DataMemory

    Address

    clrf 0x88

    What youve probably figured out is that 0x88 is actually a data memory address.When we use clrf 0x88 we expect address 0x88 to be cleared.

  • 8/2/2019 Mechatronics WIB

    82/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 82

    Architecture: Data Memory

    DataMemory

    Address

    32

    clrf b10001000

    What I didnt tell you before is that you can only specify the first 7-bits of an addressafter an instruction. That why clearing 0x88 didnt change TRISD. 0x88 is shownhere as a binary number. The bit in red is out of the range of the instruction tooperate on. With 512 bytes of data memory, we need 9-bits of addressing. Thesetwo other bits are in register 3, bits 5 and 6.

  • 8/2/2019 Mechatronics WIB

    83/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 83

    Architecture: Data Memory

    Bank 00-7F

    00xxxxxxx

    Bank 180-FF

    01xxxxxxx

    Bank 2100-17F

    10xxxxxxx

    Bank 3180-1FF

    11xxxxxxx

    00 01 10 11

    3,6 3,5

    This effectively splits the memory into 4 banks. An instruction will reference Bank0when bits 5 and 6 of register 3 are zero. An instruction will reference Bank1 when3,6 is 0 and 3,5 is 1. When 3,6 is a 1 and 3,5 is a 0 an instruction will referenceBank 2. Finally, when both bits are set, an instruction will address registers inBank3.

  • 8/2/2019 Mechatronics WIB

    84/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 84

    Bank 00-7F

    00xxxxxxx

    Bank 180-FF

    01xxxxxxx

    Bank 2100-17F

    10xxxxxxx

    Bank 3180-1FF

    11xxxxxxx

    00 01 10 11

    88

    Architecture: Data Memory

    TRISD, or data memory address 0x88, is clearly in Bank 1 as seen in this diagram.

  • 8/2/2019 Mechatronics WIB

    85/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 85

    Architecture: Bank 1 Select

    01

    bsf 3,5Bank 00-7F

    00xxxxxxx

    00

    Bank 180-FF

    01xxxxxxx

    Therefore, if we want an instruction to address TRISD we have to first set the 3,5bit. We use the bsf or bit set file instruction to set a bit in a file register.

  • 8/2/2019 Mechatronics WIB

    86/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 86

    Architecture: TRISD

    01

    bsf 3,5

    clrf 0x88Bank 00-7F

    00xxxxxxx

    00

    Bank 180-FF

    01xxxxxxx

    88

    Once we are in bank1, we can clear TRISD. We can enter clrf 0x88.

  • 8/2/2019 Mechatronics WIB

    87/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 87

    Architecture: Bank 0 Select

    01

    bsf 3,5

    clrf 0x88

    ????

    Bank 00-7F

    00xxxxxxx

    00

    Bank 180-FF

    01xxxxxxx

    8

    Once we are done setting up the TRISD register, we want to be able to manipulatePORTD, or address 8.

    What do we need to do to return to Bank0?

  • 8/2/2019 Mechatronics WIB

    88/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 88

    TRISD - Direction Control

    Our final code

    bsf 3,5clrf 0x88

    bcf 3,5

    movlw b00000000

    movwf 0x08

    movlw b11111111

    movwf 0x08goto 3

    The answer is, clear bit 3,5. This is done with the bcf instruction.

    Modify the your code as shown on this slide. Refer to the handout for commentsabout what each line of code is doing. Step through the code. Is TRISD being set

    appropriately? What is happening to PORTD?

  • 8/2/2019 Mechatronics WIB

    89/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 89

    Symbol Name and File RegisterCorrelation

    include

    bsf 3,5 bsf STATUS,RP0

    clrf 8 clrf TRISD

    bcf 3,5 bcf STATUS,RP0

    Loop

    movlw 0 movlw 0

    movwf 8 movwf PORTD

    movlw 0xff movlw 0xff

    movwf 8 movwf PORTD

    goto 3 goto Loop

    Remembering the address of every register would be hard to do. Fortunately, youcan include a file with all the symbol names defined for a given part. This allowsyou to address addresses by name rather than number.

    Add include to the top of the code.

    After the 3rd

    instruction add the label Loop. Change the goto 3 instruction togoto Loop.

    You may have made the connection that the microcontroller manipulates numbers.In order to make these numbers easier for a human to work with, specific addressesare given names that represent what that address is responsible for.

    Youll also notice by the changes to the code that register 3 is the STATUS register.Well learn more about some of the other bits in the STATUS register later.

    One important note regarding symbol names and labels They are case sensitive!The compiler will interpret PORTD and portd differently. The same goes for Loopand LOOP.

  • 8/2/2019 Mechatronics WIB

    90/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 90

    Cycle #3: What Did I Learn?

    PORTx Registers TRISx Registers

    Banking

    STATUS register, bits RP0 & RP1

    Symbol name and number correlation

    Four instructions

    One assembler directive

    Review Cycle #3

    PORTx

    PORTx

    Banking

    STATUS bits RP0 and RP1

    Symbol name and number correlation

    4 instructions: bsf, bcf, clrf, movlw

    One assembler directive: include

  • 8/2/2019 Mechatronics WIB

    91/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 91

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Cycle #4

    Up until now, weve been working will the simulator. In cycle #4, we areactually going to make the PIC16F917 interact with the physical world.

  • 8/2/2019 Mechatronics WIB

    92/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 92

    Architecture: Overview

    SpecialFeatures

    I/OPorts

    ProgramMemory

    DataMemory

    We will be doing this with the I/O ports that you were introduced to in cycle #4.

  • 8/2/2019 Mechatronics WIB

    93/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 93

    Introduction to thePICDEM Mechatronics Board

    The PICDEM Mechatronics Boards that you purchased for this workshop will be thevehicle that we use to experiment with the PIC16F917. It will allow you to see themicrocontroller working. In cycle #4 we will be using the PICDEM mechatronicsboard to observe firmware reading and manipulating the digital I/O pins.

    A few things you should know about the board are:

    We are going to power the board from a 9V, 0.75 supply

    The on-board regulator drops the voltage on the board to 5V

    What all this means is that, this board will not electrocute you!

    TRANSISION: First, we need to connect the microcontroller on the PICDEMMechatronic board to some of the surrounding components.

  • 8/2/2019 Mechatronics WIB

    94/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 94

    Connect the Hardware

    Lets configure the board for our next hands on.

    For cycle#4 we will set up one input. The input will be a tactile switch connected toRA4. PORTD will be all outputs. We are going to attach each pin in PORT D to anLED. This essentially gives us a visual binary representation of PORTD. Thestudent handout contains the wiring diagram shown on this slide.

    Using Jumper wires connect:

    SW2 (J4) to RA4 (J13)

    D0 (J14) to RD7 (J10)

    D1 (J14) to RD6 (J10)

    D2 (J14) to RD5 (J10)

    D3 (J14) to RD4 (J10)

    D4 (J14) to RD3 (J10)

    D5 (J14) to RD2 (J10)

    D6 (J14) to RD1 (J13)

    D7 (J14) to RD2 (J13)

  • 8/2/2019 Mechatronics WIB

    95/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 95

    Connecting the ICD 2 and Power

    ICD2ICD2

    J11

    J9

    USB

    Next, we need to connect the PICDEM Mechatronics Board to power and theMPLAB ICD 2

    Connect the power supply to J9

    Connect the ICD 2 to J11

    Connect the USB cord to the ICD 2

  • 8/2/2019 Mechatronics WIB

    96/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 96

    Introduction to the MPLAB ICD 2

    MPLAB ICD 2 is an In-circuit Debugger and

    Programmer

    Debug mode:

    - Find out why your program isnt doing what youexpect it to do

    - Look at the data memory

    - Step through the code

    - Set break points

    Program mode:- Program a device

    What is the MPLAB ICD 2?

    The MPLAB ICD 2 is an in-circuit debugger. An in-circuit debugger allows you to:

    Debug the code by allowing you to stop the part and step through your code.

    While stepping the debugger uploads critical registers from the microcontrollerand displays these registers in the MPLAB IDE. This allows you to see what thepart is doing and find why it isnt working as suspected. In other words, thedebugger does what the simulator did only it does it using actual hardware andthe device.

    Program a device

  • 8/2/2019 Mechatronics WIB

    97/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 97

    Hands-on with MPLABIDE

    MPLAB IDEMPLAB IDE

    Now we are going to finally make the PIC16F917 interact with the outside world.

  • 8/2/2019 Mechatronics WIB

    98/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 98

    Create a Project In MPLAB IDE

    Lets first create and save a project in MPLAB IDE. The benefits of creating aproject are:

    The project window gives you easy access to the file or files in you project

    You can link more than one file together at build time. Well look at this more

    later in the labs The advantage you will see now is that we can build at the touch of a button

    rather than choosing quickbuild

    Once in MPLAB IDE click on Project in the menu bar and select the ProjectWizard. The project wizard helps you create a project very quickly.

  • 8/2/2019 Mechatronics WIB

    99/195

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 99

    Creating a Project Continued

    Select the PIC16F917, click Next

    Choose the Microchip MPASM Toolsuite,

    click Next

    Create a project name of test

    Save in C:\, click Next

    Add h1.asm to the project, click Next

    Click Finish

    Follow these steps to finish creating a project

  • 8/2/2019 Mechatronics WIB

    100/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 100

    Save Workspace

    Save the Workspaceas test in C:\

    MPLAB IDE may automatically prompt you to save the workspace. If it doesnt,click on File -> Save Workspace As

    Next, find the c:\ and save the workspace as test.

    Benefits of a Workspace

    A workspace saves your MPLAB environment so that the next time you want towork on a specific project you can pick up right where you left off.

    Saves the configuration bits

  • 8/2/2019 Mechatronics WIB

    101/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 101

    Opening Source Files

    The project window

    contains the source,include, and linker files

    Double-click on the filenames to open (or focuson) the desired file

    Right-click on SourceFiles to add source files

    Remove files by right-

    clicking on them andchoosing Remove

    The project window now shows the name of the workspace, the project name, andthe files included in the project. Use this window to add source, include and linkerfiles. Opening a file in projects is as easy as double-clicking on a file name. Usethe project window to add and delete files for a project. In our case, we only haveone file. Later on, however, youll be working with projects with more than one

    source file.

  • 8/2/2019 Mechatronics WIB

    102/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 102

    ICD 2 Setup

    Debugger - Select Tool - 1 MPLAB ICD-2

    Debugger - Connect

    Configuration - Configuration Bits

    Lets select the ICD 2 as our debugger in MPLAB.

    Select ICD 2 as debugging tool: Debugger -> Select Tool -> 1 MPLAB ICD-2

    Connect to the ICD-2: Debugger -> Connect

    Setup Configuration bits: Configuration Configuration Bits

    Oscillator equal INTOSC

    Watchdog Timer off

    Power Up Timer on

    (The rest can remain in the default state)

    Configuration bits do exactly what the name implies they configure themicrocontroller. For the PIC16F917, there are 14 configuration bits. These bits setup the clock source for the microcontroller, turn on the watchdog timer, etc. Theconfiguration bits can not be changed during runtime. In order words you have to

    reprogram the part to re-configure these bits.

  • 8/2/2019 Mechatronics WIB

    103/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 103

    Cycle #4: Write the Source Code

    include

    bsf STATUS,RP0

    clrf TRISD

    bsf TRISA,4

    bcf STATUS,RP0

    Loop

    btfsc PORTA,4

    goto Loop

    incf PORTD,fgoto Loop

    Type in the source code shown

  • 8/2/2019 Mechatronics WIB

    104/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 104

    Building and Programming

    In a project the build command is F10.

    (Do this now!)

    Once the source code is built it must beprogrammed into the PIC16F917

    To program a device click on:

    You mustbuildandprogramafterevery change to your source code!

    The build command in a project is Project -> Make, or the F10 key. Use F10 tobuild the project now. Use this method rather than Quickbuild when working with aproject.

    We are now using the ICD 2 and not the simulator. This means we have to transferthe code to the PIC16F917 before running the device. Use the indicated icon toprogram the PIC16F917.

    Keep in mind that every time you make a change to your code you will have to buildthe source code and then program the PIC microcontroller before running.

  • 8/2/2019 Mechatronics WIB

    105/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 105

    Watching the Source Run

    Create a Watch window

    Watch PORTD and PORTA

    Click the Animate button

    What happens when you press SW2?

    Were almost there!

    Create a watch window that watches PORTD and PORTA

    Click the animate button

    Watch the program flow pointer in the h1.asm file. Press SW2. What happens tothe program flow pointer. Look at PORTA in the watch window while pressing andreleasing SW2. What happens to bit 4? (Other bits might change. These bits arefloating and are electrostatically influenced by RA4. Use a jumper wire to connectthe changing pin to Vss. The pin will no longer change.)

    With SW2 pressed look at PORTD in the Watch window. Look at the LEDs. Seeany correlation?

  • 8/2/2019 Mechatronics WIB

    106/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 106

    Cycle #4: What Did I Learn?

    Set up the PICDEM MechatronicsBoard

    Configured the MPLAB ICD 2

    Created a Project

    Saved a Workspace

    Built a project

    Programmed the PIC16F917

    Ran code using the MPLAB ICD 2

    Review Cycle #4

  • 8/2/2019 Mechatronics WIB

    107/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 107

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    Now were going to start working on the labs.

  • 8/2/2019 Mechatronics WIB

    108/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 108

    Lab Introduction

    Problem: Management wants you to design

    a cooling fan for an electronics bay in thenew Mars Rover

    All of our labs will focus on solving this problem:

    Management wants you to create a cooling fan for an electronics bay in the newMars Rover.

    The labs will all focus on solving this problem. The labs will be very basic and thengradually get more and more complex

  • 8/2/2019 Mechatronics WIB

    109/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 109

    Agenda

    Introduction to Microchip

    Mechatronics examples and benefits

    PICMicrocontroller Basics

    - Hands-On Learning Cycles

    Labs

    - Simple I/O and Timer 0

    - Reading an analog sensor, LCD module

    - Controlling the speed of a motor Resources

    LAB 1

    The purpose of Lab 1 is to use the knowledge youve just learned in PICMicrocontroller Basics to perform the specific task. You will be introduced to Timer0 in this lab.

    Lets take a look at our design objectives for this Lab.

  • 8/2/2019 Mechatronics WIB

    110/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 110

    Lab 1: Design Objectives

    Read the state of a thermal breaker

    Turn on the fan when the breaker trips

    When the breaker resets, wait 2 seconds,then turn off fan

    PIC16F917Thermal BreakerFan

    In Lab 1 we will be creating a very simple system. We will be using a PIC16F917to read a thermal breaker output. When the thermal breaker trips we will turn on thefan. Now, in order to up the complexity of this system a little and make putting aPIC microcontroller in it worthwhile, management has mandated that when thebreaker resets, the fan should cool for another two seconds before shutting down.

  • 8/2/2019 Mechatronics WIB

    111/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 111

    Lab 1: Hardware

    We will use a tactile switch on the board tosimulate the thermal breaker

    The Brushed DC motor will substitute for thefan

    For the PIC16F917 . . . . well well use that!

    PIC16F917

    SW2

    Tactile Switch Brushed DC motor

    For the lab we will be using other components on the PICDEM Mechatronics Boardto simulate our hardware requirements.

    SW2 is a tactile switch. The output from SW2 is normally high (meaning at 5VDC). When the button is pressed, its output becomes low (ground or 0 V). Wewill use SW2 high to simulate a breaker operating normally. SW2 low will simulatethe breaker being tripped

    The substitution for the fan is the brushed DC motor on the PICDEM MechatronicsBoard. This is relatively realistic substitution as if we put a fan blade on the motorit would cool! However, since we didnt want anybody to lose their fingers wedidnt include a fan blade.

    The PIC16F917 will be taking the role of itself in this lab

    TRANSITION: Lets set up our hardware first.

  • 8/2/2019 Mechatronics WIB

    112/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 112

    Lab 1: Schematic

    PIC16F917

    SW2RA4

    RD7

    +5V

    +5V

    Motor

    MOSFET

    D0

    R1

    N2

    Here is a simplified schematic of the system we need to create for this lab.

    The line tying Switch 2 to the microcontroller is tied to +5V via a pull-up resistor,R1.

    When SW2 is depressed the line is grounded. This changes the state of the inputpin from a 1 to a 0.

    RD7 is our output. When RD7 is a logic 0, or at ground potential, the MOSFET willbe open and the LED off. The motor will not run when the MOSFET is open. WhenRD7 is a logic 1, or at +5V, the MOSFET will close, causing the motor to turn on.

    A MOSFET is a solid-state switch that is open or closed based the input at itsgate. For simplicity its shown in this schematic as a switch.

    D0 is a LED that weve also hooked up for this lab. If you get tired of the motorrunning on your desk you can connect just D0. D0 will give a visual representationof the drive control to the motor.

    The lines in red show the connections you will be making on the PICDEMMechatronics board. Lets make those connections now.

  • 8/2/2019 Mechatronics WIB

    113/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 113

    Lab 1: Connection Diagram

    RA4,SW2

    RD7,D0

    RD7,N2

    Vdd,P1

    Now we are going to hook up the board like I just described.

    First, connect a wire jumper between SW2 on J4 and RA4 on J13. J4 and J13 aswell as other headers on the board have horizontal pins connected together. Thisis so that you can jumper from a peripheral device to the microcontroller and alsofrom the peripheral device to a piece of test equipment or LED.

    Connect a wire jumper between VDD (J10) and P1 (J1).

    Connect a wire jumper between RD7 (J10) and D0 (J14). We will use the LED tovisually check the state of RD7

    Connect a wire jumper between RD7 (J10) and N2 (J1)

  • 8/2/2019 Mechatronics WIB

    114/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 114

    Lab 1: Connection Diagram

    JP8: Centerand Rightusing shunt

    Inspect your board for 2 pin jumpers, or shunts. The only shunt on the board willbe connecting +5 VDC to our output stage (JP8). Make sure the shunt isconnecting the middle and right pin.

    Connect one lead of the brushed DC motor to the screw terminal labeled DRIVE 1

    Connect the other lead of the brushed DC motor to the screw terminal labelDRIVE 2

  • 8/2/2019 Mechatronics WIB

    115/1951

    2005 Microchip Technology Incorporated. All Rights Reserved. Mechatronics Workshop-in-a-Box Slide 115

    Timer 0

    8-bit timer It continuously runs

    Overflow flag: INTCON,T0IF

    Example:

    Timer 0 INTCON,T0IF

    11111110 0

    11111111 0

    00000000 1