The main function after the start of the processing flow:
1. peripheral initialization: HAL_Init ()
2. The system clock configuration
- RCC oscillator Initialization: HAL_RCC_OsConfig ()
- RCC clock initialization: HAL_RCC_ClockConfig ()
- The system tick timer initialization: HAL_SYSTICK_Config ()
3. Key GPIO initialization
- GPIO Port Clock Enable: __ HAL_RCC_GPIOA_CLK_ENABLE ()
- Operating mode
- Activating the pull-down or pull-
- Pin Initialization: HAL_GPIO_Init ()
4. serial port initialization
- Serial GPIO port is enabled: __ HAL_RCC_GPIOA_CLK_ENABLE ()
- Serial port initialization (containing the serial port hardware initialization): HAL_UART_Init ()
The timer is initialized encoder
- Timer Clock Enable: __ HAL_RCC_TIM3_CLK_ENABLE ()
- GPIO pins are initialized encoder
- GPIO Port Clock Enable: __ HAL_RCC_GPIOB_CLK_ENABLE ()
- Operating mode
- Activating the pull-down or pull-
- Pin Initialization: HAL_GPIO_Init ()
- Interrupt priority encoder configuration
- Set the interrupt priority: HAL_NVIC_SetPriority ()
- Enable interrupt request: HAL_NVIC_EnableIRQ ()
- Basic environmental timer initialization: HAL_TIM_Base_Init ()
- Timer Clock Source: HAL_TIM_ConfigClockSource ()
- Timer input capture environment initialization: HAL_TIM_IC_Init ()
- Output synchronization master timer mode: HAL_TIMEx_MasterConfigSynchronization ()
- Timer input capture configuration: HAL_TIM_IC_ConfigChannel ()
6. The encoder timer is started: HAL_TIM_Base_Start ()
7.L298N timer initialization
- Basic environment initialization: HAL_TIM_Base_Init ()
- Clock Source: HAL_TIM_ConfigClockSource ()
- Initialization comparison output (mcu comprises hardware initialization): HAL_TIM_PWM_Init ()
- Initialization: HAL_TIM_Base_MspInit ()
- Deinitialization: HAL_TIM_Base_MspDeInit ()
- Output synchronization master mode: HAL_TIMEx_MasterConfigSynchronization ()
- Brakes and dead-time configuration: HAL_TIMEx_ConfigBreakDeadTime ()
- Comparator Output 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. [Comparative channel output pulse timer 450, the timer period is 900, then the 50% duty cycle, the motor does not turn]
- GPIO pins are initialized
- 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 ()
8. encoder capture timer interrupt start: HAL_TIM_IC_Start_IT ()
9. The L298N PWM channel timer channels and a complementary output (motor can be controlled forward and reverse)
- HAL_TIM_PWM_Start() 、
- HAL_TIMEx_PWMN_Start()
10 cycles: the while (. 1) {}
Remarks:
The system tick timer interrupt callback function (tick timer interrupt occurs once every access to the callback function once): HAL_SYSTICK_Callback ()
Input capture timer interrupt callback function: HAL_TIM_IC_CaptureCallback ()
Redirection C library function printf: int fputc (int ch, FILE * f) {}
Redirection C library function getchar, scanf: int fgetc (FILE * f) {}