Saturday, April 14, 2012

Using Config Bits appearing in Microcontroller Based Projects

Microcontrollers attend to to take place fanatical to a detail drive, so while they'on the subject of very flexible strategy these days, at hand are a amount of various (often conflicting) options in lieu of how you might need the hardware to handiwork. You might think with the aim of this configuration is complete fashionable software, but could you repeat that? if you want the hardware to proceed a assured way from the very start? Keeping in mind with the intention of C.P.U PIC diplomacy can "riding boot" in a carry some weight of milliseconds, in attendance needs to be present a way you indicative the hardware how to perform in advance of it opening up. This article covers how to understand your microcontroller based project working the way you expect what time it starts up.

Enter config bits, before, seeing that they used to occur called, config fuses. Back inwards the days as soon as microcontrollers were syllabus-as soon as campaign, you really did blow a fuse in order to program them. now, for the most part micros partake of flare recall with the intention of can be planned tens of thousands of period, but in attendance are still single-period-programmable (OTP) procedure all but.

In one court case, near's a bunch of "config terminology" to facilitate describe how the micro is going away to conduct yourself from the induce-stretch. accede to's look by the side of a number of of these options (we'll select the PIC18F2620 so an model) and therefore perceive how to list them. Sourceboost gives you all the config strings featuring in a standing by-to-utilize format on behalf of together with in your project. The format has the config bits suffixed with the same famous person as the config word so you can ensure with the purpose of the accurately bits are departure in the right word. Of course of action, your config language yearn for survive discrete if you'on the subject of using a different microcontroller, but you be supposed to study as much as necessary at this time to promontory you during the right direction.

In the 18F2620, the config bits are stored in twinkle, but next to a great recall location. They'a propos stored on 0x300001 and upwards. intended for historical reasons due to the way remembrance was previously arranged on PIC microcontrollers, config expressions are numbered with every add up to having a "high" and "low" byte.

CONFIG1L doesn't exist on the 18F2620. If it did, it would live by 0x300000 location.

CONFIG1H contains bits so as to spell out oscillator options. commonly, into Embedded Adventures projects we try and value peripheral crystals which offer supplementary accurate and steadfast results. This does use up two pins however, and on occasion these can subsist new essential than the hurry by which the disfigure is running. The outdoor gemstone oscillator is referred to in the function of the HS oscillator (if you'pertaining to responsibility the classic obsession of frustrating to run the micro as fast as it want get to). into the 18F2620, you can too enable the PLL module which will allot you a four-epoch break the speed limit boost. From CONFIG1H are besides options to enable the fail-safe control screen (with the purpose of switches to the domestic oscillator be supposed to the outer solitary fail, and an option to enable the switching among atypical oscillator sources.

We usually advise with the purpose of you utilization an peripheral rock, and roll inedible one oscillator switching / failover modes. arrived prototyping, it is weighty to partake of steadfast, repeatable results (mostly so you can reduce the axes of miscalculation). It is probable to configure the 18F2620 to start up using the interior oscillator (which runs by 8Mhz, otherwise 32Mhz with the PLL enabled) and subsequently switch to the outside lone (we use a 10Mhz sparkler with PLL enabled giving you 40Mhz). with the aim of gives you nearer startup from interrupts featuring in nap mode before on bootup, if that's valuable, however in support of prototyping, this is normally not essential.

Our recommended config row for CONFIG1H:

#pragma DATA _CONFIG1H, _OSC_HSPLL_1H & _IESO_inedible_1H & _FCMEN_OFF_1H

CONFIG2L handles bronzed-exposed reset and the power up timer. Brown Out Reset (or else BOR) is the talent on behalf of the microcontroller to reset itself if the supply voltage cascade under a specified threshold. It self-control wait all the rage reset state until the supply goes back completed the threshold. This can mean a number of battery saving (on slightest, formerly the battery is preset ahead of a selected level, it'll be over draining power in the role of quickly) - but on with the intention of use present's veto functionality open anyway. The power on timer waits on first power-on used for the supply to travel more than the BOR voltage threshold, at that moment hangs around for an additional 65ms in advance kicking things rotten for real. This can help ensure with the aim of your power supply is steady before annoying to accomplish several code.

We grasp seen around pretty unpredictable results from the 18F2620 while tough some LED put on show panels. We concept the software was rolling or else resetting the micro while stylish information, could you repeat that? was event was the BOR was being tripped to the same extent additional LEDs were lit and the power supply dropped. As such, but for you've got a real need in support of it, we advise switching it inedible. Leaving the power supply to settle formerly preliminary the firmware, is by and large a satisfactory suggestion (you'relating to probably not disappearing to notice the 65ms it takes).

#pragma DATA _CONFIG2L, _BOREN_inedible_2L & _BORV_2_2L & _PWRT_ON_2L

CONFIG2H gives you settings used for the watchdog timer. This is a timer with the purpose of resets the PIC in the sphere of a precise amount of occasion (you can broadly detail how slow that might transpire). It might be good chart to reset your PIC if you'about burden something from which you might on no account recover - although confidently you're in print good a sufficient amount code with the aim of this cannot go off! on the other hand, the watchdog timer can as well tug the PIC shown of have a lie-down mode. This channel you can display in favor of the PIC to operate to sleep for a several amount of phase (if nothing as well happens). For prototyping, we advise switching the watchdog timer rotten. If you figure out enable it, make up certainly you reset the watchdog timer steadily before - well, you can deduction I beg your pardon? force transpire.

#pragma DATA _CONFIG2H, _WDT_sour_2H & _WDTPS_128_2H

CONFIG3H has a collection of configuration items. You can point out intended for the RE3 pin to exist open (when input merely) before for with the intention of pin to be MCLR (which resets the micro as soon as pulled low). For prototyping, being able to reset the micro by critical a button is easier than pulling the power ready.

The LPT1OSC tad gives the option of a "area of high pressure power" mode or else a "low power mode". The low power mode is supplementary delicate happening high blare environments. So if battery practice is very essential, you need to design your circuit carefully. representing prototyping, of pattern, we would vouch for leaving this in high power mode.

PBABEN, allows you to list if PORTB pins 0 - 4 be supposed to wake up what analog input pins or else digital pins in the lead reset. Of course you can adjust this popular software in the ADCON1 register on a few calculate.

The CCP module is a Capture / Compare / PWM module and a final CONFIG3H fragment allows the "steering" of this output to ensue on either RC1 before RB3. This is within reach to be able to change if you require the other functionality open on solitary of these pins (RB3 is besides analogue input 9 and RC1 can be Timer 1 oscillator input). on the other hand, your PCB arrangement might happen easier if you may well move this output to lone before the other. instead of prototyping, in the main this doesn't problem either way.

#pragma DATA _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_inedible_3H & _MCLRE_ON_3H

CONFIG4L contains various appealing options and shows very openly how worthy it is to ensue able to configure the PIC already startup.

The DEBUG smidgen allows hardware debugging. You can step through code, stage set breakpoints and so on - if you get your software set right and this tad unfurnished. Hardware debugging and requires the exclusive advantage of RB6 and RB7 (also used in place of ICSP brainwashing). now all honesty, we uncover to ongoing output is in general sufficient to find bugs, although you can debug a batch of PICs with just a PicKit2.

XINST allows for the 18F extended education set mode. This isn't used by Sourceboost and if you switch it on by underestimate (despite the consequences of the compiler you'on the subject of using) near desire be alive several pretty unpredictable results. single of our readers spent days tiresome to unearth what did you say? was mistaken with his code merely to realise the XINST morsel was unyielding.

LVP gives you the gift to curriculum the PIC using ICSP lacking requiring the "elevated" Vpp voltage. in attendance is a catch however - you need to dedicate the RB5 pin (PGM) to being an indicator if you are within indoctrination mode or else not. particular the PicKit2 generates the genuine voltage anyway, here doesn't seem to be real a plight of profit in switching this on instead of prototyping purposes.

to end with, the STVREN gives the option of having the PIC reset if the stack overflowed or else underflowed. If, for paradigm, you call too many nested functions, it would allow the PIC to reset. one time reset, you can examine why the PIC reset and present yourself a fault. We counsel leaving this on - if your PIC boots participating in the hub of responsibility something, you can sensibly simulate with the purpose of you've used up the stack pause (likely at what time you'a propos deep in a nested location and in that case an interrupt occurs).

#pragma DATA _CONFIG4L, _STVREN_ON_4L & _LVP_sour_4L & _DEBUG_OFF_4L & _XINST_sour_4L

CONFIG5L gives the option of specifying if whichever solitary of four neighboring blocks of recollection are protected from any attempts by the PIC to alter (to be exact note down) the burst reminiscence ideals.

#pragma DATA _CONFIG5L, _CP0_sour_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_inedible_5L

CONFIG5H givest the option of caring the jam of reminiscence preliminary on 0x0000 to 0x7fff) - used by approximately bootloaders, like well as a spot to allow the protection of EEPROM recollection. The PicPack bootloader, "Boostbloader", resides appearing in higher recollection, import with the aim of while it is to some extent a smaller amount robust than a safe-down, physically protected bootloader, it doesn't require the "twin vault" in support of interrupts to bootloaders located in drop recollection accomplish. We may possibly provide this being an option in the hope.

#pragma DATA _CONFIG5H, _CPB_rancid_5H & _CPD_OFF_5H

CONFIG6L allows the protection of recollection blocks being send a letter to protected.

#pragma DATA _CONFIG6L, _WRT0_rancid_6L & _WRT1_OFF_6L & _WRT2_sour_6L & _WRT3_OFF_6L

CONFIG6H, CONFIG7L and CONFIG7H assign further granular protection, allowing blocks of reminiscence to be situated protected from whilst the code being executed is not concerning the same oppose. We might, in favor of exemplar, build a bootloader so as to was "secret" and unable to be timely by several other code.

#pragma DATA _CONFIG6H, _WRTC_rotten_6H & _WRTB_OFF_6H & _WRTD_sour_6H

#pragma DATA _CONFIG7L, _EBTR0_inedible_7L & _EBTR1_OFF_7L & _EBTR2_sour_7L & _EBTR3_OFF_7L

#pragma DATA _CONFIG7H, _EBTRB_rancid_7H

While narrowly speaking they'regarding not config language, the DEVID words allow code to determine which prototypical of the damage is running and which hardware revision. This is vital once at hand are bugs fashionable the hardware with the purpose of are fixed in excess of poles apart revision levels and code needs to kill differently based on the outcome.

Making configs

You've probably worked old hat by at this moment with the purpose of the Sourceboost compiler's config defines are expertly conceived so that you can simply & laid back the appropriate options; this wealth you don't need to be successful out exactly which spot positions act pardon?. The #pragma DATA gives you the skill to shove a byte happening a individual location (in our circumstances, into a config word slot).

Other PICs

at this juncture's the config we depletion with the PIC16F88:

#pragma DATA _CONFIG, _CP_sour & _CCP1_RB0 & _DEBUG_OFF & _WRT_safeguard_inedible & _CPD_OFF & _LVP_OFF & _PWRTE_sour & _WDT_OFF & _PWRTE_ON & _BODEN_rotten &_MCLR_ON & _INTRC_IO

Yep, with the intention of's privilege, it's solely individual word sustained. nearly of these options willpower probably be present familiar to you already.


If your damage is not behaving and you fancy to effect impossible if you've made a faux pas hip your config bits, and dexterous hint is to use Microsoft's MPLAB IDE to import the.magic charm box file you've produced by clicking on Menu | Import... next Configure | Configuration Bits... at this point's the screen you'll discover while importing the PIC18F2620 BoostBloader.

You can even variation the config bits if you would like, it follows that export again in the function of a.magic charm file, although keep happening mind this doesn't change your source code itself.

what did you say? you've probably realised at this point is with the purpose of the bootloader categorically has config bits embedded in the.curse line. Our usual PicPack programs don't - since we simulate you'with regard to running with a bootloader already installed. If you work out neediness to predetermine candidly with ICSP, of stream you'll need to benefit config bits to be selected for your PIC run the way you be determined. Check banned the configbits.h file used by Boostbloader - we'concerning early to build up a files of near config bits as well as particular configuration options to veer for all things on or else rotten (these you effortlessly place taking part in the config.h dossier in your project).

Electronic Circuit is a good site for hobbyist also who would like to try DIY because it shared good circuits.