View previous topic :: View next topic |
Author |
Message |
ombrastein
Joined: 14 Jul 2007 Posts: 7
|
WDT postscaler problem |
Posted: Fri May 03, 2013 10:24 am |
|
|
Hei
I'm having trouble setting my configuration bits properly for the WDT PS.
Using:
PIC18F47J53
CCS PCS 4.134
mp_lab v8.85
CCS plugin 2.0.0.13
test code that has this problem:
Code: |
#include <18F47J53.h>
#fuses EC,WDT16,NOWDT
#use delay(clock=48000000)
void main(void){
//toggle an LED to indicate restart
output_high(PIN_D0);
delay_ms(300);
output_low(PIN_D0);
delay_ms(500);
output_high(PIN_D0);
//ENABLE WDT
setup_wdt(WDT_ON);
restart_wdt();
while (TRUE){
delay_ms(1000);
}
}
|
Problem:
No matter what I set WDT to as fuse, it is always written to be 8192 (as confirmed by timing the WDT).
If i change it in "ConfigurationBits", and then recompile, it is automatically set back to 8192 in configuration bits view in MP-LAB.
When i time it with stopwatch, the delay before wdt reset is about 33 sec, equivalent to a WDT PS setting of 8192.
The only way i can successfully change WDT timeout is by changing it in configuration bits _after_ compilation and before download. This must be done every time i download program, since compiling resets the Config. bits settings in MP-LAB.
Is this a compiler bug, or am i missing some setting in MP LAB that tells compiler to use my #fuses and not the MP-LAB configuration bits?
And why wont Configuration bits update to the settings i give them as #fuses ?
Am I misunderstanding somehow completely how #fuses work?
EDIT: I've also noticed that if i try to enable WDT via #fuses, and remove the setup_wdt call, wdt is in fact never enabled. Seems to indicate further that my wdt related #fuses are completely ignored by compiler/mp-lab
EDIT2: I tried for purpose of testing to change EC to HS and recompile. Then config. bits view is updated with this change. However the WDT/NOWDT or WDTNNNN #fuses have no affect on the config bits, neither whats shown in mp-lab or what is downloaded. This looks alot like a compiler bug to me...
EDIT3: After some investigation it seems this is caused by running the compiler in "debug" mode. If build is set to debug some #fuses are overridden by the compiler, apparently for no reason at all, since manually overriding them again from config bits window after compiling works just fine. I get why it is necessary to override some config settings during debug, but it would be _very_ nice to get a warning that this happens...
Thanks in advance for any help you can provide...
Last edited by ombrastein on Fri May 03, 2013 11:07 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 03, 2013 11:01 am |
|
|
Tell us whether you are running MPLAB in Debug or Release mode.
There is a drop-down box at the top of MPLAB that shows the mode. |
|
|
ombrastein
Joined: 14 Jul 2007 Posts: 7
|
|
Posted: Fri May 03, 2013 11:11 am |
|
|
Figured it out. Seems the problem was that I am still using debug compile.
Compiling in release makes it no longer ignore my wdt #fuses.
It really should give a big red warning when this happens. CCS through warning at me for lots of things thats less important then #fuses being ignored. It is clearly known to the compiler that I'm trying to manipulate #fuses that it can't let me do while in debug mode. A simple warning at compile time should be easy to do... CCS is a great compiler, but weird little quirks like this makes it far less good then it could have been... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 03, 2013 11:20 am |
|
|
If you own the compiler, email CCS support and ask them to add output
warnings if fuses are changed because of compiling in Debug mode. |
|
|
ombrastein
Joined: 14 Jul 2007 Posts: 7
|
|
Posted: Fri May 03, 2013 11:29 am |
|
|
Good idea. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Fri May 03, 2013 5:44 pm |
|
|
I think the problem is with MPLAB not CCS, as the normal default for MPLAB is 'debug',though I never use 'debug' mode...
I asked MCHP about it couple years ago, they told me how to 'patch' the code so default now 'release'.I think you can now do it within MPLAB, though I haven't updated for ,well, 2 years....
cheers
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 03, 2013 7:10 pm |
|
|
It's the compiler. Install the PCM command line compiler and you'll get
a "PIC C Compiler" icon on your desktop. Create a C source file with
WDT and Brownout fuses set, and with the #device ICD=TRUE line that
tells CCS to create code suitable for running with the debugger:
Code: |
#include <16F886.H>
#device ICD=TRUE
#fuses INTRC_IO, WDT, BROWNOUT
#use delay(clock=4M)
//================================
void main(void)
{
while(1);
} |
Now drag the C source file onto the CCS compiler icon on your desktop.
It will compile the file and create a .LST file on your desktop (and several
other files). Look at the end of the .LST file. It says:
Code: |
Configuration Fuses:
Word 1: 0CF4 INTRC_IO NOWDT NOPUT MCLR NOPROTECT
NOCPD NOBROWNOUT IESO FCMEN NOLVP DEBUG
Word 2: 3FFF BORV40 NOWRT
Some fuses have been forced to be compatible with the ICD debugger. |
The compiler has disabled the WDT and BROWNOUT fuses. MPLAB is not
involved in this test at all.
When you compile in MPLAB, the compiler looks at the setting of the
drop-down box and it uses that configuration, but it's the compiler that
is changing the fuses.
The Release/Debug drop-down box in MPLAB defaulting to the DEBUG
setting for new projects is a separate issue. This post has a link on how to fix that:
http://www.ccsinfo.com/forum/viewtopic.php?t=50053&start=4 |
|
|
|