[SOLVED] How to change tick interval?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] How to change tick interval?

    Hi,

    I'd like to change tick interval other than 1ms. (500us or 250us).
    When I change the period of Timer as 500us, tick interrupt is generated in every 500us.
    But timer related APIs are not work properly.
    When I call OS_Delay(1000), it expires after 500ms.

    Is there anything I need to do?

    I'm using embOS 4.22.
  • Hi Shinkyu,

    Thanks for your inquiry!

    shinkyu.park wrote:

    When I change the period of Timer as 500us, tick interrupt is generated in every 500us.But timer related APIs are not work properly.
    When I call OS_Delay(1000), it expires after 500ms.
    This actually is expected behavior. OS_Delay() [or OS_TASK_Delay() as it's called in recent versions] doesn't take milliseconds as a parameter, but system ticks. Therefore, by doubling the system tick interrupt's frequency, all delays will expire twice as fast.

    shinkyu.park wrote:

    Is there anything I need to do?


    I'm using embOS 4.22.
    If you want timeouts to be based on milliseconds even when the system tick interrupt is not, there's three different options in general:
    1. Most obviously, you may modify all timeouts within your application to account for the modified tick frequency, i.e. doubling all timeouts in your application's source code.
    2. With embOS V5.8, we've introduced a new API function OS_TIME_Convertms2Ticks(), which may be used to convert parameters before passing them to OS_TASK_Delay(). E.g., OS_TASK_Delay(OS_TIME_Convertms2Ticks(10)) would result in a delay of 10 ms regardless of whatever frequency the system tick interrupt is configured at. Unfortunately, however, V5.8 was not released for Cortex-M and IAR yet (but is already on out ToDo), so as of now that API is not available to you. If desired, we may try to prioritize the release of embOS V5.8 for Cortex-M and IAR to make that API function available to you, too, but since our offices will be closed during the holidays that shipment could become available in January at earliest.
    3. By using OS_TICK_Config() you may configure embOS for a different interrupt-to-tick-ratio. Generally speaking, this means that embOS would not increment the internal time variable with every occurance of the system tick interrupt, but with every second, third, fourth occurance only (or whichever other ratio you desire). For example, OS_TICK_Config(1000u, 2000u) would configure embOS' internal time variable to equal milliseconds when the respective interrupt occurs every 500 us - which effectively renders all timeouts to be based on milliseconds once again. For using OS_TICK_Config(), however, please keep in mind that your tick interrupt handler would then need to call OS_TICK_HandleEx() instead of OS_TICK_Handle().
      We typically wouldn't recommend doing this, however, since it basically means that you'd double the frequency of the system tick interrupt, only to ignore every second occurance of that interrupt so the effects would cancel out each other. Therefore, usage of OS_TICK_Config() typically is advised only when the system tick interrupt cannot be generated at 1000 Hz to begin with, for example due to limitations of the hardware timer. Hence, I'd like to ask for more information on why you want to double the frequency of the system tick? With more information on your exact use-case, we may be able to give more proper advice on what embOS can do for you. Since you're holding a valid support agreement, please also feel free to contact us via email if you do not want to discuss these details on a public forum.
    Does this answer your question? Please let me know if I can be of any further help.

    Best regards,
    Martin