cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate exact number of pwm pulses?

AP.2
Associate II

hi,

I am working on a stepper motor driver with stm32f407. Facing a challenge in generating exact number of steps for driving the motor. Now what i have done is, i shorted a pwm generating pin with input capture and stops the pwm generation once the input capture reaches the pulse count.

my question is

  1. At higher frequency will there be any issues if i drive 6 steppers same time. I am stopping the pwm inside the input capture cal back.
  2. Is there any better way to remove the necessity of input capture and can generate exact number of pwm signals?. note that frequency must be an unavoidable factor, i need to generate pulses at fixed calculated frequencies.

Thanks

7 REPLIES 7
AP.2
Associate II

please let me know if you want more description!.

The'F4 is not the best for this purpose.

Use one-pulse mode in a timer which has RCR - in 'F4, only TIM1 and TIM8, and they have only 8-bit RCR.

Other option is to gate one timer from other through internal master-slave connection, or stop one timer from other using DMA after a precalculated time or after having counted pulses through internal master-slave connection or through external connection as you've done it.

JW

berendi
Principal

> i shorted a pwm generating pin with input capture and stops the pwm generation once the input capture reaches the pulse count.

You could do this internally with a slave timer. Read timer functional description / timer synchronization / using one timer as prescaler for another timer in the reference manual. See the example there, TIM1 as master providing the PWM signal and the pulses for the TIM2 counter.

If that works, move on to the next example Using one timer to enable another timer in the reference manual, but swap TIM1 and TIM2, so that TIM2 would be the master, generating a PWM signal which is used internally to gate the TIM1 counter. As TIM2 is using TIM1 as its clock source, set the PWM duty cycle (compare register) to the number of pulses required.

GAnto.2
Associate

Hi 🙂

I'm facing the same problem as AP.2 previously.

I'm beginner in STM32 Programming. I'm using a Nucleo F446RE.

So i want to generate an exact amount of inpulsion with a predetermined frequencie.

I' ve done some reasearchs about the one pulse mode but I don't think it really corespond to what i want to do.

So does it exist a way to trigger a series of pulse that are only generate by hardware so my main is not block?

G.Anto.2

I believe what has been written above by berendi and me still pertains.

One-pulse mode using RCR is still the easiest way. Try.

JW

Ok 🙂 i don't really no what RCR is but i will try my best if it's the easiest way ^^

thanks you for replying so fast :D

GAnto.2

Repetition Count Register.

Read the TIM1/TIM8 chapter in Reference Manual.

JW