2015-05-27 06:30 AM
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 boardSo, I have 2 input channels and two ouput channelsch0 - 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 dripch4 - 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öm2015-05-27 08:39 AM
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/timer2015-05-27 11:56 AM
2015-05-27 12:32 PM
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¤tviews=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=20582015-05-27 12:34 PM
Check the Reference Manual for internal trigger mapping that would get a Master TIMx_CHx to fire a slave
2015-05-28 06:36 AM
2015-06-03 05:38 AM
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'' ?2015-06-03 08:20 AM
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.