Skip to main content
ADevi.1
Associate
March 17, 2020
Question

RC Radio PWM signal, problems reading

  • March 17, 2020
  • 9 replies
  • 2079 views

Hi,

Im trying to resurrect this project from 2015 (Software AWD control for RC Cards using 4x brushless motors):

https://github.com/hammerfet/BrinirController

Ive built his VS2013 solution and got all that side working fine. However, next is to determine I can read the RC Radio signal (standard RC drone Turnigy 9x and FRSky V8FR-II receiver) and Im getting problems. The signals are just two, throttle and steering and connected to PA0 and PA1 on a STM32 F407 discovery.

Sometimes it doesnt read anything, sometimes it reads it once occasionally it reads everything fine.

Here is the IO code:

/* TIM2 Init - PPM Inputs */

htim2.Instance = TIM2;

htim2.Init.Prescaler = PPMMEASUREPRESCALER;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 65535;

htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

HAL_TIM_Base_Init(&htim2);

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

HAL_TIM_Base_Start_IT(&htim2);

and some more references in config.h:

  #define PPMMEASUREPRESCALER 4

  #define RECEIVERMINSIGNAL 500

  #define RECEIVERMIDSIGNAL 25000

  #define RECEIVERMAXSIGNAL 34000

Is there anything obviously wrong here? Anything I should know about connecting RC Radio PWM to the F407?

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
March 17, 2020

Timers have a PWM input "mode" - use it. Read the timer chapter in RM.

JW

ADevi.1
ADevi.1Author
Associate
March 21, 2020

Right, read the chapter, looked at the code and tried every combo of modes.

Here is the default:

GPIO_InitStruct.Pin = REC1PIN | REC2PIN | FB1PIN | FB2PIN | FB3PIN | FB4PIN;

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;

GPIO_InitStruct.Pull = GPIO_PULLUP;

HAL_GPIO_Init(RECPORT/*same as FBPORT*/, &GPIO_InitStruct);

REC1 and 2 are PA0 and PA1 on TIM2.

As I said, it works sometimes (5% of the time) and when its displaying anything than zero it seems to just capture the first reading then stops.. but again not 100% of the time. Is there a time out or something?

Piranha
Principal III
March 22, 2020

Well, now read the GPIO chapter, especially the alternate function configuration. =)

waclawek.jan
Super User
March 21, 2020

I don't understand what exactly you do and I don't use Cube, but maybe you should try to adopt the example from [STM32Cube_FW_F4_Vxxxx]\Projects\STM32F4-Discovery\Examples\TIM\TIM_PWMInput\

JW