我要实现PWM交替输出50KHz和100KHz,占空比都是50%,在同一个管脚上。
现在用TIM,捕获比较方式,每次改变频率时,都有从新设置,拿示波器看,发现频率交替时,有大概50us的停顿时间。
请问香主,STM32能否实现无缝交替,或者是很小,只有几us的停顿时间?多谢先。
程序如下,每次交替,都有从新设置,但只改变一下红色部分的值。
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Enable GPIOE clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM1,ENABLE);
/* Configure PE11 PE13 as IPD */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
TIM_DeInit(TIM1);
/* ---------------------------------------------------------------
TIM1 Configuration: Free Up Count Mode:
TIM1CLK = HCLK(32MHz), Prescaler = 1, TIM1 counter clock = 32 MHz
--------------------------------------------------------------- */
TIM1->BDTR=0x0000;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 320-1;
TIM_TimeBaseStructure.TIM_Prescaler = 1-1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); |