When Config Changes Take Effect

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

When Config Changes Take Effect

Postby Joseph Watson » Thu Sep 03, 2015 3:55 am

I know that on a PIC18F47J53, the alteration of configuration settings by a program is possible just as it is possible on apparently all PIC18 series chips. I also know that the configuration register system works differently in that family of MCUs from many of the other PIC18 chips.

In the PIC18F47J53 family, the last 4 words of Flash program memory are reserved as the FCW (Flash Configuration Words). A running program can alter these Flash words just as it can alter any of the words of Flash memory. Each time the chip is reset, the chip reads these 4 words and transfers their contents to the true configuration registers that are controlling the behavior of the chip. These true configuration registers are actually volatile memory cells. The volatile configuration memory cells are not directly writable but they are readable by a program.

One result of this organization is that making a change to the configuration data in the 4 Flash Configuration Words at the top of Flash memory has no effect on the behavior of the chip until the chip experiences a reset cycle. This is clearly described in the data sheet for the PIC18F47J53 chip family.

However, as I read the data sheets for some of the other PIC18 series chips which do not have this organization (where the configuration is copied to the true configuration registers upon reset) I am left unclear as to when a change written to the configuration registers actually affects the behavior of those chips. For example, I am currently using a PIC18F4620 and I don't seem to see where it says changing the configuration registers causes an effect immediately or not until the next reset cycle.

Does anyone here know for certain how the chips similar to the PIC18F4620 work in this regard?
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist

Re: When Config Changes Take Effect

Postby jtemples » Thu Sep 03, 2015 5:37 pm

For most parts, the new config values are latched only on a power-on reset.
jtemples
Verified identity
 
Posts: 162
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: When Config Changes Take Effect

Postby Joseph Watson » Thu Sep 03, 2015 7:57 pm

Great. Thanks.

I am writing a special bootloader of my own design and I wondered how I was going to manage to keep it running if the MCU was going to start behaving differently as I wrote new bytes into the config registers. In particular, things like switching from a fast external crystal driven clock to a slower internal clock would have really messed with things. I was hopeful that I would not have to worry about that happening while my bootloader was running.
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist

Re: When Config Changes Take Effect

Postby jtemples » Thu Sep 03, 2015 10:39 pm

I believe internally, the config registers are only read once at startup. You could easily prove the behavior to yourself by running on the internal RC, then programming the oscillator to use a crystal when one isn't present.
jtemples
Verified identity
 
Posts: 162
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: When Config Changes Take Effect

Postby Joseph Watson » Fri Sep 04, 2015 8:42 pm

The test results are in....

I have evidence to show that changing at least one Config register takes effect immediately. In the PIC18F4620, the CONFIG1H register includes the specification for the oscillator for the clock. I have a 10MHz crystal connected to the PIC chip and CONFIG1H set with the HSPLL oscillator setting. Since the PLL is used to quadruple the clock, the system clock ends up at 40MHz and execution ends up running at 10 MIPS.

My program stores the CONFIG1H register with the INTIO67 oscillator setting. This setting specifies the use of the internal clock. The default setting of the IRCF2:IRCF0: Internal Oscillator Frequency Select bits of OSCCON specifies that the internal clock will result in a 1MHz system clock with a resulting execution speed of 0.25MIPS, a reduction in speed by a factor of 40. Indeed, as soon as I change the contents of CONFIG1H in this way, the execution speed does immediately drop by a factor of 40.

I think I might need to permit my bootloader to change some configuration registers but not others.
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist

Re: When Config Changes Take Effect

Postby jtemples » Fri Sep 04, 2015 9:20 pm

That doesn't seem right. The erased state of CONFIG1H is an external RC oscillator, which you obviously don't have. If the changes latched immediately, the PIC should halt as soon as your program erases CONFIG1H before writing it, since it would no longer have an oscillator.

Edit: I found some old 18F452 code I had written that does this, and I had forgotten that you don't need to erase the configuration fuses before writing them.
jtemples
Verified identity
 
Posts: 162
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: When Config Changes Take Effect

Postby Joseph Watson » Sat Sep 05, 2015 6:51 am

I am not sure about the other PIC18 chips in this regard but you do not erase the CONFIG registers before writing them as you do with Flash in the PIC18F4620 or the PIC18F2550. Here is the relevant text from the data sheets: "Setting the WR bit starts a long write to the configuration register. The configuration registers are written a byte at a time. To write or erase a configuration cell, a TBLWT instruction can write a ‘1’ or a ‘0’ into the cell."

In my particular experiment case, CONFIG1H was 0x06. I have been updating it with a single long write that changes it from 0x06 to 0x08. In that single operation, two 1's become 0 and a 0 becomes a 1. My testing seems to confirm the notion that one does not need to erase the CONFIG registers before writing to them.

In my bootloader project, although I have not implemented this yet, I now expect to be buffering any needed changes to the configuration registers in some RAM. Then when all the rest of the hex file has been loaded and the bootloader is about to terminate, it will write the buffered data into the configuration registers as the last step. That way, a change in clock speed will not affect the I/O operations that take place prior to that point. I am expecting that the configuration writes can take place at any clock speed, as long as there really is a clock still running.
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest