cancel
Showing results for 
Search instead for 
Did you mean: 

How to adjust stm8s timer settings

Myk
Associate

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

2 REPLIES 2
Cristian Gyorgy
Senior III

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!

Myk
Associate

Thank you very much for your reply.