18.3.2.1 Use Model 1: 32-Bit Mode

To generate a 1 ms delay with a 100 MHz clock using 32-bit Timer 1 in Periodic mode:

  1. Initialize Timer for Periodic mode using MSS_TIM1_init(MSS_TIMER_PERIODIC_MODE).
  2. Use MSS_TIM1_load_immediate(load_value) or MSS_TIM1_load_background(load_value) to load required time period. For a 1 ms delay load value calculation:
    • For 100 MHz, clock period is 0.01 µs
    • Number of counts for a 1 ms delay is 1 ms / 0.01 µs equal to 100,000 (186A0 in hexadecimal)
    • MSS_TIM1_load_immediate(0x186A0)
  3. Enable Timer 1 interrupt using MSS_TIM1_enable_irq().
  4. Start the Timer using MSS_TIM1_start().
  5. Whenever the counter reaches zero, it generates an interrupt.
  6. Clear the interrupt using MSS_TIM1_clear_irq and stop the Timer using MSS_TIM1_stop().
Important:
  • MSS_TIM1_clear_irq () function must be called as a part of implementation of the Timer1_IRQHandler () Timer 1 interrupt service routine (ISR) in order to prevent the same interrupt event from retriggering a call to the ISR.
  • The MSS_TIM1_load_background() function is used to specify the value that will be reloaded into the Timer 1 down-counter the next time the counter reaches zero. This function is typically used when Timer 1 is configured for Periodic mode operation to select or change the delay period between the interrupts generated by Timer 1.
  • To calculate the load_value for different clock frequencies use formula load_value = Hexadecimal value of (Timer Frequency × Required delay).