cancel
Showing results for 
Search instead for 
Did you mean: 

Servo not working with STM32F767Zi

VNaid.2
Associate

I'm trying to control a Servo motor (MG90S) using the STM32F767Zi by leveraging the TIM2 Channel 1 (PA0). 

The Servo requires a 50Hz frequency (20ms) signal. 

The APB1 bus gives TIM2 timer port 108MHz frequency. 

The Servo is powered through a 5V port through STM and STM is powered through USB type B cable from my laptop.

I'm using the below calculations for PSC and ARR and have given a Duty Cycle of 2.5% - 12.5%. (0.5ms - 2.5ms)

My Timer_freq TIM2(APB1) is 108MHZ(108000000)

Required Frequency is 50Hz

i.e PSC*ARR = 108000000/50 == 2160000

PSC = 2160-1

ARR = 1000

Duty Cycle given is: (since ARR = 1000 i.e 100%)

TIM2->CCR1 = 25 (0 degrees - 2.5%)

TIM2->CCR1 = 125 (180 degrees - 12.5%)

Code Snippet

MX_GPIO_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */
  HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
      TIM2->CCR1 = 25; // 0 degrees
      HAL_Delay(500);
 
      TIM2->CCR1 = 75; // 90 degrees
      HAL_Delay(500);
 
      TIM2->CCR1 = 125; // 180 degrees
      HAL_Delay(500);
 
    /* USER CODE BEGIN 3 */
  }

My servo is not responding. 

I used the same calculations to control my servo with STM32f103 (Bluepill) and it worked fine. 

I tried connecting the servo to an external power supply (ground being common between the Servo, STM32F7 and the power source) - Still no response from the Servo. Again, the Bluepill works with the same setup.

I have checked the 5V port of STM32F7 using a multimeter and it gives the correct voltage reading.

So, the next step that I’m planning to do is to check the signal port using an oscilloscope/logic analyzer. I’ll update on that soon.

It would be great if anyone can point out if I’m doing something wrong or help me with the right direction.

0693W00000QMbXyQAL.png

1 ACCEPTED SOLUTION

Accepted Solutions

I'd divide down to 1 MHz (PSC of 108-1), giving a tick rate of 1us, and ARR of 20000-1 for 20 ms

Then CCRx would be in us, 1500 would be top-center (1.5ms)

The F7 chip doesn't have a 5V pin, the "signal" would be 3.3V CMOS levels, but should be sufficient. Validate signal with a scope.

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

View solution in original post

1 REPLY 1

I'd divide down to 1 MHz (PSC of 108-1), giving a tick rate of 1us, and ARR of 20000-1 for 20 ms

Then CCRx would be in us, 1500 would be top-center (1.5ms)

The F7 chip doesn't have a 5V pin, the "signal" would be 3.3V CMOS levels, but should be sufficient. Validate signal with a scope.

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