Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sharing experience about PIC configurarion bits

Status
Not open for further replies.

MrNobody

New Member
Hi,
I was reading about configuration bits and was trying to think about it from the perspective of real-world applications where the execution of the PIC needs to be foolproof in the sence that it as stable as it is designed for. For example, I read that if the VDD of the PIC gets below a certain level, depending on what situation/setting the PIC is used, it may run in an unstable manner. Because of that, we enable BOR right?

There are few fuses that I need inputs on whether to use it or not. So, if you are free, please share your experience related to using the fuse. Below are my thoughts on the different fuses.

Oscillator - Internal or external?:
If internal oscillator is used, then there are 3 to 4 less components on the board and that safe cost. So far, unless the PIC is used to perform tasks that requires perfect timing such as UART or any serial communication, then using Internal oscillator is fine because internal oscillator is not as accurate as external oscillator. How about power consumption? Is there any major differences? Any other thoughts?


Watchdog Timer:
Well, don't really use it. If the code is bug free and everything seems to perform well during testing, there is no reason to use WDT to reset the PIC is there?

Power Up Timer:
Use it so that the PIC will start executing the instructions when everythhing is stable. The timer gives the PIC time to stablelize.

MCLR - Enable or disable:
Well, if the product is ready for market and the code is finalise, there is no reason to enable the MCLR pin is there? Besides, enableing it means that we have less I/O pin to use. So, if everything is well, I would not enable it.

Code Protect:
I'm not sure about this. I heard that even though the code protest feature is set, the code can still be read by removing a layer of the PIC. How true is that? Can somebody please confirm?

Brown Out Reset:
I would enable it but will let SBOREN to control the BOR function.

Internal/External Switch Over Mode:
I would enable it if the PIC spends most of its time in sleep mode and only wake up to execute few instructions before it goes back to sleep so that it consumes less power.

Monitor Clock Fail-safe:
Well, what is the chances of external oscillation malfunctioning? So, is there really a need to enable this fuse? Besides, enableing it would mean that the internal oscillator is running as well as the external oscillator because the external oscillation is compared to the internal oscillation. This will comsume more power wouldn't it?
 
Watchdog Timer:
Well, don't really use it. If the code is bug free and everything seems to perform well during testing, there is no reason to use WDT to reset the PIC is there?

Bug free code? Testing procedures that test all possible states? Those would be nice but back in the real world, any non-trivial bit of code has the potential for bugs, and testing cannot always find them.

I would always leave the WDT on in finished code.
 
Internal/External Switch Over Mode:
I would enable it if the PIC spends most of its time in sleep mode and only wake up to execute few instructions before it goes back to sleep so that it consumes less power.

I don't think that you need to enable this if you want to use the sleep command. Using the sleep command doesn't change the clock speed, it just stops completely.
 
Thanks for the inputs.

Diver300:
I was reading the "Two-Speed Clock Start-up Mode" in the link below
https://www.mikroe.com/en/books/picmcubook/ch8/. Below is an excerpt from there explainaing on Sleep and Wake-up. Hope it helps to clarify what i was trying to say.

When conditions for wake-up are met, the microcontroller will not immediately start operating because it has to wait for clock signal frequency to become stable. Such delay lasts for exactly 1024 pulses. After that, the microcontroller proceeds with program execution. The problem is that very often only a few instructions are performed before the microcontroller is set up to Sleep mode again. It means that most of time as well as power obtained from batteries is wasted. This problem is solved by using internal oscillator for program execution while these 1024 pulses are counted. Afterwards, as soon as the external oscillator frequency becomes stable, it will automatically take over the “leading role”. The whole process is enabled by setting one bit of the configuration word. In order to program the microcontroller it is necessary to select the Int-Ext Switchover option in software.
 
My thoughts,

Oscillator - Internal or external?:
The internal oscillator is more than adequate for most tasks including serial communication. It's only really clock type circuits that need the accuracy of a crystal. OTOH, one reason to use an external crystal is the increase in speed available.

Watchdog Timer:
Always enable this in finished code. I know that I write bug free code :D and so don't worry about it. However, I have no control over nearby lightening strikes which may corrupt my variables and cause a hang.

Monitor Clock Fail-safe:
I like this feature. I recently designed a GLCD serial board and if you put a crystal on the board it runs at 20MHz, no crystal and it switches to the internal oscillator at 8MHz. The choice is left with the end user.

Mike.
 
And, whilst we're talking about configuration bits,

Did you know you can type
mcc18 --help-config -p=18f4550
in a dos window and you get the configuartion settings for whichever pic (18 only) you put in the command.

The above returns,
C:\MCC18>mcc18 --help-config -p=18f4550
Configuration settings available for processor 18F4550
PLL Prescaler Selection bits:
PLLDIV = 1 No prescale (4 MHz oscillator input drives PLL directly)
PLLDIV = 2 Divide by 2 (8 MHz oscillator input)
PLLDIV = 3 Divide by 3 (12 MHz oscillator input)
PLLDIV = 4 Divide by 4 (16 MHz oscillator input)
PLLDIV = 5 Divide by 5 (20 MHz oscillator input)
PLLDIV = 6 Divide by 6 (24 MHz oscillator input)
PLLDIV = 10 Divide by 10 (40 MHz oscillator input)
PLLDIV = 12 Divide by 12 (48 MHz oscillator input)

CPU System Clock Postscaler:
CPUDIV = OSC1_PLL2 [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
CPUDIV = OSC2_PLL3 [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
CPUDIV = OSC3_PLL4 [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4]
CPUDIV = OSC4_PLL6 [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6]

USB Clock Selection bit (used in Full Speed USB mode only; UCFG:FSEN = 1):
USBDIV = 1 USB clock source comes directly from the primary oscillator block with no postscale
USBDIV = 2 USB clock source comes from the 96 MHz PLL divided by 2

Oscillator Selection bits:
FOSC = XT_XT XT oscillator, XT used by USB
FOSC = XTPLL_XT XT oscillator, PLL enabled, XT used by USB
FOSC = ECIO_EC External clock, port function on RA6, EC used by USB
FOSC = EC_EC External clock, CLKOUT on RA6, EC used by USB
FOSC = ECPLLIO_EC External clock, PLL enabled, port function on RA6, EC used by USB
FOSC = ECPLL_EC External clock, PLL enabled, CLKOUT on RA6, EC used by USB
FOSC = INTOSCIO_EC Internal oscillator, port function on RA6, EC used by USB
FOSC = INTOSC_EC Internal oscillator, CLKOUT on RA6, EC used by USB
FOSC = INTOSC_XT Internal oscillator, XT used by USB
FOSC = INTOSC_HS Internal oscillator, HS used by USB
FOSC = HS HS oscillator, HS used by USB
FOSC = HSPLL_HS HS oscillator, PLL enabled, HS used by USB

Fail-Safe Clock Monitor Enable bit:
FCMEN = OFF Fail-Safe Clock Monitor disabled
FCMEN = ON Fail-Safe Clock Monitor enabled

Internal/External Oscillator Switchover bit:
IESO = OFF Oscillator Switchover mode disabled
IESO = ON Oscillator Switchover mode enabled

Power-up Timer Enable bit:
PWRT = ON PWRT enabled
PWRT = OFF PWRT disabled

Brown-out Reset Enable bits:
BOR = OFF Brown-out Reset disabled in hardware and software
BOR = SOFT Brown-out Reset enabled and controlled by software (SBOREN is enabled)
BOR = ON_ACTIVE Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
BOR = ON Brown-out Reset enabled in hardware only (SBOREN is disabled)

Brown-out Voltage bits:
BORV = 0 Maximum setting
BORV = 1
BORV = 2
BORV = 3 Minimum setting

USB Voltage Regulator Enable bit:
VREGEN = OFF USB voltage regulator disabled
VREGEN = ON USB voltage regulator enabled

Watchdog Timer Enable bit:
WDT = OFF HW Disabled - SW Controlled
WDT = ON HW Enabled - SW Disabled

Watchdog Timer Postscale Select bits:
WDTPS = 1 1:1
WDTPS = 2 1:2
WDTPS = 4 1:4
WDTPS = 8 1:8
WDTPS = 16 1:16
WDTPS = 32 1:32
WDTPS = 64 1:64
WDTPS = 128 1:128
WDTPS = 256 1:256
WDTPS = 512 1:512
WDTPS = 1024 1:1024
WDTPS = 2048 1:2048
WDTPS = 4096 1:4096
WDTPS = 8192 1:8192
WDTPS = 16384 1:16384
WDTPS = 32768 1:32768

MCLR Pin Enable bit:
MCLRE = OFF RE3 input pin enabled; MCLR disabled
MCLRE = ON MCLR pin enabled; RE3 input pin disabled

Low-Power Timer 1 Oscillator Enable bit:
LPT1OSC = OFF Timer1 configured for higher power operation
LPT1OSC = ON Timer1 configured for low-power operation

PORTB A/D Enable bit:
PBADEN = OFF PORTB<4:0> pins are configured as digital I/O on Reset
PBADEN = ON PORTB<4:0> pins are configured as analog input channels on Reset

CCP2 MUX bit:
CCP2MX = OFF CCP2 input/output is multiplexed with RB3
CCP2MX = ON CCP2 input/output is multiplexed with RC1

Stack Full/Underflow Reset Enable bit:
STVREN = OFF Stack full/underflow will not cause Reset
STVREN = ON Stack full/underflow will cause Reset

Single-Supply ICSP Enable bit:
LVP = OFF Single-Supply ICSP disabled
LVP = ON Single-Supply ICSP enabled

Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit:
ICPRT = OFF ICPORT disabled
ICPRT = ON ICPORT enabled

Extended Instruction Set Enable bit:
XINST = OFF Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
XINST = ON Instruction set extension and Indexed Addressing mode enabled

Background Debugger Enable bit:
DEBUG = ON Background debugger enabled, RB6 and RB7 are dedicated to In-Circuit Debug
DEBUG = OFF Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins

Code Protection bit Block 0:
CP0 = ON Block 0 (000800-001FFFh) code-protected
CP0 = OFF Block 0 (000800-001FFFh) not code-protected

Code Protection bit Block 1:
CP1 = ON Block 1 (002000-003FFFh) code-protected
CP1 = OFF Block 1 (002000-003FFFh) not code-protected

Code Protection bit Block 2:
CP2 = ON Block 2 (004000-005FFFh) code-protected
CP2 = OFF Block 2 (004000-005FFFh) not code-protected

Code Protection bit Block 3:
CP3 = ON Block 3 (006000-007FFFh) code-protected
CP3 = OFF Block 3 (006000-007FFFh) not code-protected

Boot Block Code Protection bit:
CPB = ON Boot block (000000-0007FFh) code-protected
CPB = OFF Boot block (000000-0007FFh) not code-protected

Data EEPROM Code Protection bit:
CPD = ON Data EEPROM code-protected
CPD = OFF Data EEPROM not code-protected

Write Protection bit Block 0:
WRT0 = ON Block 0 (000800-001FFFh) write-protected
WRT0 = OFF Block 0 (000800-001FFFh) not write-protected

Write Protection bit Block 1:
WRT1 = ON Block 1 (002000-003FFFh) write-protected
WRT1 = OFF Block 1 (002000-003FFFh) not write-protected

Write Protection bit Block 2:
WRT2 = ON Block 2 (004000-005FFFh) write-protected
WRT2 = OFF Block 2 (004000-005FFFh) not write-protected

Write Protection bit Block 3:
WRT3 = ON Block 3 (006000-007FFFh) write-protected
WRT3 = OFF Block 3 (006000-007FFFh) not write-protected

Boot Block Write Protection bit:
WRTB = ON Boot block (000000-0007FFh) write-protected
WRTB = OFF Boot block (000000-0007FFh) not write-protected

Configuration Register Write Protection bit:
WRTC = ON Configuration registers (300000-3000FFh) write-protected
WRTC = OFF Configuration registers (300000-3000FFh) not write-protected

Data EEPROM Write Protection bit:
WRTD = ON Data EEPROM write-protected
WRTD = OFF Data EEPROM not write-protected

Table Read Protection bit Block 0:
EBTR0 = ON Block 0 (000800-001FFFh) protected from table reads executed in other blocks
EBTR0 = OFF Block 0 (000800-001FFFh) not protected from table reads executed in other blocks

Table Read Protection bit Block 1:
EBTR1 = ON Block 1 (002000-003FFFh) protected from table reads executed in other blocks
EBTR1 = OFF Block 1 (002000-003FFFh) not protected from table reads executed in other blocks

Table Read Protection bit Block 2:
EBTR2 = ON Block 2 (004000-005FFFh) protected from table reads executed in other blocks
EBTR2 = OFF Block 2 (004000-005FFFh) not protected from table reads executed in other blocks

Table Read Protection bit Block 3:
EBTR3 = ON Block 3 (006000-007FFFh) protected from table reads executed in other blocks
EBTR3 = OFF Block 3 (006000-007FFFh) not protected from table reads executed in other blocks

Boot Block Table Read Protection:
EBTRB = ON Boot block (000000-0007FFh) protected from table reads executed in other blocks
EBTRB = OFF Boot block (000000-0007FFh) not protected from table reads executed in other blocks

Mike.
 
MCLR - Enable or disable:
Well, if the product is ready for market and the code is finalise, there is no reason to enable the MCLR pin is there? Besides, enableing it means that we have less I/O pin to use. So, if everything is well, I would not enable it.
Some programmers will not reprogram the PIC if MCLR is disabled and the PIC is using the internal oscillator. MCLR is usually, or should I say always, an input only pin (It could be an open drain I guess) because Vpp must rise above Vdd. I would only disable MCLR if there were NO other pins left to use.
Code Protect:
I'm not sure about this. I heard that even though the code protest feature is set, the code can still be read by removing a layer of the PIC. How true is that? Can somebody please confirm?
It will make it harder to steal your code. Nothing stops the determined hacker however.
Monitor Clock Fail-safe:
Well, what is the chances of external oscillation malfunctioning?
It happens. Crystals can shatter internally when dropped or just fail from age or manufacturing defects. Crystal oscillators are high impedance circuits and a little moisture can upset them. For mission critical circuits, it's always good to add as much redundancy as possible.
 
Last edited:
My thoughts,

Oscillator - Internal or external?:
The internal oscillator is more than adequate for most tasks including serial communication. It's only really clock type circuits that need the accuracy of a crystal. OTOH, one reason to use an external crystal is the increase in speed available.
Mike.

I was programming a stopwatch the other day using Timer2 interrupt running internal oscillator. I run it and compared it to an actual stopwatch. For the first 1 minute or so, it was running fine. After that, i begin to see the difference in time. This must be the reason for the difference in time, because i was running on internat oscillator.
 
I was programming a stopwatch the other day using Timer2 interrupt running internal oscillator. I run it and compared it to an actual stopwatch. For the first 1 minute or so, it was running fine. After that, i begin to see the difference in time. This must be the reason for the difference in time, because i was running on internat oscillator.

Yes, the internal oscillator is only accurate to 1% and so is not suitable for clock/stopwatch applications (1% = 15 minutes per day). It is however adequate for most other tasks.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top