2012-07-12 02:25 AM
I want to generate single pulse with given length on GPIO pin on STM32F4 Discovery kit. I wanted to use timer in OnePulse mode. So I was planning to use TIM4 and TIM12, becouse I need 6 independent pins for pulses. But I am a little confused from the example in Standard Peripherals Library. There's used a timer as a trigger for pulse. But I want to trigger pulse from my code, not from timer. How can I do that?
I want to have function like this: void GeneratePulse(uint8_t pin, uint16_t duration). How should I configure timer to get this kind of behaviour? Thanks in advance.2012-07-12 03:01 AM
I'm hard pressed to see a simple way to generate 6 different single pulses out of 2 timers. ie using multiple channels, and non-repetitively.
What kind of pulse widths are we talking about, and how precise do they need to be? Express in units of time.2012-07-12 03:51 AM
I need to generate 2 kinds of pulses - one with fixed length 300ns with tollerance -+200 ns and pulses with variable lenght from 200 ns to 1 ms with precision +-50ns.
Is it impossible to generate 6 independent pulses? I thought each channel of timer is independent, they share only counting register. I am sorry for maybe stupid questions - I try to understand the timers, but as I said, I am a little bit confused from the examples and RefMan.2012-07-12 05:34 AM
The timers are complex beasts, and not overly flexible. You could certainly expect to spend days fighting with them, and still not win.
Unfortunately the channels are tied to what the timebase counter is doing, and don't themselves count. ie you could fire pulses on all four channels together, and control width of each, but probably not independently. For 50ns granularity, you could drive your timebase at 20 or 40 MHz via the prescaler. You might need to choose PLL and XTAL frequencies to suit depending on the STM32 part you plan on utilizing. Any phase/placement requirements, or simultaneous/parallel firing?2012-07-12 06:56 AM
The timers are complex beasts, and not overly flexible. You could certainly expect to spend days fighting with them, and still not win.
I've already found out that. I spet lots of time getting timers to work - successfuly, but this time I have no idea how...Unfortunately the channels are tied to what the timebase counter is doing, and don't themselves count. ie you could fire pulses on all four channels together, and control width of each, but probably not independently.I know the channels don't count themselves. But I thought it's possible to set pin high and let the timer to set the pin low when the counter value reaches certain value (independentely on other channels). But as I am reading the RefMan, timers unfortunately can't do that. And solution via OC with interrupt is slow, I guess.Any phase/placement requirements, or simultaneous/parallel firing?
My application drives simultaneously several axes of motion. Each axis moves independently. The movement of the axis is given by equation. In constat frequency I calculate new position of the axis and depending on the new position I send control pulse to motor driver. So there's no need for synchronizing the axes, but there's a requiement to generate pulse as soon as it is possible. As I am reading examples, RefMan and other examples I found on the Internet, I still don't know, if it is possible to use OnePulse mode on timer triggered by SW - ''when I call this function, the timer will be triggered and pulse generated''. In every exaple is the pulse triggered by external source. If it is possible, how should I configure timer (how would the configuration code in C looked like?) Thank you for your answers, I appreciate your help.
2012-07-12 08:15 AM
Let me muse on this a little when I get some time.
Sub-microsecond stuff is not going to be soluble with interrupts, cortex parts are going to saturate at several hundred KHz. Your problem seems like it might be more slickly solved with a small CPLD/FPGA. The TIM/CH arrangement works really well for repetitive PWM stuff like 20 ms servos. I've posted some examples on the forum that can drive 4 servos from a single timer. With a little modification one could change the trajectory in the update interrupt. The other potential method of attack would be to run the time base continuously, use PWM, pull the width/duty to 0 (ie OFF), and then set the desired width in one update period, and set back off in the next. Have an update period of 1 or 2 ms, and a period of 20000/40000 cycles. The update could be reduced and the pins set ON over one or multiple periods, but at a rate serviceable by interrupt.2012-07-14 02:19 AM
The other potential method of attack would be to run the time base continuously, use PWM, pull the width/duty to 0 (ie OFF), and then set the desired width in one update period, and set back off in the next. Have an update period of 1 or 2 ms, and a period of 20000/40000 cycles. The update could be reduced and the pins set ON over one or multiple periods, but at a rate serviceable by interrupt.
This is a brilliant idea. Using PWM to generate single pulse works great. It needed a little tweaking on the timer constants and now it works perfectly! Thanks for your help.2012-07-14 02:46 AM
Awesome, you're welcome.
2015-08-12 07:20 AM
I have a similar problem, I want to generate one pulse that is triggered from code, not from activity on an input pin. My tolerances are quite large (pulse width: 90 ms +- 5 ms). Is it possible to achieve this without involving interrupts?
2015-08-12 07:29 AM
STM32F4xx_DSP_StdPeriph_Lib_V1.5.1\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_OnePulse ?