cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 InputCaptures rising/falling on TIM3 not working like expected

bladeboarder1
Associate
Posted on July 12, 2014 at 18:41

Hi there,

I am trying to read in an PWM-Signal on my STM32F4-Microcontroller. I know there is a PWM-Input function to get Frequency and Dutycycle, but I would like to do it ''manually with Inputcaptures.

The Signal I want to read is a normal RC-Signal, 20ms long with 9 pulses. 8 pulses for signal transmitting and one final pulse filling the rest of the time with a ''big'' pulse (minimum 3ms long). the first 8 pulses will be 0,5ms-1,5ms high plus 0,5ms low for each.

I want to have one timer (TIM3) with Inputcapture1 for Rising, InputCapture2 for Falling-Edge detection and a Outputcompare which only counts for 3ms to detect the last ''big'' pulse.

My Problem is that my TIM3_IRQHandler only gets active when the rising-InputCapture creats interrupt. I don't get the mistake in my code. If I DISABLE TIM_IT_CC1(Rising) than the IRQHandler also gets active through Falling-Edge.

I am sending Text over Bluetooth to read in on PC. I am getting this:

... --------------------------------------------- -RISING-EVENT- sumLength: 4512 -OUTPUTCOMPARE-RESET- 3ms has gone: Reset long Pulse-timer -FALLING-EVENT- PulseLength: 2999 -OUTPUT-COMPARE->----------- Long Pulse captured ----------- --------------------------------------------- ... The lined line should always appear if TIM3_IRQHandler pops up. So I expected something like this: ... --------------------------------------------- -RISING-EVENT- sumLength: 4512 -OUTPUTCOMPARE-RESET- 3ms has gone: Reset long Pulse-timer --------------------------------------------- -FALLING-EVENT- PulseLength: 2999 --------------------------------------------- ...

I would be so happy if anyone could help me about this.

The Code about the magic is in the attachments!!!

Befor I miss to tell: the Timer clock and GPIO clock is enabled seperatly,

if it helps I could post more parts of the code.

Greatings,

Florian

#stm32f4-inputcapture
3 REPLIES 3
Posted on July 12, 2014 at 19:55

That's far more of a mess than I'm going to touch. There's a confused jumble of PWM Input and Input Capture initialization. Input Capture doesn't need slave mode, you just need to set up the channels, and if you want to pair ch1/ch2 capture channels with a singular input channel you need to set the TIx routing.

Not sure of the value of timing out at 15 ms when the period's going to be 20 ms. Or how that figures into the math to compute the frequency/pulse-width etc.

You seem to assume that the BlueTooth output takes zero time.

4 Channel Input Capture

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/PWM%20Input%20capture%20doesnt%20work%20on%20Ch34%20pair&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&...

1 Channel PWM Input

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F103ZE%20TIM1%20InputCapture&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=107

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bladeboarder1
Associate
Posted on July 12, 2014 at 20:18

Hi clive,

Hart but clear answer, thank you so far!!!

I have read alot of your comments already, I definitly take any advice of you seriously!! 

Would you recomment using PWM-Input function with reading out Dutycycle and Frequency directly?

Thanks for the links, too!

Posted on July 12, 2014 at 20:42

PWM Input works well with high frequencies, but consumes a whole timer per signal.

Input Capture on a 50 Hz (20ms) signal shouldn't challenge a processor running this fast.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..