- int main(void)
- {
- /* USER CODE BEGIN 1 */
- uint8_t i=1;
- /* USER CODE END 1 */
- /* MCU Configuration----------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART3_UART_Init();
- MX_USB_OTG_FS_PCD_Init();
- MX_TIM10_Init();
- MX_TIM2_Init();
- /* USER CODE BEGIN 2 */
- HAL_UART_Receive_IT(&huart3,&rxbuf,1);
- HAL_TIM_PWM_Start(&htim10,TIM_CHANNEL_1);
- HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);
- HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_2);
-
- // PWM_ChangeDuty(20);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- PWM_ChangeDuty(i);
- HAL_Delay(100);
- // PWM_ChangeDutyTest();
- printf("PWM_Freq is %.4f\n",Freq_Capture);
- printf("PWM_Duty is %.4f\n",PWM_Duty);
- i++;
- if(i>99)
- {
- i=1;
- }
- }
- /* USER CODE END 3 */
- }
复制代码
原理图: 无
仿真: 无
代码:
STM32F4_PWM.7z
(318.59 KB, 下载次数: 7)
|