2017-08-02 11:25 AM
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.
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!
2017-08-02 11:42 AM
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
2017-08-02 03:55 PM
Nice challenge. I believe it could be made to run with no software (except setup) with two coupled timers and a DMA.
JW
2017-08-02 03:58 PM
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
2017-08-02 06:52 PM
One could implement a delay line, with a pattern buffer.
Helpful parameters would be expected pulse widths, repetition rate, tolerable jitter, etc.
2017-08-03 02:49 AM
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
2017-08-03 05:45 PM
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
2017-08-03 05:47 PM
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!
2017-08-03 06:58 PM
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.
2017-08-04 03:06 AM
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