Hello friends, I have a problem to obtain an exact 1 millisecond flag using the MTIM module.
Here are the details:
USBSPYDER08 programmer ( trimming enabled 20000000 DCO )
A very simple program in C using CodeWarrior 6.2
Device initialization wizard screen shows:
Internal oscillator frequency = 31.25 KHz
Initialize trim values = Yes
Trim value address = 3FFA
Fine trim value address = 3FFB
Bus freq. divider = autoselect
Internal bus clock = 8.0 MHz
FLL = Engaged
Clock source = bus clock
Prescaler = 32
Modulo register value = 249
Period = 1ms
Overflow interrupt = disabled
Enable MTIM module = Yes
Main program code:
for( ; ; )
while( MTIMSC_TOF == 0 ) /* wait for MTIM counter overflow */
MTIMSC_TOF = 0; /* clear counter overflow flag */
TEST_PIN ^= 1; /* oscilloscope mark 500 Hz square wave */
timer_tick(); /* really small processing here */
MCU_init() contains this code that installs trimming values in corresponding registers:
/* System clock initialization */
ICSTRM = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFA); /* Initialize ICSTRM register from a non volatile memory */
ICSSC = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFB); /* Initialize ICSSC register from a non volatile memory */
/* ICSC1: CLKS=0,IREFSTEN=0 */
ICSC1 = 0x00; /* Initialization of the ICS control register 1 */
/* ICSC2: BDIV=0,LP=0 */
ICSC2 = 0x00;
The result is a 800 us ( 0,8 ms ) MTIM overflow instead of 1000 us ( 1 ms ) period.
I can see that the USBSPYDER writes "Trimming ... " while in FLASH programing.
I can't understand what I am doing wrong. This has worked for me with any other 9S08 MPU perfectly well.
Any ideas ?
Thank you in advance.