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 */ } 希望高手指点 |
修改PWM占空比:
谢谢指教