For time-sensitive HCS08/RS08/CFV1 applications the developer often needs to trim the internal reference clock in order to generate a desired bus frequency. PEmicro's HCS08, RS08, and CFV1 Flash Programmers provide a command called “Program Trim” that allows developers to program a pre-calculated value to the non-volatile flash locations that are reserved for storing ICSTRM and ICSSC registers. These can then be loaded at run-time.
In order to calculate the appropriate trim value for the device, we start at the center trim value and scan in the proper direction. We measure the 16 closest trim values in detail. The appropriate trim value is chosen by measuring the device’s run frequency to find the one which is as close as possible to the desired reference clock frequency for the particular device. The calculated trim value has an accuracy of +/1 trim value. Meaning that the 9 bit trim value can be off by 1 step that yields the best trim frequency. For example, if the exact value you need are $3D in TRIM and $0 in FTRIM, we may calculate the value $3C and $1, $3D and $0, or $3D and $1.
Here is a demonstration of how the “Program Trim” command can be used to generate a bus frequency of 8 MHz on a 9S08QE128 microcontroller. For the 9S08QE128, the “Program Trim” command will generate a value that will trim the Internal Reference Clock to 31.25 KHz The command will then program the generated value to 0xFFAE and 0xFFAF. We will be working with an assembly file that configures the Internal Clock Source module and toggle Port A every 20 CPU cycles.
Configuration source file:
ROMSTART equ $2080
SOPT1 equ $1802
ICSC2 equ $0039
ICSTRM equ $003A
ICSSC equ $003B
PTAD equ $0000
PTADD equ $0001
sta SOPT1 ; Disable watchdog
sta ICSTRM ; Load TRIM bits from Flash and store it into ICSTRM
ora $FFAE ; Load FTRIM bit from flash and store it into ICSSC
and #$3F ; Set BDIV to Divide DCOOUT by 1
sta ICSC2 ; FLL factor= 512, therefore 31.25Khz*512/1=16 MHz=DCOOUT
; 16MHz/2=8MHz=Bus Frequency
mov #$ff,PTADD ; Set all PTAD pins as outputs
mov #$ff,PTAD ; Set all PTA outputs as high
mov #$00,PTAD ; 4 cycles
mov #$ff,PTAD ; 4 cycles
jmp loop ; 4 cycles
dw Main ;Reset Vector