cancel
Showing results for 
Search instead for 
Did you mean: 

Hello,I want to generate R/C signal in stm32f446re nucleo board.But i don't understand that how to do it.Can anyone tell me about that?

SM3
Associate II

Hello, I want to connect my FLYsky radio reciever to stm32f446re for which an rc signal in required.The Rc signal has duty cycle from 1500 us to 2000 us.But i can not understand how to do it with the help of timers.If you have a code about that please share me.

4 REPLIES 4

Need to configure the TIM(s) to generate a 20ms (50 Hz) signal. Set the prescaler to get you to 1 MHz (1us ticks), then the period can be 20000us

Configure the individual channels in PWM and program the pulse width into the CCRx registers.

Posted F4 servo examples in the past.

Check the CubeF4 HAL examples for TIM with PWM output

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
berendi
Principal

Assuming the necessary RCC clocks are set, and the pin is already in alternate mode, AF number for the timer is set.

Set the prescaler to downscale the timer clock to 1 us (1 MHz). Recall the APB clock frequency of the timer, put that value - 1 in PSC

TIM->PSC = APBxTIM_MHZ - 1;

As the PSC register is buffered, generate an update event to make it effective

TIM->EGR = TIM_EGR_UG;

Set the ARR register to the period of the required signal - 1 (in microseconds)

TIM->ARR = PERIOD_us - 1;

Set the CCRx register to the required duty cycle, where x is the timer channel used.

TIM->CCRx = DUTY_us;

Set PWM mode 1 in the Capture/Compare Mode Register CCMRy (y=(x+1)/2)

TIM->CCMRy = TIM_CCMRy_OCxM_1 | TIM_CCMRy_OCxM_2;

Enable compare output in CC1E

TIM->CCER = TIM_CCER_CCxE;

Enable the counter

TIM->CR1 = TIM_CR1_CEN;

Now you should be able to observe the signal on the timer output pin.

See the timer register descriptions and the functional description in the reference manual.

Thank you,I will try it.

Thank you,I will try it.