cancel
Showing results for 
Search instead for 
Did you mean: 

Timer generate a delayed pulse with same width as input

Alex Z
Associate II
Posted on August 02, 2017 at 20:25

Hi all, is it possible to use timer to capture the input pulse, and generate the output pulse with same width and a certain delay.

0690X00000603zfQAA.jpg

I have tried use one pulse mode with connect input on two channel, one trigger with rise edge and one with falling. but it did not work.

Thanks all for help!

9 REPLIES 9
Posted on August 02, 2017 at 20:42

Pretty sure one-pulse isn't going to work, the TIM has a single counting element, which you'd want in maximal mode.

Time stamp the input edges, and use toggle of place output edges ie CCR = CNT + x, CNT + y

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

Nice challenge. I believe it could be made to run with no software (except setup) with two coupled timers and a DMA.

JW

Posted on August 02, 2017 at 22:58

Clive's trick with toggle would make it doable with your method on a single timer, but only in the special case that the pulse is guaranteed to last longer than the delay (as is the depicted case).

JW

Posted on August 03, 2017 at 01:52

One could implement a delay line, with a pattern buffer.

Helpful parameters would be expected pulse widths, repetition rate, tolerable jitter, etc.

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

One could implement a delay line

Wasteful in RAM but yes that's an option too. Nice thinking out of the box.

Helpful parameters [...]

+1

Jan

Posted on August 04, 2017 at 00:45

Hi Clive, thanks so much for your reply! The expected pulse width is from 50 micro secs to few hundred micro secs. The delay should be couple hundred nano secs. So I want to implement with hardware method.

Can you give me some more detail of the delay line approach? Thanks

Posted on August 04, 2017 at 00:47

Hi JW, thanks so much for your reply! 

The expected pulse width is from 50 micro secs to few hundred micro secs. The delay should be couple hundred nano secs. I want to implement with no software. Can you give me some instruction about your idea?

Thanks!

Posted on August 04, 2017 at 01:58

Few hundred nano-seconds, couldn't you just use a shift register?

To move from GPIO bank to another, you could use two circular buffers on DMA2 (GPIOX->MEM, MEM->GPIOY), triggered via a TIM and of sufficient depth for the delay. Pretty shallow for hundreds on nano-seconds, going to be rather high speed to reduce jitter. Would be better for servo type rates.

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

The idea is to delay the edges rather than trying to copy the whole waveform. We've done this in 'semi-analog' back then - an edge detector (XOR of input with a slightly-RC-delayed copy of itself) triggered a one-shot (with a potentiometer in its RC so that delay could be set manually) and its output clocked a div-2 (half-7474 with /Q fed back to D). This works only if the delay is shorter than the distance of edges (i.e. both the pulses and distances between them should be long enough) and the D has to be reset properly otherwise it outputs a delayed but inverted version of the input.

Now do exactly the same: feed the input into CH1, set trigger to TI1 Edge Detector (TI1F_ED - TIMx_SMCR.TS=0b100), set slave mode to Trigger (TIMx_SMCR.SMS = 0b110). Set TIMx_ARR to the longest possible delay - I repeat it MUST be shorter than the distance of edges, set the same value to TIMx_CCR2 for maximum delay. CH2 set to output compare (TIMx_CCMR1.CC2S = 0b00), set mode to toggle (TIMx_CCMR1.OC2M = 0b011) and enable (TIMx_CCER.CC2E=1). Make sure you do this initialization while the input is low. You can then adjust delay by value of TIMx_CCR2. 

JW

[EDIT] i've forgotten - set the OnePulse mode - and of course enable - in TIMx_CR1