STM32F1

STM32F1, STMCubeMX, PWM, 9g micro servo

CoyoteUgly 2018. 8. 6. 13:35

STM32F1, STMCubeMX, PWM, 9g micro servo



0. 참고 사이트


1. 모듈



2. HW 구성

5V로 구동함


3. RCC > HSE > Crystal/Ceramic Resonator


4. Timer Enable

  • Clock Source : Internal Clock
  • Channel1 : PWM Generation CH1


5. Clock Configuration > 72MHz


6. Configuration > TIM


7. Parameter Settings

  • Prescaler : 72-1
  • Counter Period : 20000
/*
    20ms ( 50Hz )

    1) 72MHz System Clock, Prescaler 1MHz Timer Clock
        Prescaler = 72MHz / 72MHz - 1 = 1MHz
    2) 1MHz Timer Clock, 50Hz
        Period = 1MHz / 50Hz = 20,000
*/


8. SW 구성

while (1)
{
    htim3.Instance->CCR1 = 1500; // pos 0' , 20,000 * 7.5 / 100        
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);        
    HAL_Delay(1000);
    HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);

    htim3.Instance->CCR1 = 2300; // pos 90' , 20,000 * 11.5 / 100        
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
    HAL_Delay(1000);
    HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);

    htim3.Instance->CCR1 = 700; // pos -90' , 20,000 * 3.5 / 100        
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
    HAL_Delay(1000);
    HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
}


9. 소스


50% duty 상태