PEmicro | Experts in Embedded tools for Flash Programming and Development
Cart New Account Login

HomeAbout usProductsSupportForumsBlogCustomer Service

Please accept the use of cookies on our site

At PEmicro we use web browser cookies in order to provide you with an enhanced experience and in order to be able to do things like shopping cart processing and identify you when you login to our website.

Click here to accept

For time-sensitive HCS08/RS08 applications the developer often needs to trim the internal reference clock in order to generate a desired bus frequency. P&E's HCS08 and RS08 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.

Here’s 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 with an accuracy of up to +/- 0.2%. 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


     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

     mov #$00,PTAD ; 4 cycles
     mov #$ff,PTAD ; 4 cycles
     jmp loop ; 4 cycles
     Org $FFFE
     dw  Main ;Reset Vector


After saving the above source file section as "9S08QE128_Example.asm" and assembling it, we can use PROGHCS08 to program the generated 9S08QE128_Example.s19 file into flash. The programming sequence outlined below will program our generated .S19 and the pre-calculated trim value.

CM  ; Choose module 9S08QE128.S8P
SS    ; Specify our object file 9S08QE128_Example.S19
EM  ; Erase module
BM  ; Blank check module
PM  ; Program module
VM ; Verify module
PT  ; Program Trim Value

On a power-on reset, our 9S08QE128 target will disable the watchdog, load trim values from flash and store them into their corresponding ICS registers, set the bus frequency divider to 1, and toggle PTA pins every 20 cycles. With a bus frequency of 8MHz, if we were to put a scope on any of the PTA pins, we would expect to observe a signal with a 400 KHz frequency +/-0.2% accuracy.

search in blog posts


Product pages
Cyclone (41)
Cyclone FX (43)
Multilink (22)
Multilink FX (17)
GDB Server (11)
Prog ACMP (6)
Interface Library Routines (5)

ARM (36)
NXP (43)
Microchip (4)
Cypress (5)
Infineon (1)
Maxim (2)
Nordic Semiconductor (2)
Silicon Labs (4)
STMicroelectronics (5)
Texas Instruments (1)
Toshiba (2)
Renesas (6)

Production Programming (52)
Debug (27)
Automated Control (13)
Miscellaneous (36)

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