如题,当单片机供电由J-LINK仿真器提供,电源为3.2468V,占空比100%时,测量电压为3.2378V,差不多相差10MV。当单片机供电由TPS70933提供,电源为3.2973,输出测量为3.2681V,相差30MV。
其中均采用定时器1的互补2通道。
Tim1_Init(7199,0);
void Tim1_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = arr; // ´Ó×°±È½Ï×î´ó 18k = 72000/ 6000= 12k
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // ģʽ Ôö
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // ·ÖƵ
// TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = arr ;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
//TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);//¼ÆÊý¿ªÊ¼
TIM_CtrlPWMOutputs(TIM1, ENABLE);
// TIM_ClearFlag(TIM1, TIM_FLAG_Update);
// TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //ÇåÖжϱê־λ
// TIM_ITConfig(TIM1,TIM_IT_Update ,ENABLE); //´ò¿ªÖжÏ
//ÅäÖÃTIM1µÄ¸üÐÂÖжÏʹÄÜ
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//Ö¸¶¨ÇÀÕ¼ÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//Ö¸¶¨ÏìÓ¦ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
|