Hi,
When the 9S08 is passing the last test sequences in the factory, the ICSTRM byte is changed until it gives the corrrect fBUS frequency. The value is then written into the TRIM byte high up in the Flash EPROM memory.
This means that when you pick a brandnew 9S08, the Flash EPROM is erased, expcept for one byte, the TRIM value.
To use this byte in your code, just write
ICSTRM = TRIM;
and it will copy the TRIM value into the ICSTRM.
Note that it is not called TRIM in all versions of 9S08. If you get errors, look in the include file that contains all the register names, and you can see what name to use.
Also note that there are, right now, three differenct versions of the clock circuit. They are called ICS, ICG and MCG, so the xxxTRM register might not be called ICSTRM in your MCU.
When the Flash EPROM is bulk erased, everything including the TRIM byte is erased.
But good enough, the erase program saves the TRIM value in advance, and then writes it back after you have erased the Flah.
If you by mistake have managed to erase the TRIM value for good, most programmers offer an automatic update of the value. PEMicro offerers you to either use a standard value of 31.25 kHz or your own value.
Note that if the TRIM value gets reset, to 0xff, the ICSTRM value willl treat it as the value 0x80.
In this way, if the TRIM value gets erased, the calbration value will be +/- 0%.
Regards,
Ake