Home > other >  About the STM32 PWM wave output configuration
About the STM32 PWM wave output configuration

Time:11-16

1, open the clock configuration RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIMX, ENABLE);//can make clock, timer X

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//can make GPIO peripheral clock can make


Set the port to reuse the push-pull output GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;//multiplexing push-pull output
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_6 | GPIO_Pin_7;//configure port
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

2, set the TIM1 ARR and PSC, opens the TIMX clock, we need to set the value of ARR and PSC two registers to control the output of the PWM
Cycle,
TIM_TimeBaseStructure. TIM_Period=arr;//set up automatic heavy load values
TIM_TimeBaseStructure. TIM_Prescaler=PSC;//set the preassigned frequency values
TIM_TimeBaseStructure. TIM_ClockDivision=0;//set the clock division: TDTS=Tck_tim
TIM_TimeBaseStructure. TIM_CounterMode=TIM_CounterMode_Up;//counting up mode
TIM_TimeBaseInit (TIM1, & amp; TIM_TimeBaseStructure);//based on the specified parameters initialization TIMx



To be continued,,,,,,,,,,,,,,
  • Related