Config PR Script
Config PR Script
Page 1 of 9
*H
Slide 1: Introduction Microchip Technology welcomes you to the Device Configuration module of the PICmicro x14 microcontroller. This module will give you a basic overview of what 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 the device at programming time. This includes enabling features such as the Watchdog Timer (WDT), Brown out Reset (BOR), Power Up Timer (PWRT), code protection and Low Voltage programming, as well as selecting the type of oscillator 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 also discuss how to use the _CONF IG directive in the MPASM assembler which allows you to set the device configuration in your source code rather than choosing the options manually on the device programmer.
Page 2 of 9
*H
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 bits determines 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 the Configuration 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 PIC16F87XA family of microcontrollers. Starting at the right with the least significant bits, FOSC0 and FOSC1 are used to select 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 the Flash Program Memory, and the Debug bit allows access to the In-Circuit Debugger Mode. We will discuss the use of each of these functions in the following slides.
Page 3 of 9
*H
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 oscillator mode 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, so it 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 Oscillator eLearning module. Slide 5: Knowledge Check #1 Q: The Configuration Word is: A) accessible only at device programming time B) a group of non-volatile memory bits C) used to configure features of the device specific to the application it is being 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 onboard internal RC oscillator. The WDT is typically used for one of 2 functions: to force the 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 is available 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.
Page 4 of 9
*H
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 power supply 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 PowerUp Timer is automatically enabled, regardless of your settings. This allows the VDD to 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 V DD drops below a safe operating level. Once the BOR has been triggered, it will hold the device in reset for as long as V DD remains below the BOR trip point. On some devices, the BOR can be made to start the Power-up reset timer, to create a longer reset time for reliability. For more specific information about using the Brown-out Reset feature, please consult the eLearning module on Resets. Slide 9: Low Voltage Programming On some PICmicro devices, the Low Voltage Programming bit (LVP), in the configuration word enables Low Voltage Programming, also referred to as LVP. The LVP feature allows the device to be programmed with logic level signals instead of the traditional 13 Volts on V PP. It is important to note that when LVP is enabled, it dedicates the RB3 pin for use during the Low Voltage Programming. A rising edge on RB3 followed by a rising edge on MCLR will cause the device to enter programming mode. Please consult the datasheet for details. Although LVP is enabled from the factory, the user can disable this feature if it will not be used. If Low Voltage Programming is enabled, high voltage programming can still be used.
Page 5 of 9
*H
Slide 10: Knowledge Check #2 Q: On some devices, the BOR can be made to? A) Enable the code protection bits B) 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 provides some 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 the code protection bits. Because there are so many differences in the way the code protection 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 code protection options are available and how to use them. For Flash devices such as the PIC16F873A, there are 2 different bits that control the code protection. These are CP, which is used to code protect the program memory and CPD, which is used to code protect the data memory. 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 redundant bits, but all of the CP0 bits must be programmed the same, and all the CP1 bits must 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 code protection prevents the reading out of data, it is best to verify the part before setting 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 windowed device is a permanent change to that part. UV erasing the device will not erase the code protection bits. For this reason we do not recommend code protecting windowed devices. However, FLASH microcontrollers are different. Setting the code protection on a FLASH device is not a permanent change. You can disable the code protection after it has been set by executing a bulk erase.
Page 6 of 9
*H
Slide 12: Flash Program Memory (Write Enable) On Flash MCUs, there are also configuration bits to write protect portions of the program memory. These are the Flash program memory Write Enable bits, WRT0 a nd 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 memory from 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 low cost programmer and debugging tool.
Page 7 of 9
*H
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 a programs 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 the incorrect configuration settings. It is important to remember that the __CONFIG directive is only interpreted by the PRO MATE , PRO MATE II, and PICSTART Plus 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. Notice that 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 directive is 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 logic one. In this case, you should always consult the datasheet and understand what effect a logic one has for each of the configuration bits.
Page 8 of 9
*H
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 code C) Disabling the feature that erases program memory if the VDD level drops below a safe operating level D) All of the above Slide 16: Closing Slide This concludes the basic module on PICmicro Device Configuration. We hope you found this presentation interesting and worthwhile. If you have comments about this presentation or any other topic concerning Microchips eLearning Program, you can send your comments by clicking on the Feedback link on the left side of this screen.
Page 9 of 9