CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Setting WDT in 18F direction with configuration bits

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

Setting WDT in 18F direction with configuration bits
PostPosted: Sat Feb 21, 2009 12:47 pm     Reply with quote

Hi,

I've searched previous posts, but haven't come across a concise answer.

On an 18F chip, the WDT can be turned on/off in software using setup_wdt(). But the watchdog postscale bits are only set in the #fuses at time of programming.

I've read that the configuration bits can be set directly, but how is this done? Why hasn't CCS provided this functionality in the setup_wdt() function, as with 16F devices?

In summary, I want to be able to change the postscale bits on the fly anywhere in code - how can I do this? A couple lines of code example much appreciated.
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Sat Feb 21, 2009 12:50 pm     Reply with quote

Just a quick follow-up question, with an 18F device, if in the fuses, the WDT is turned off (nowdt), and no fuse value for the watchdog postscale is set (e.g. WDT256), if the watchdog is turned on in software (setup_wdt(WDT_ON)), what value is used for the postscale? The default/unprogrammed value?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 21, 2009 1:02 pm     Reply with quote

Always post your PIC so we know specifically what the options are.

Also post your compiler version.
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Sat Feb 21, 2009 1:06 pm     Reply with quote

PCM programmer wrote:
Always post your PIC so we know specifically what the options are.

Also post your compiler version.


18f2620, PCH 4.030
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

Re: Setting WDT in 18F direction with configuration bits
PostPosted: Sat Feb 21, 2009 1:50 pm     Reply with quote

evsource wrote:

In summary, I want to be able to change the postscale bits on the fly anywhere in code - how can I do this? A couple lines of code example much appreciated.


Maybe I've figured it out on my own ... and maybe this is garbage.

Above main:

Code:
#byte CONFIG2H = 0x10
#bit wdt_postscale3 = CONFIG2H.4
#bit wdt_postscale2 = CONFIG2H.3
#bit wdt_postscale1 = CONFIG2H.2
#bit wdt_postscale0 = CONFIG2H.1
#bit wdt_onoff_hw = CONFIG2H.0


In my initializing section of main:

Code:

wdt_postscale3 = 1; // 256 postscale x 4ms = approx. 1s
wdt_postscale2 = 0;
wdt_postscale1 = 0;
wdt_postscale0 = 0;
wdt_onoff_hw = 0;
setup_wdt(WDT_ON); // WDT on in software


I'm using a bootloader (TinyBootloader), and the WDTEN bit is set to zero in the bootloader code. When the above code is loaded by the bootloader, will the #byte CONFIG2H = 0x10 line set the configuration bits? I'm under the impression that the #fuses directives are only used at time of "normal" programming, and that when using a bootloader, #fuse directives do nothing. Is that true of #byte line?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 22, 2009 1:53 pm     Reply with quote

Quote:
When the above code is loaded by the bootloader, will the
#byte CONFIG2H = 0x10 line set the configuration bits?

No. The #byte directive tells the compiler the hardware address of a
variable. It doesn't load the variable with a value.

CCS does have these two functions:
Code:
write_configuration_memory()
read_configuration_memory()

Read the manual, especially the part about erasing all of Config memory.

Here are some posts with more limitations/warnings:
http://www.ccsinfo.com/forum/viewtopic.php?t=36081
http://www.ccsinfo.com/forum/viewtopic.php?t=28958

The endurance of the Config Bits memory can be as little as 10K cycles.
Do you really need to change the WDT postscaler very often ? Or do
you just want to override the bootloader's config bit settings (and do it
just one time, per PIC) ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Feb 22, 2009 3:10 pm     Reply with quote

Quote:
Why hasn't CCS provided this functionality in the setup_wdt() function, as with 16F devices?
Cause it's not present in the Microchip designed hardware.
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Mon Feb 23, 2009 11:38 am     Reply with quote

PCM programmer wrote:

CCS does have these two functions:
Code:
write_configuration_memory()
read_configuration_memory()

Read the manual, especially the part about erasing all of Config memory.


So all the configuration bytes are erased when this function is used? It seems a little odd that there would be provision to just write some of the configuration bytes if they all have to be re-written for things to work correctly.

BTW, read_configuration_memory() must have appeared after 4.030, since it's not in my manual, and not recognized at compile time.

It seems this person had a similar situation to me:

http://www.ccsinfo.com/forum/viewtopic.php?t=25687

Did the chip stall because not all configuration bytes were written?

Final question - on the 18F2620, I'm assuming all fuses are covered by config bytes 300001H - 30000DH? That is, these are the values that are erased when using write_configuration_memory()?

Thanks in advance.
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Mon Feb 23, 2009 11:50 am     Reply with quote

PCM programmer wrote:

The endurance of the Config Bits memory can be as little as 10K cycles.
Do you really need to change the WDT postscaler very often ? Or do
you just want to override the bootloader's config bit settings (and do it
just one time, per PIC) ?


Oh, meant to mention, since using this with a bootloader, and trying to change the bootloader fuse settings, this just needs to be done once per PIC, so the 10K cycles won't be a problem. Unless I want the code to run each time the chip is powered up, I'll need to save in EEPROM that the code was run, and check that on each power-up.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 23, 2009 12:39 pm     Reply with quote

Writing the configuration bits only occasionally would cause no endurance problems in fact. However, I think it also put the fail-safe-behaviour of a bootloader at risk. I prefer to protect the bootloader area as well as configuration bits in initial production programming.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group