Skip to main content
Visitor II
April 18, 2022
Question

How to adjust stm8s timer settings

  • April 18, 2022
  • 2 replies
  • 1442 views

Hello, I am using the Stm8s003f3p6 processor. I want to create 1 microsecond time on processor. I tried TIM1 and TIM4 peripherals for this. I gave the values of 2, 4 and 8 respectively as Presecaler values. Again, I gave 7, 3 and 1 values as periods, respectively. But my timer enters the interrupt in 20 microseconds. How can I get the 1 microsecond time?

Thanks for your answers

    This topic has been closed for replies.

    2 replies

    Visitor II
    April 20, 2022

    If you want to generate 1 us periodic interrupt you should keep in mind, that 1 us means exactly 16 CPU cycles - not a lot of time,

    If you really need this, you could achieve it by using the interrupt-only activation level (CFG_GCR/AL bit set), but you would still only have about 10 cycles available in the interrupt routine. (5 cycles used with the jump/iret instructions).

    In normal usage, the saving and restoring of the context takes 18 cycles and if you add up the 5 cycles for jump/iret your 1 us is already lost.

    For an 8-bit MCU, nobody really wants to execute an interrupt routine with a 1 us period, so, you better re-think your system.

    Also, when you need critical timing, I suggest using assembly language directly, because a C compiler might introduce quite some delays.

    Good luck!

    MykAuthor
    Visitor II
    April 29, 2022

    Thank you very much for your reply.