完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
int main(void)
{ /* USER CODE BEGIN 1 */ myFlag. power = 0; Vtimer0[1]=0; /* 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_DMA_Init(); MX_ADC1_Init(); MX_TIM1_Init(); MX_USART1_UART_Init(); MX_TIM14_Init(); /* USER CODE BEGIN 2 */ HAL_ADCEx_Calibration_Start( hadc1);//ADC自校验 HAL_ADC_Start_DMA( hadc1,(uint32_t *)ADC_ConvertedData,ADC_SAMPLE);//启动AD转换并使能DMA传输和中断 HAL_TIM_Base_Start_IT( htim1); //初始化定时器中断 HAL_TIM_Base_Start_IT( htim14); //初始化定时器中断 HAL_TIM_PWM_Stop( htim1,TIM_CHANNEL_1); HAL_TIMEx_PWMN_Stop( htim1,TIM_CHANNEL_1); //__HAL_TIM_CLEAR_FLAG( htim6,TIM_FLAG_UPDATE); //这是关断定时器语句 /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_TIMEx_PWMN_Start( htim1,TIM_CHANNEL_1); HAL_TIM_PWM_Start( htim1,TIM_CHANNEL_1); HAL_Delay(500); ADC_ConvertedData[3]; //htim1.Instance->sTimerxRegs[0].PERxR = 50000;//通过修改重装载值PER,从而修改PWM的频率 //htim1.Instance->sTimerxRegs[0].CMP1xR = 11504;//通过修改比较值CMP,从而修改占空比 //上面两个语句在STM32G071不能用啊 } /* USER CODE END 3 */ } 希望高手指点 |
|
相关推荐
2个回答
|
|
|
|
|
|
sh memory and the processor registers */ void HAL_MspInit(void){ /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_SYSCFG_CLK_ENABLE(); / * Configure the system clock */ /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */}
/ * * @brief TIM_Base MSP Initialization * @param htim_base: TIM_Base handle pointer * @retval None */ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef tid) { nue ... } */ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM1) { __HAL_RCC_TIM1_CLK_ENABLE(); } } / * * @brief TIM PWM_MspInit * @param htim_pwm: TIM PWM handle pointer * @retval None */ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef tid) { nude ... } */ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if (htim->Instance == TIM1) { __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); USART1_Clk_Init(); } } int main(void) { /* USER CODE BEGIN 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_TIM1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ // Set the PWM frequency __HAL_TIM_SetPrescaler(&htim1, 271); // 271 corresponds to a frequency of 1 kHz // Set the PWM duty cycle __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_1, 200); // 200 corresponds to a duty cycle of 78% // Start the PWM generation HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1618 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1545 浏览 1 评论
979 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
683 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1597 浏览 2 评论
1863浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
645浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
516浏览 3评论
532浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
505浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 13:32 , Processed in 0.745259 second(s), Total 82, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号