0

I am using STM8S Cosmic C compiler, and I am trying to configure tim2 for 350 µs (350 µs should be the pulse width).

As per the reference manual, tim4 is a 16-bit with a prescaler factor of 32768. I will be using the internal 2 MHz clock

My calculations are as follows:

1/2000000 Hz = 0.0000005 seconds ~ 0.5 µs
If we use a 128 prescaler:
128 * 0.5 µs = 64 µs

I want each pulse to be of 350 µs, how do I calculate that? Are the calculations are wrong too?

I am trying to calculate it for 350 µs, but I am not getting actual value and need guidance!

1
  • Reduce prescaler to 1 to get a timebase of 0.5us. The ARR register has to be loaded with 350us/0.5us - 1= 700 - 1= 699. Commented Aug 11 at 3:26

1 Answer 1

0

Use the lowest value of the prescaler.

As you mentioned, tim2 is 16 bit. So you have the span of 65535 counts. Without a prescaler (2^0), the counter can reach a value of 700 (for 350 µs).

It depends on the accuracy you want. I would not use a prescaler for these settings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.