cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure HW for periodic burst of pulses?

SWenn.1
Senior III

What is the best way to create 480 1us pulses (to clock an A/D) every x seconds?

Can this be done with one timer?

1 ACCEPTED SOLUTION

Accepted Solutions

Note, that even if some timers in STM32 have repetition counter TIMx_RCR, in some STM32 families it is only 8-bit long.

If pulses are far enough apart, you can simply use the given timer's interrupt to count and stop, then reprogram the timer to time the one second.

A two-timer solution is to use the master-slave interconnection, one timer gating clock of the other.

JW

View solution in original post

3 REPLIES 3
KiptonM
Lead

I am not an expert on the STM32 timers, but here is my 2 cents worth.

There is no "best" way, it depends on what you are doing.

I am guessing the 1 us pulse is 1 us high. But you do not say what the low time is. If it is also 1 us, that can be a different answer than if it is 1 ms low between pulses.

Also, we do not know how precise you want every x seconds. Because we could use a timer for that if it is precise, or let the processor start it if it is not precise.

I would start with a timer with a repeat function. Some of the STM32 timers have it, most do not. Use that and you can do the 480 pulses with 1 timer. I do not have the timers memorized to know which ones have a repeat function.

If you do not use a timer with a repeat function you can use a processor interrupt if the low time is long enough, but it is probably "better" to use a second timer.

Finally, either the processor or another timer can start the cycle of 480 pulses every x seconds.

So, you can do it with 1, 2, or 3 timers. Only you can decide what is "best" for your application. And that depends on what else the processor is doing. And how many timers you need for other functions other than the external ADC.

On one non-STM32 project, I had a more complicated waveform and I was able to use the SPI to generate it (without DMA). That was the best for that 8-bit processor with not too many peripherals and very simple timers because it was very cost sensitive, I could not use a more expensive microcontroller with better timers. (480 is only 15 32-bit words or 60 8-bit bytes just to confuse the situation.)

Note, that even if some timers in STM32 have repetition counter TIMx_RCR, in some STM32 families it is only 8-bit long.

If pulses are far enough apart, you can simply use the given timer's interrupt to count and stop, then reprogram the timer to time the one second.

A two-timer solution is to use the master-slave interconnection, one timer gating clock of the other.

JW

S.Ma
Principal

Two timers, one for the 1 MHz pwm with enable signal coming from another timer acting as enable? DMA cyclic modd on compare here wouldn't work. SPI as clock gen is nice, only prescaler granularity to dodge.