cancel
Showing results for 
Search instead for 
Did you mean: 

Reading incoming PWM signal

Posted on May 14, 2017 at 03:23

How can i read an incoming PWM singal coming from my rc receiver ?? i kept searching and i found something called input capture but i couldn't understand it ?? so i will be glad if you can provide me an example.

8 REPLIES 8
S.Ma
Principal
Posted on May 14, 2017 at 14:51

Timer is free running, say counting up and then overflows back to 0x0000.

From this timer counting value, are up to 4 registers you control: The compares.

Either you program a value (say 0x4000) and connect it to a GPIO as OUTPUT compare to make PWM with 25% duty cycle, or you connect a GPIO input and a chosen edge will take a snapshot of the timer instant value and save it in the compare register (usually triggering an interrupt) for you to use this captured value. This is the INPUT capture mecanism.

So to measure a PWM, you can use input captures to capture rising/falling edge time and deduct the period, high and low time of the incoming signal. 

Posted on May 14, 2017 at 16:23

Also PWM Input mode, SPL and HAL have examples, and examples for servo reading have also been published to the forum. A brief search should yield some on-point threads.

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 16, 2017 at 10:21

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6lx&d=%2Fa%2F0X0000000bv2%2FPM_kQS0IyTOl50SyLvwq1rBd3zOgAzQGFe.4hUymtbQ&asPdf=false
Posted on May 16, 2017 at 14:01

Faced similar problem a while ago. Not sure why your code doesn't work, but in my case it was due to improper counting unit reset procedure: counting unit was running whithout reset, and therefore I got random numbers all the time.

So, what I did to get it fixed:

- use the Slave Reset mode feature on rising edge: it automatically resets counting unit to zero when a new pulse arrives

- configured two IC channels, 1st for rising edge direct TI and another one for falling edge indirect TI.

How it works:

Rising edge of a new pulse resets counting unit to zero, then falling edge of this pulse triggers IC of channel 1. Rising edge of next pulse triggers IC of channel 2 and again resets counting unit - starts new cycle. You would only need to handle IC channel 2 interrupts and get values of both IC channels. Channel 1 value will reflect pulse width, channel 2 - duty cycle width.

Posted on May 16, 2017 at 18:16

TIM1 is an Advanced Timer, you need additional configuration fields that need to be populated. You'd also need TIM_CtrlPWMOutputs(TIM1, ENABLE);

Missing code here, but the values would need to be in uint16_t for the maths to work properly.

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 17, 2017 at 00:28

I will give it a try.

Posted on May 17, 2017 at 00:30

I did this in TIM4 but i got mixed up values, like when i try to separate data thay are all affecting the first value. Today i will provide you with a screenshot of this.

Posted on May 17, 2017 at 10:38

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6s9&d=%2Fa%2F0X0000000bx1%2FyIo7V.v2_EPT3dGCDymEROBtRuHBETkwJ8BzWqUCNgI&asPdf=false