cancel
Showing results for 
Search instead for 
Did you mean: 

One pulse with repitition counter

Imran Arshad
Associate II
Posted on March 03, 2017 at 08:14

Hi all,

I am a newbie developer for STM I am developing an application using the STM32F746 Discovery board and KEIL uVision. I need to output two pulses on GPIO that I will feed to another board. The first pulse is a simple PWM with 250kHz frequency and 60% duty cycle. This part was easy as I simply modified the examples of PWM given in DFP 2.8 using HAL library and I outputted it on TIM3 Channel 1.

The tricky part is the second pulse. It should start on the falling edge of pulse 1 and out put a fixed number of pulses and then stop and start on next falling edge. The processor should never be involved in this. So I searched for solutions and found that it could be done using One Pulse mode and Repetition Counter register.

Also I figured out that only TIM1 and TIM8 have repetition counter.

So my question is how can I start the One Pulse Mode with N-Pulse generation using TIM3 Channel 1 falling edge as trigger? The reason I am asking is because in the HAL library there is a function HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel). So it requires two channels of same timer (One for Input i.e trigger and other for the desired waveform output). So do we need to physically short the output of TIM3 channel 1 to TIM1 Channel 2?

Or can we set the trigger internally without doing any such thing?

Also is there any example of this available? Anyone who has completed this who can share their work? I am a newbie and facing great difficulty in my first STM32 project.

0690X00000603i0QAA.jpg

Note: this post was migrated and contained many threaded conversations, some content may be missing.
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 04, 2017 at 01:51

Perhaps not, but my inference is that micro-managing TIM registers on a cycle-to-cycle basis is done with an IRQ or DMA.

Or the built-in facilities of timers themselves - these manage individual bits rather than complete registers, of course. One-time mode (in timers where available, sure) is one of them - if set, the (repetition-)update event will clear CR1.CEN. Trigger mode of slave controller is other - it sets CR1.CEN upon TRGI leading edge. Incidentally, we don't need anything else here.

Have a 'L476 DISCO?

www.efton.sk/STM32/slave_onex3.zip (needs headers from www.efton.sk/STM32/stm32l476xx.zip )

Enjoy! 😉

Jan

View solution in original post

14 REPLIES 14
S.Ma
Principal
Posted on March 03, 2017 at 13:05

There should be few ways to implement this. Try to use DMA to Output Capture, cycling through a list of compare values, if the chosen timer and STM32 is able to do this. Otherwise, use another timer trigged by the PWM to repeat counts as initially thoughts.

Posted on March 03, 2017 at 17:49

+1 Use a DMA pattern buffer to drive a cyclic pattern into the TIMx->CCRx (zero disables the output). You could trigger the DMA from the TIM outputting the pattern

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 03, 2017 at 22:04

IMO DMA is an overkill in this case. This calls for two timer being linked, one providing the output pulse and a TRGO to the other, which is set to one-pulse mode with repetition counter, and as a slave linked to first and set to trigger mode.

I am a newbie and facing great difficulty in my first STM32 project.

We all were newbies and faced difficulties, and believe me, I still face them today, but I believe I will prevail simply by continued learning, however boring this may sound.

Your first STM32 project is an overkill.  The first project in whatever mcu should be a plain blinky, and then evolve from that. You can achieve spectacular effects with modifying existing cube or whatever projects, but beyond those, having achieved no firm foundations, you get quickly lost.

http://norvig.com/21-days.html

JW

Posted on March 03, 2017 at 22:14

250 KHz would be in the realm where interrupting is less desirable. If the signal is continuous DMA would solve with near zero loading.

The complexity is not STM32 unique.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 03, 2017 at 22:17

? No one mentioned interrupts.

JW

Posted on March 03, 2017 at 22:51

Perhaps not, but my inference is that micro-managing TIM registers on a cycle-to-cycle basis is done with an IRQ or DMA. There are other gating, triggering and repetition methods, but some of the more functional modes are limited to TIM1/TIM8 of the advanced counters.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 04, 2017 at 01:51

Perhaps not, but my inference is that micro-managing TIM registers on a cycle-to-cycle basis is done with an IRQ or DMA.

Or the built-in facilities of timers themselves - these manage individual bits rather than complete registers, of course. One-time mode (in timers where available, sure) is one of them - if set, the (repetition-)update event will clear CR1.CEN. Trigger mode of slave controller is other - it sets CR1.CEN upon TRGI leading edge. Incidentally, we don't need anything else here.

Have a 'L476 DISCO?

www.efton.sk/STM32/slave_onex3.zip (needs headers from www.efton.sk/STM32/stm32l476xx.zip )

Enjoy! 😉

Jan

Posted on March 04, 2017 at 07:06

In our user profile edition we should be able to describe our programming experience (in years?), and this shows up when asking a question.

This would also shows up when someone answers and if the 'gap' is big, it would tell the gap... As a question probably interest others, the answer may be of interest to more experienced readers. The questions and answers will stay for years on the forum. It may become useful at a later time, when the programming experience gap shrinks.

The 10 days to teach yourself programming is quite true. The question is how to speed up the learning curve.

My personal gut feeling would be:

- Start with an easy programming language such as Python or Javascript or Basic (pure programming)

- Dig to C and look at the assembly generated by the compiler in the debug window (pure programming)

- Have fun with function pointers

- Read some books on different programming language

(Clojure was inspiring I liked the reentrancity/no use global variable access in a function. This is what we usually don't do when we have to optimize a SW for performance and code size)

- Have a look at the semiconductor design techniques (memory access time, pipeline, cache, dual port ram principle, FPGA)

- Dig to the HW peripheral without any SW (after init) and use the debugger register window to manually play with GPIO, SPI, USART...)

==> People who likes to use HW assistance as much as possible to off-load the SW are either from FPGA background or having in their mind multiple constrains to solve such as lowest power consumption, small latency, which are constrained in a project related to a finished product (battery operated?) 

- Co work with someone on a project

- Develop a program and pass it to your co-worker. See if he reuses it or claim it's better for him to restart from scratch

- 6 month later, re-visit one of your SW project and see if you can continue/reuse it.

This is a quick thought about this topic, not the 10 commendments...

Imran Arshad
Associate II
Posted on March 06, 2017 at 09:26

I wont be able to try any suggestion till next week as I have to go outside of my city for a week..... I will let you know about the result or any problem that I will face....