cancel
Showing results for 
Search instead for 
Did you mean: 

Generating trigg signals relative input capture

dangraf
Associate II
Posted on May 27, 2015 at 15:30

Im trying to understand the input captre and output compare modes in the STM32 to fit my needs.

This code is supposed be used in a shotdetector for droplets for our test equipmnet.

Currently I'm using the STM32F3discovery board

So, I have 2 input channels and two ouput channels

ch0 - input capture - receives a pulse when droplet is supposed to be ejected (trigg signal)

ch1 - input capture - receives a pulse if a droplet is passing by my sensor (drop detector)

Ch3 - ouput compare - generates a pulse to a camera (about 10us pulse width) to capture the drip

ch4 - ouput compare - generates a pulse to a flash (about 100ns pulse width) to freese the drip in the picture.

The trigg-signal is also used to for a counter to know how may dots that was supposed to be ejected.

The detect signals is used for a counter to know how may dots that actually was ejected.

the input captue part is already finished and working. It's the output compare part that I have some questions about.

I would like to generate the the camera and flash pulses in relative the drop detetor signal. I also need to keep track of the time. Example, when i get the signal from the drop-detector (eg 23us after trigg signal on ch1) I would like to generate a trigg for the camera after 10us  and a flash signal after 20us. The logged times for the camera and flash wold be 33us for camera and 43us for the flash for that exact droplet (relative the trigg-signa from ch0l).

I have looked at the ''one pulse mode'' but it seems like it's clearing the clock.

Is it posssible to have a free-running clock (eg timer2) for the input catpture pins and use a second clock (eg timer 3) for the one pulse mode output pins? then it would be possible for me to captue the time between the two trigg-signals and then add an offset to generate the output signals.

Another question that popped up is when looking at reference code ''stm32f3xx_hal_tim.c in STM32Cube_FW_F3_V1.1.0'' it seems like the OPM is only supported on CH0 and CH1. But I can't find anything about this in the documentation.

Is it possible to use one pulse mode on channel 2 and 3 as well?

Or is there a better solution to the problem?

Thanks/

Daniel Grafström
7 REPLIES 7
Posted on May 27, 2015 at 17:39

The key thing to understand is there is a single counting element in each timer. You can't generate arbitrary pulses within the period of the timers. The only way I'm aware of effectively placing edges anywhere in the run of the counter is to use Toggle mode.

To use One-Pulse mode you'd have to trigger it into a second counter/timer
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dangraf
Associate II
Posted on May 27, 2015 at 20:56

Thanks. I know that one counter can only count on one variable.

I was thinking maybe there is a way to prevent the timer to be reset.

Eg.

1. I get an input catpure interrupt at showing time 0xF2

2. I get the detect time at time 0xF9 and then writing to the delay register that I want a trigger at time 0xF9+0x4 = 0xFD  for camera and 0xF9+0x6 = 0xFF for flash

3 I set the period register to 0x4 so trigger signal will become low at time 0xFD+4 = 0x01 for camera and 0x03 for flash.

I know that the counter is 16 bit this is just a simplified example of how it might could work.

Anyway if this is not an option, how do I setup the the input captue for one timer and the output compare for another timer?

I'm afraid that the toggle mode will be too slow and might be affected by other interupts since the pulse width is pretty short (below 100ns).

Is there any examples of how to setup input capture for eg timer2 and use timer 3 for one pulse mode output compare? I've tried to read the datasheet (STM32_ref2_DM00043574 General-purpose timers (TIM2/TIM3/TIM4)) but do not fully understand all the functionality.

Best regards/

Daniel Grafström

Posted on May 27, 2015 at 21:32

Slaving a TIM to generate ''One Pulse'' x5, periodically. On a non-advanced timer you'd get to generate a single pulse, rather than variable count, as the don't have a Repetition Counter.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Stop%20PWM%20output%20after%20N%20steps&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2058]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FStop%20PWM%20output%20after%20N%20steps&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=2058

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 27, 2015 at 21:34

Check the Reference Manual for internal trigger mapping that would get a Master TIMx_CHx to fire a slave

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dangraf
Associate II
Posted on May 28, 2015 at 15:36

Thanks a lot! that should solve my problem.

I will test this.

Best regards/

Daniel

dangraf
Associate II
Posted on June 03, 2015 at 14:38

I'm still struggling with this problem.

The ''one pulse mode'' does not seem to solve my problems.

the period of ''delay''+''pulse'' is the same for all channels on the same timer.

I need to have the ''pulse'' fixed to 100ns+-10ns and be able to change the ''delay'' for each channel separately.

Is there a workaround for this?

I have also tried to trigger timer8 from timer2 channel 2 (capture compare) but are not able to do so.

It is easy to setup timer8 to trigger on the timer2 output. But I can only find settings to generate trigger signals from timer2 output compare. I need to trigger on input capture.

TIM_TRGOSource_Reset               

TIM_TRGOSource_Enable             

TIM_TRGOSource_Update 

TIM_TRGOSource_OC1 

TIM_TRGOSource_OC1Ref 

TIM_TRGOSource_OC2Ref 

TIM_TRGOSource_OC3Ref  

TIM_TRGOSource_OC4Ref 

Is there any other way?

which chapter exactly is the ''internal trigger mapping'' ?

Posted on June 03, 2015 at 17:20

Not sure this is solvable with general purpose timers, given the finite resources, and inflexibility. Sounds like some digital logic clocking at 100 MHz is what you need.

You can pick the trigger output on the master, and the source timer on the slave.

0690X000006031VQAQ.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..