Hello Pradeep,
In the S08RNA4 the CPU is being clocked at the same rate as the bus – i.e., there is no divide-by-2. Please refer to Figure 1-2 “System clock distribution diagram”. The S08RN and S08Px families use a newer, lower power implementation of the CPU (HCS08 V6) which is capable of being clocked at the same frequency as the bus.
For a CPU/bus frequency of 20MHz you should not need to write to register ICS_C3 as per the following description found on page 134:
“All MCU devices are factory programmed with a trim value in a factory reserved memory location. This value is uploaded to the ICS_C3 register and ICS_C4 register during any reset initialization.”
According to the specifications in the corresponding data sheet, the factory trim value should be for 39.0625kHz. In FEI mode this gets multiplied by 512 resulting in a CPU/bus frequency of 20MHz. If this is not the frequency which you desire, I suggest instructing the debug tool (i.e., CodeWarrior) to measure, calculate and store a trim value. Your code will then need to copy this into ICS_C3.
I’m not sure how you arrived at the value of 0x60 for the ICS_C3 register, but this value really can’t be fixed as it will vary from device to device. This is why the BDM interface tool will need to calculate the appropriate trim value for the MCU which it is programming. The result of this calculation is stored at a fixed location in Flash and your program would then copy this value into ICS_C3.
When I disassemble your delay routine I calculate that the port pins will toggle approximately every 2454 cycles. For k <256, your delay routine calculation is 42 + (24 × k) cycles. For a value of 100, your delay routine needs 2442 cycles:
24: void delay (int k)
delay:
00000009 89 PSHX ; 2
0000000A 8B PSHH ; 2
0000000B A7FE AIS #-2 ; 2
27: for (delay=0; delay<k; delay++);
0000000D 95 TSX ; 2
0000000E 6F01 CLR 1,X ; 5
00000010 7F CLR ,X ; 4
00000011 2006 BRA *+8 ; 3 abs = 0x0019
00000013 95 TSX ; 2
00000014 6C01 INC 1,X ; 5
00000016 2601 BNE *+3 ; 3 abs = 0x0019
00000018 7C INC ,X ; 4
00000019 9EFE03 LDHX 3,SP ; 5
0000001C 9EF301 CPHX 1,SP ; 6
0000001F 92F2 BGT *-12 ; 3 abs = 0x0013
28: }
00000021 A704 AIS #4 ; 2
00000023 81 RTS ; 6
Using your measurement of 130μs on and off, I calculate that your bus is actually running at about 18.9MHz and that the internal reference is being trimmed to approximately 36869kHz.
By the way, a faster way to write your delay routine would be:
void delay (int k)
{
for (; k!=0;k--);
}
And if k <256, this would be even faster:
void delay (char k)
{
for (; k!=0;k--);
}
Although I would prefer to use “uint8_t” and “uint16_t” instead of “char” and “int”, respectively.
For the watchdog, you do not indicate that you are changing any of its default settings. Upon reset, the watchdog timeout value is set to 0x09C4 = 2500 and its clock source is the internal 1kHz low-power oscillator. The accuracy of this oscillator is specified as being in the range between 670Hz and 1.25kHz. This should result in a watchdog timeout of approximately 2.5 seconds (i.e., between 2 and 3.73 seconds). In order to get a watchdog timeout of less than 10ms, you must be writing to the watchdog registers. I suggest taking a look at these registers via the debugger.
Best Regards,
Derrick