Skip to main content
mohamedmostafamousa1991
Associate III
May 14, 2017
Question

Reading incoming PWM signal

  • May 14, 2017
  • 2 replies
  • 4882 views
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.

    This topic has been closed for replies.

    2 replies

    S.Ma
    Principal
    May 14, 2017
    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. 

    Tesla DeLorean
    Guru
    May 14, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mohamedmostafamousa1991
    Associate III
    May 16, 2017
    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
    denis2
    Associate
    May 16, 2017
    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.