With Config bits in microcontroller-based projects

in Technology

Microcontrollers generally have a specific purpose to be paid, so while they are very flexible devices these days, there are a number of different (often conflicting) options for how you want to work the hardware. One might think that this configuration is done in software, but what if the hardware you want to be a certain way from the start? If you consider that Microchip PIC devices can "boot" in a matter of milliseconds, it has a way to tell the hardware as it will act in advance of the start-up. This article is about how you work your microcontroller project, how do you expect when it is launched.

Enter config bits, or, as it was then called, config backups. Back in the days when microcontroller program once were devices that you have really blow a fuse to program it. Today, most micros have flash memory, the program can sometimes be tens of thousands, but there are one-time-programmable (OTP) of devices.

In any case, there are a number of "config words," as the mic is from the get-go behavior defined. Let's look at some of these options (we select the PIC18F2620 for example) and then see how to program them. Source Boost gives you all the config string in a ready-to-use format for inclusion in your project. The format has the config bits with the same name as the config word so you can ensure that the right bits will be appended to the word. Of course, your config will be different words, if you are a different microcontroller, but you should learn enough here to keep you in the right direction.

In the 18F2620, the config bits are stored in the flash, but at a high space. They are mounted on 0x300001 and up. For historical reasons due to the type of store previously was located on PIC MCU, config words with each number with a "high" and "low" numbered byte.

CONFIG1L do not exist on the 18F2620. If so, it would be live on location 0x300000.

CONFIG1H contains bits that indicate oscillator options. Generally in embedded projects, we try and provide external Adventures crystals, the more accurate and reliable results. This does use up two pins, however, and sometimes these more important than the speed at which the chip runs. The external crystal oscillator is referred to as the HS oscillator (if you're doing the typical thing to try to run the accounts as soon as it goes). In the 18F2620, you can also use the PLL module that allows you to increase a four-fold speed. From CONFIG1H are also options to allow the Fail-Safe Clock Monitor (that the switch to the internal oscillator, the external should fail, and to allow an option to switch between different oscillator sources.

Generally, we recommend that you use an external crystal oscillator and disable all switch / failover modes. In prototyping, it is important, reliable, reproducible results have (mostly so you can reduce the axes of the error). It is possible to configure the 18F2620 so start with the internal oscillator (which runs at 8MHz or 32MHz with PLL enabled) and then switch to the external one (we use a 10MHz crystal with PLL enabled you 40Mhz). This gives you faster startup of interrupts in sleep mode or when you boot, but it's important for prototyping, this is not usually necessary.

Our recommended config string for CONFIG1H:


CONFIG2L handles Brown-out reset and power timer. Brown Out Reset (BOR or) is the ability for the microcontroller is reset when the supply voltage falls below a certain threshold. It will remain in the reset state until the supply goes back over the threshold. This may mean some energy saving mode (at least if the battery is flat over a certain level, it will stop draining power as quickly) - but at this point there is no functionality available anyway. The power depends on timer waits for first power-on to the supply voltage going through the BOR threshold, then for another 65ms before kicking things off for real. This can help ensure that your power supply is stable before you execute arbitrary code.

We have seen some pretty unexpected results from testing some of the 18F2620 LED display panels. We thought the software to crash or to reset the account, when in fact what happened was, when several LEDs are lit and the power supply was BOR was being thrown. As such, unless you have a real need was for him, off we recommend. Leave the power supply before to regulate the firmware is generally a good idea (you are probably not the 65ms it takes notice).


CONFIG2H gives you the settings for the watchdog timer. This is a timer that PIC is in a certain time (you can largely determine how long that might be). It could plan well in order to reset your PIC, you have to do something that you may never again - although hopefully you're well written enough code that can not happen! Alternatively, the watchdog timer and remove the PIC24 from sleep mode. This means you can be open for the PIC to go to sleep for some time (if nothing else happens). For prototyping, we recommend switching off the watchdog timer. If you want to make it, you must reset the watchdog timer or a regular basis - you guessed well, you know what will happen.

# Pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H

CONFIG3H has a collection of configuration items. You can look for the RE3 pin select available (as input) or for the MCLR pin to be (which is considered the accounts for low). reset for prototyping, the ability to keep accounts by pressing a button is easier than pulling out of power.

The LPT1OSC bit is the possibility of a "high power" mode or a "low-power mode. The low-power mode is more sensitive in noisy environments. So if battery power is very important, you must carefully design your circuit. For prototyping of course, we recommend leaving them in high power mode.

PBABE, can you specify if PORTB pins 0-4 should wake up on reset as analog or digital input pins pins. Of course, you can be in the software change in the ADCON1 register at any time.

The CCP lcm is a Capture / Compare / PWM module and a final CONFIG3H bit allows the "control" the output to be either RC1 or RB3. The change is to be practical in a position where you need the other functions on one of these pins (RB3 is also analog input 9 and RC1 can be Timer 1 oscillator input). Alternatively, your PCB layout easier if this output could be on one or the other to move. For prototyping, in general, this is not relevant or so.


CONFIG4L contains some interesting and shows very clearly how important it is in a position to which the PIC is configured before use.

The DEBUG bit enables hardware debugging. You can step code, set breakpoints and so on - if you have your software set correctly and delete this bit. Hardware debugging requires the exclusive use of RB6 and RB7 (for ICSP programming is used). In all honesty, we find that serial output is usually sufficient to find fault, although you can debug many PICs with just a PICkit2.

XINST 18F allows extended instruction set mode. This is not used by source and boost when you turn it on by mistake (regardless of the compiler you use) it will be some rather unpredictable results. One of our readers for days trying to figure out what was wrong with his code to recognize only the XINST bit is set.

LVP gives you the opportunity to the PIC with ICSP, without the "higher" VPP program. There is a catch however - you need to RB5 pin (PGM) is not only an ad if you are in programming mode or not pay. Given the PICkit2 the correct voltage generated anyway, it does not seem too much value in switching to this for prototyping purposes.

Finally, the STVREN the opportunity to reset the PIC, when the overflow or underflow of the stack. When you call, for example, too many nested functions, it would allow the PIC reset. After the reset, you can check why the PIC reset and report an error. We recommend leaving this on - if you do PIC boots in the middle of something, you can reasonably assume that you have the stack (possible if you are deeply nested in a situation and then a break occurs) is used.


CONFIG5L is the possibility of indicating whether one of the four contiguous blocks of memory from any attempts to change the PIC are protected (eg writing) the flash memory values.

# Pragma DATA _CONFIG5L, _CP0_OFF_5L _CP1_OFF_5L & & & _CP2_OFF_5L _CP3_OFF_5L

CONFIG5H give the opportunity to protect the block of memory from 0x0000 to 0x7FFF) - used by some boot loader, and a little to allow the protection of the EEPROM memory. The PicPack bootloader "Boostbloader," lives in the upper memory, which means that, although somewhat less robust than one-down, locked physically protected boot loader, it does not require the "double jump" to interrupt the boot loader in the lower memory Thurs . We can use this as an option in the future.


CONFIG6L allows protection of protected memory blocks to write.

# Pragma DATA _CONFIG6L, _WRT0_OFF_6L _WRT1_OFF_6L & & & _WRT2_OFF_6L _WRT3_OFF_6L

CONFIG6H, CONFIG7L CONFIG7H and give more granular protection, so that memory blocks when the code is protected not running in the same block. We could, for example, a boot loader was "secret" and not be ready by another code.




While strictly speaking they are not config words, let the code DEVID words to determine which model is the chip and the hardware revision. This is important if there are errors in the hardware that are fixed on different levels of review, and code must perform differently based on the result.

Making configs

You have probably worked by now that the boost source compiler config's are designed wise defined, so you simply and together the appropriate options, which means you do not need to work, the exact bit positions to do something. The # pragma DATA offers the possibility of a byte to a specific place slide (in our case, in a config word slot).

Other PICs

Here is the config we use the PIC16F88:


Yep, that's right, there is only one word long. Some of these options will most likely already know.


If your chip does not behave and you want to work when you've made a mistake in the config bits and handy hint is to use Microsoft's MPLAB IDE to import the.hex file you have created by pressing the Menu | Import. .. then click Configure | Configuration Bits ... Here is the screen you see when you import the PIC18F2620 BoostBloader will.

You can even set the config bits if you want, then export as a.hex file, even though in mind this does not change your source code to stop himself.

What you have is probably realized that the boot loader is embedded bits in the.hex definitely config file. Our usual not PicPack programs - as we expect, you are installed with a bootloader running. If you want to program directly with ICSP, of course, you have to config bits to run your PIC as you want. Check out the file used by configbits.h Boostbloader - we start building a library of handy config bits including some configuration options for things together on and off (you of course in the config.h file in your project).


Author Box
zerryxu has 73 articles online

led driver, infineon mcu

Add New Comment

With Config bits in microcontroller-based projects

Log in or Create Account to post a comment.
Security Code: Captcha Image Change Image
Related searches:

With Config bits in microcontroller-based projects

This article was published on 2011/03/02