>hi thisobj:
>Thank you very much. Your way to trim the MCU works but I can get the values I want. Nevertheless >I get another value for ICGTMR different from 0xFF which I got everytime.
>The values that you set for
>WRITE_BYTE_AND_SYNC=08/00000048/
>WRITE_BYTE_AND_SYNC=00/00000049/
>HCS08_TRIM=004E/FFBE/003d0900/
>are fixed or they vary with they frequency we want to calibrate. If it´s the last case, what is the formula to >get the correct value?
>Thank you very much.
>Best regards
The value I chose, "3d0900", is for a 4MHz bus clock. The formula for the internal frequency is:
f(icgout) = (243000/7) * 64 * N/R, where N/R is the final multiplier. Bus Clock = f(icgout)/2.
In my example, P/N = 4. If you want 7.7MHz for f(icgout), then N/R = 7 * 7.7MHz /(243000 * 64) = 3.47.
If you select "3", then the untrimmed frequency will be (approx) 6.67MHz and Bus Clock = 3.33MHz--not what you want, so trimming will be required. You need to set the N/R bits in ICGC2 as follows:
For N = 6, MFD bits (6:4) = 001B (binary)
For R = 2, RFD bits (2:0) = 001B
So for ICG2, a value of 0x11 should work. This results in the following lines in the init file:
WRITE_BYTE_AND_SYNC=08/00000048/ ; unchanged
WRITE_BYTE_AND_SYNC=11/00000049/ ; selects 6/2 = 3 for multiplier
HCS08_TRIM=004E/FFBE/00757E20/ ; 7.7MHz => 3.88 Bus Clock
Remember that this entire process is for the purpose of generating a trim value ONLY. You must still load the value from memory and place your values into ICG1 and ICG2 in your code.
If you haven't already, you might want to download "MC9s08AW60.PDF" from documents area.
Chapter 8 covers clock generation in good detail.
-------------