R8C watchdog problem
Up to R8C/Tiny
I have one problem with watchdog. I can not start it. I've set OFS register to FE, in my initialization function i start wtd with wdts = 1 but still nothing
Does anyone have a code that initializes WDT to run ?
Thnx
void WD_Init(){ //Initialize Watchdog Timer
cm06 = 1; //BCLK = (20/8) MHz = 2.5 MHz (Xin div by 8, default)
wdc7 = 1; //prescaler is div by 128, Watchdog Timer
//period = (32,768 x 128) / (2.5 MHz) = 1.678s
wdts = 0; //start Watchdog Timer by writing any value to wdts
//reg (value always resets to 0x7fff when written to)
}
void TimerA1_ISR(void){
wdts = 0; // restart watchdog timer
red_led_status != red_led_status;
if (red_led_status) red_led = 1;
else red_led = 0;
}
does that help?
I also found this:
http://america.renesas.com/request?LANGUAGE_CD=EN&SCREEN_ID=ViewUsrFrameApnDocumentSearch&LAYER_ID=81&DOC_TYPE=Application%20Notes&FUNCTION_FLG=0
There should be sample code under: "The Software Reset Judging Method"
Does that help?
Anyway, my watchdog timer starts, but I can't reset it. For example, I have this small program (after my CPU initialisation), but the cspro bit won't set

prc1 = 1; //enable PM1 write
pm12 = 1; //watchdog reset enabled
prc1 = 0; //PM1 write protected
cspro = 1; //count source protection - clock is onboard osc.
//which renders wdc7 (divide by 128) irrelevent
wdts = 0; //watchdog starts when counter is written to
while(1)
{
wdts = 0; //watchdog reset
led = 1;
}
Basically, when I program the chip, the led comes on briefly, then the watchdog times out, and it turns off. Then it turns on again etc... It seems that writing to the wdts register doesn't reset the counter, but I have no idea why.
Any help would be appreciated...
Thanks!
Regards
Frank
As (ambiguously IMHO) in the hardware manual it says you have to write a 0x00, followed by 0xff to the WDTR register. It won't reset the timer if you do anything else, and unlike other devices in the family, writing anything to the WDTS register does nothing.
Cheers,
Timmins
Have anybody an idea how works the Watchdog in Reset Mode in the R8C/13 (Tiny Series)? I already read the data sheet but still can´t make it works. At the moment the instruction "wdts=0" comes, the program stop working properly...but it doesn´t restart...
Thanks
Guti
Assuming that you are using R8C/26, i have the below sample code, hope you find it useful.
Please be informed that the *.c files mentioned in the comments are generated by HEW project generated when selecting C Source Start up.
Also, for others who are unable to clear wdt in time, please note at start-up oscillator is 125KHz / 8 which is very slow, so, either perform clock settings before main call in start() or use multiple WDT clear statements to avoid continuous reset.
// NOTE: #define __WATCH_DOG__ 1 , modified to 1 in "cstartdef.h",
// this will affect the .ofsreg setting in "fvector.c", for this demo program we have enabled
// _asm(" .ofsreg 07EH"); // With count source protect// WDT with count source protect i.e. the clock source to WDT is on-chip Oscillator [Low-Speed].
// The WDT is Enabled on Power-ON itself, hence it is also cleared once in the Start function
// of "resetprg.c" to avoid generation of reset before initialisation, this is only a precautionary
// measure taken to ensure that the execution reaches Main(), WDT is then cleared periodically in the
// Main() function at relevant places.
unsigned int usi;
asm("FCLR I"); // Disable Interrupts
prc0 = 1; // Write Enable
cm1 = 0x2C; // Clock Mode Register Settings
cm0 = 0x00;
// for(usi = 0; usi < 300; usi++); // Delay for Clock Stabilisation
ocd0 = 1; // Enable Clock Stop Detect Function
while(ocd3 == 1){ // Wait for the Main clock to Stabilize
wdtr = 0x00; // Conitnue Clearing WDT to prevent RESET
wdtr = 0xFF; // while waiting for Xin to stabilise
};
ocd2 = 0; // Select Xin Main Clock
cm14 = 0; // Note ocd2 = 0 makes cm14 = 1 [ On-chip osc stop ],
// hence Start On-chip Oscillator again
prc0 = 0; // Write Disable
pd1_0 = 1; // Set Direction Port Output
p1_0 = 0; // Initialise the Port to 'L'
asm("FSET I"); // Enable Interrupts
// Till This point in execution the Timing is approx 24msec as observed on the DSO
// hence Programmer can remove the WDT Reset Statements, However, the execution time
// till this point is dependent on the No.of Variables that will be initialised and
// Main clock oscillation stabilsation, hence it is recomended that the WDT is cleared
// atleast once in the Initialisation code to avoid continuous Reset.
while(1){
//////////////////////////////////////////////////////////////////////////////////////////////////////
// For Testing -- Start Comment from cbelow statement
asm("FCLR I"); // Note that No Interrupt Occurs during clearing WDT
wdtr = 0x00; // Clear WDT
wdtr = 0xFF;
asm("FSET I");
// For Testing -- End Commenting on the above Statement
// For Testing Purpose you can comment the above statements and check the reset functionality
//////////////////////////////////////////////////////////////////////////////////////////////////////
p1_0 = ~p1_0; // Toggle Port Only for testing
};
CHEERS!!!
i use assembly language , and get a empty application,
*.inc and *.a30 files by myself, to handle wdt by this:
;wdt initial
mov.b #80h, wdc
mov.b #0, wdts
mov.b #00h, wdtr
mov.b #0ffh, wdtr
;clear wdt
mov.b #00h, wdtr
mov.b #0ffh, wdtr
is any one having code of watchdog timer of r8c/24 ,
does any one know how OFS register write
please send information
No, it is no bug that OFS register is not in sfr_25.h. OSF is no variable register and cannot be written to during software execution. OFS is treated like program memory and must be written to when programming your software to the device. To write to the OFS register you must use inline assembler like this:
_asm(" .ofsreg 0FEH");
This statement must NOT be inside one of your functions. You can put it at the beginning of one of your C-files.
prc1=1;
pm12=1;
cm07=0;
wdc7=0; //divide by 128
cspro=0;
// wdtr=0x00;
// wdtr=0xFF;
//wdc=0x7F;
uart1_putstring("Hi");
wdts=0x7f;
while(1)
{
}
//----------------------------------------------------
use this code it run on r8c24 processor well for watchdog timer
Previously wrote:
Can you tell me exactly which R8C you are using (e.g. R8C/11, R8C/13 or R8C/1B). There are some variations on the Watchdog timer circuits. If you provide this information I can provide a code example
i am using R8C/1A can u plse send me the source code to prabhakar6777@yahoo.com

