标题:
STM32F4 HAL_PWM测频程序
[打印本页]
作者:
zlkj
时间:
2024-10-8 16:09
标题:
STM32F4 HAL_PWM测频程序
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)
2024-10-9 02:09 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1