HAl L298N DC motor rotation control library notes

Process: The main function -> System Clock Configuration -> Advanced timer initialization -> mcu hardware initialization -> GPIO pins are initialized

 

1. The main function

  • All a peripheral initialization:. HAL_Init ()
  • b. The system clock configuration
  • c. Advanced timer initialization
  • d start timer:. HAL_TIM_BASE_Start ()
  • e starts timer channels and a complementary channel PWM output:. HAL_TIM_PWM_Start (), HAL_TIMEx_PWMN_Start ()
  • f endless loop:. while (1) {}

 

2. The system clock configuration

  • a.RCC oscillator Initialization: HAL_RCC_OsConfig ()
  • b.RCC clock Initialization: HAL_RCC_ClockConfig ()
  • . C system tick timer initialization: HAL_SYSTICK_Config ()

 

3. Advanced timer initialization

  • . A basic environment initialization: HAL_TIM_Base_Init ()
  • . B Clock Source: HAL_TIM_ConfigClockSource ()
  • . c initialization comparison output (comprising mcu hardware initialization ): HAL_TIM_PWM_Init ()
  • d master output mode synchronization:. HAL_TIMEx_MasterConfigSynchronization ()
  • . E braking configuration and dead time: HAL_TIMEx_ConfigBreakDeadTime ()
  • . F compare the output channel configuration: HAL_TIM_PWM_ConfigChannel ()
    • Timer actual clock frequency: 72MHz / (timer prescaler +1) = 36MHz
    • PWM frequency is: timer actual clock frequency / (timer period +1), [900, then the timer period, 36MHz / (900 + 1) = 40Khz]
    • The actual frequency PWM: PWM frequency / (Advanced timer Repeat Count Register value of +1), [Advanced timer repeatedly count register value is 0, then, 40KHz / 0 + 1 = 40KHz]
    • The PWM duty cycle is: Comparator output pulse timer / timer cycle * 100%, 50% duty cycle the motor does not rotate. [ Timer Channel comparator output pulses 450, 900 for the timer period, then the 50% duty cycle, the motor does not turn]
  • g.GPIO pin initialization

 

4.mcu hardware initialization : HAL_TIM_Base_MspInit (), HAL_TIM_Base_MspDeInit ()

 

5.GPIO pin initialization

  • a.GPIO Port Clock Enable: __ HAL_RCC_GPIOA_CLK_ENABLE ()
  • b Set IO pins:. Pin
  • c Set operating mode:. Mode
  • d Set Speed:. Speed
  • . E complete initialization: HAL_GPIO_Init ()

 

Guess you like

Origin www.cnblogs.com/kerwincui/p/12032362.html