Cart New Account Login

HomeAbout usProductsSupportForumsBlogCustomer Service
   Home P&E Customer Support FAQs - Frequently Asked Questions FAQ ID # 123
FAQ ID # 123
 
Question
How can I program a pre-calculated trim value into my HCS08/RS08/CFV1 device to be loaded at run time?
 
Answer
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

     Org ROMSTART

Main:  
     lda SOPT1
     and #$7F
     sta SOPT1   ; Disable watchdog  
     lda $FFAF
     sta ICSTRM  ; Load TRIM bits from Flash and store it into ICSTRM
     
     lda ICSSC    
     and #$FE
     ora $FFAE   ; Load FTRIM bit from flash and store it into ICSSC   
     sta ICSSC   
     
     lda ICSC2
     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
     Bra Loop
  
Loop:
     mov #$00,PTAD   ; 4 cycles
     nop
     nop
     nop
     nop
     nop
     nop
     mov #$ff,PTAD   ; 4 cycles
     nop
     nop
     jmp loop   ; 4 cycles
        
     Org $FFFE
     dw  Main ;Reset Vector
 
Related Downloads
none
 
Architectures Categories Products
HCS08, RS08, ColdFire V1 Flash Programming Software XPC560PKIT100S, XPC560SADPT280S, CYCLONEPRO, PROGHCS08, PROGRS08, UNIT12Z-LINUX-DIST, DEMO9S08JM16, XPC560PADPT144S, XPC560PKIT144S
 
Please rate this FAQ to help us improve our support
0 means "not helpful"
10 means "very helpful"
0 1 2 3 4 5 6 7 8 9 10

© 2017 P&E Microcomputer Systems Inc.
Website Terms of Use and Sales Agreement