2014-07-12 09:41 AM
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-inputcapture2014-07-12 10:55 AM
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 1 Channel PWM Input2014-07-12 11:18 AM
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!2014-07-12 11:42 AM
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.