config pr script

Upload: juan-gonzalez

Post on 04-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Config Pr Script

    1/9

    Text script for Device Configuration Page 1 of 9

    34Text Script for eLearning course Device ConfigurationTable of contents

    Topic Slide Number

    Introduction 1Programming Configuration 2

    Configuration Word 3Oscillator Configuration 4Knowledge Check #1 5

    Watch Dog Timer 6Power-up Timer 7

    Brown-out Reset 8Low Voltage Programming 9Knowledge Check #1 10Code Protection 11Flash Program Memory (Write Enable) 12

    Debug 13Config Assembler Directive 14Knowledge Check #3 15

    Closing Slide 16

  • 8/13/2019 Config Pr Script

    2/9

    *H

    Text script for Device Configuration Page 2 of 9

    Slide 1: Introduction

    Microchip Technology welcomes you to the Device Configuration module of the

    PICmicro x14microcontroller. This module will give you a basic overview ofwhat the Device Configuration word is and how it is used. It is recommended

    that you are familiar with the PICmicro MCU x14 architecture and instruction set

    modules.

    Slide 2: Device Configuration

    PICmicro MCUs give the user the ability to configure several features of thedevice at programming time. This includes enabling features such as theWatchdog Timer (WDT), Brown out Reset (BOR), Power Up Timer (PWRT),

    code protection and Low Voltage programming, as well as selecting the type ofoscillator being used.

    This module will cover the basic configurable features, and how the Configuration

    Bits are used to set these features for your particular application. We will alsodiscuss how to use the _CONFIG directive in the MPASM assembler whichallows you to set the device configuration in your source code rather than

    choosing the options manually on the device programmer.

  • 8/13/2019 Config Pr Script

    3/9

    *H

    Text script for Device Configuration Page 3 of 9

    Slide 3: Configuration Word

    The Configuration Word is a group of non-volatile memory bits within the

    PICmicro MCU that are set at programming time. The state of these bitsdetermines how several features within the MCU will function when the device is

    operating. These bits are not part of program memory, and they are only

    accessible during device programming. The actual number of bits within theConfiguration word varies by family, and not all bits in the Configuration Word are

    implemented for all devices.

    Here you can see the Configuration Word options available for the PIC16F87XAfamily of microcontrollers.

    Starting at the right with the least significant bits, FOSC0 and FOSC1 are used toselect the type of oscillator you are using.

    Next is the Watchdog timer Enable (WDTEN) bit followed by the Power-up timer

    Enable bit (PWRTEN).

    Then we have the Brown-Out Reset Enable bit (BOREN), followed by the Low

    Voltage In-Circuit Serial Programming Enable (LVP) bit.

    CPD and CP are used to set the code protection for data memory and program

    memory, respectively.

    WRT0 and WRT1 are the write enable bits used to write protect portions of theFlash Program Memory, and the Debug bit allows access to the In-CircuitDebugger Mode.

    We will discuss the use of each of these functions in the following slides.

  • 8/13/2019 Config Pr Script

    4/9

    *H

    Text script for Device Configuration Page 4 of 9

    Slide 4: Oscillator Configuration

    Lets start with the FOSC0 and FOSC1, which are bit 0 and bit 1 of the

    Configuration Word, respectively. These two bits are used to set the oscillatormode for the device. Each mode provides varying amounts of oscillator gain for

    various oscillator designs, and each mode has different constraints on the

    minimum and maximum frequency that can be used.

    Note that the available oscillator configurations vary depending on the device, soit is important to check your device datasheet for the ones that apply to your

    device.

    For more specific information about the different oscillator modes and how to

    select the proper mode for your application, please consult the OscillatoreLearning module.

    Slide 5: Knowledge Check #1

    Q: The Configuration Word is:

    A) accessible only at device programming timeB) a group of non-volatile memory bits

    C) used to configure features of the device specific to the application it isbeing use for

    D) All of the above (correct answer)

    Slide 6: Watch Dog Timer

    The Watchdog Timer enable bit (WDTEN) determines if the Watchdog Timer is

    enabled at run time.

    The Watchdog Timer is an independent free running timer with its own onboardinternal RC oscillator. The WDT is typically used for one of 2 functions: to forcethe processor to reset itself if code execution becomes unstable, or to force the

    processor to wake from sleep mode on a periodic basis. A postscaler isavailable that will allow the user to increase the Watchdog timeout period if

    necessary.

    For more specific information about using the Watchdog timer, please consult the

    eLearning module on Resets.

  • 8/13/2019 Config Pr Script

    5/9

    *H

    Text script for Device Configuration Page 5 of 9

    Slide 7: Power-Up Timer

    The Power-up Timer Enable bit (PWRTE) enables the Power-Up Timer or

    PWRT. This timer is designed to hold the device in reset while the system powersupply stabilizes. This is done to prevent ambiguous operation when VDD has

    not reached a stable level. Like the Watchdog timer, the Power-up Timer

    operates on an internal RC oscillator and provides a nominal 72ms delay.

    Keep in mind that when a Brown-out Reset is used, on some devices the Power-Up Timer is automatically enabled, regardless of your settings. This allows the

    VDDto rise to an acceptable level after a Brown-Out Reset.

    Slide 8: Brown-out Reset

    The Brown Out Detect Enable bit (BOREN) in the Configuration Word is used to

    enable the Brown-Out Reset feature, also referred to as BOR.

    The purpose of a Brown-Out Reset is to trigger a reset of the CPU when VDD

    drops below a safe operating level. Once the BOR has been triggered, it willhold the device in reset for as long as VDDremains below the BOR trip point. On

    some devices, the BOR can be made to start the Power-up reset timer, to createa longer reset time for reliability.

    For more specific information about using the Brown-out Reset feature, pleaseconsult the eLearning module on Resets.

    Slide 9: Low Voltage ProgrammingOn some PICmicro devices, the Low Voltage Programming bit (LVP), in theconfiguration word enables Low Voltage Programming, also referred to as LVP.

    The LVP feature allows the device to be programmed with logic level signalsinstead of the traditional 13 Volts on VPP.

    It is important to note that when LVP is enabled, it dedicates the RB3 pin for useduring the Low Voltage Programming. A rising edge on RB3 followed by a rising

    edge on MCLR will cause the device to enter programming mode. Pleaseconsult the datasheet for details.

    Although LVP is enabled from the factory, the user can disable this feature if itwill not be used. If Low Voltage Programming is enabled, high voltage

    programming can still be used.

  • 8/13/2019 Config Pr Script

    6/9

    *H

    Text script for Device Configuration Page 6 of 9

    Slide 10: Knowledge Check #2

    Q: On some devices, the BOR can be made to?A) Enable the code protection bitsB) Start the Power-up reset timer (PWRT) for additional reset time

    (correct response)C) Reset the prescaler value to the largest value

    D) Enable low voltage programming (LVP)

    Slide 11: Code Protection

    The code protection bits set the code protection, which is a feature that providessome protection from program and data memory being read out, and in some

    cases, from being written over.

    Each microcontroller has different levels of code protection controlled by thecode protection bits. Because there are so many differences in the way the codeprotection is implemented from device to device, it is very important that you

    consult the data sheet of the device you are using to find out what codeprotection options are available and how to use them.

    For Flash devices such as the PIC16F873A, there are 2 different bits that controlthe code protection. These are CP, which is used to code protect theprogram

    memory and CPD, which is used to code protect the datamemory.

    For non-Flash devices such as the PIC16C74B, the code protection bits are

    defined as CP0 and CP1. These allow the user to select no code protection,upper half, upper or all program memory protected. We should also note that

    some devices have several sets of the CP0 and CP1 bits. These are redundantbits, but all of the CP0 bits must be programmed the same, and all the CP1 bitsmust be also programmed the same.

    Whether your MCU is Flash based or not , there are some important points to

    remember when using code protection. First, remember that that since codeprotection prevents the reading out of data, it is best to verify the part beforesetting the code protection bits.

    Second, it is important to note that each type of microcontroller has code

    protection limitations. For example, setting the code protection on a windoweddevice is a permanent change to that part. UV erasing the device will noterasethe code protection bits. For this reason we do not recommend code protecting

    windowed devices. However, FLASH microcontrollers are different. Setting thecode protection on a FLASH device is nota permanent change. You can disable

    the code protection after it has been set by executing a bulk erase.

  • 8/13/2019 Config Pr Script

    7/9

    *H

    Text script for Device Configuration Page 7 of 9

    Slide 12: Flash Program Memory (Write Enable)

    On Flash MCUs, there are also configuration bits to write protect portions of theprogram memory. These are the Flash program memory Write Enable bits,

    WRT0 and WRT1. Similar to the Code protection bits we spoke about in the last

    slide, these 2 bits allow a user to protect segments of Flash program memoryfrom being changed.

    Slide 13: DEBUG

    The DEBUG bit enables a feature available on some Flash based MCUs known

    as in-circuit debugging. This feature allows the use of the MPLAB ICD as a lowcost programmer and debugging tool.

  • 8/13/2019 Config Pr Script

    8/9

    *H

    Text script for Device Configuration Page 8 of 9

    Slide 14: Config Directive

    The last topic in this module that we will discuss is the __CONFIG assembler

    directive. This directive enables the configuration word to be set within aprograms source file rather than being set manually during device programming.

    When the code is assembled, the configuration word is included in the hex file.

    This reduces the chance that devices will be inadvertently programmed with theincorrect configuration settings.

    It is important to remember that the __CONFIG directive is only interpreted by

    the PRO MATE, PRO MATEII, and PICSTARTPlus programmers. Currently,the ICD and ICD2 are not able to interpret this directive.

    This piece of code shows an example of the __CONFIG directive in use. Noticethat the __CONFIG directive is preceeded by a space or tab. If a space or tab is

    not present a warning message will appear stating that the __CONFIG directiveis in column 1. Also note that there are 2 underscores in front of the __CONFIG

    word, not just one.

    The specific configuration bits are separated by the ampersand and it does not

    matter what order they are listed in.

    In this example we have the following configuration bits set:

    Code Protection is turned off,the Watchdog Timer is disabled,

    and both the Brown-Out Reset feature and the Power-Up Timer are on.

    The RC oscillator mode is selected,

    Flash Program Memory Write is On,Low Voltage Programming is enabled,

    In-Circuit Debugging Mode is off,and Code protection for Data EEPROM Memory is off.

    Although it is not necessary to specify all of the configuration bits when using the__CONFIG directive, it is very important to understand that any of the

    configuration bits not called out in the directive will be programmed to a logicone. In this case, you should always consult the datasheet and understand whateffect a logic one has for each of the configuration bits.

  • 8/13/2019 Config Pr Script

    9/9

    *H

    Text script for Device Configuration Page 9 of 9

    Slide 15: Knowledge Check #3

    Q: The __CONFIG assembler directive can be used for:

    A) Erasing all program memory in a Flash based MCU

    B) Setting Configuration Bits in source codeC) Disabling the feature that erases program memory if the VDD level drops

    below a safe operating levelD) All of the above

    Slide 16: Closing Slide

    This concludes the basic module on PICmicro Device Configuration. We hopeyou found this presentation interesting and worthwhile. If you have comments

    about this presentation or any other topic concerning Microchips eLearningProgram, you can send your comments by clicking on the Feedback link on the

    left side of this screen.