两天前自己配置的定时器1PWM输出,当时能用,同学还看到了的,今天来突然不能用了,大神能不能帮忙看下代码有没有错误
GPIO_InitTypeDef GPIO_InitStructure;
RCC->APB2ENR|=1;//enable the clock of Timer1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_TIM1 );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_TIM1 );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_TIM1 );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_TIM1 );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_Init(GPIOA,&GPIO_InitStructure); //3õê¼»ˉPA
TIM1->ARR=1000; //auto reload
TIM1->PSC=84;
TIM1->CCMR1|=6<<4; //CH1 PWM1 mode
TIM1->CCMR1|=6<<12; //CH2 PWM1 mode
TIM1->CCMR2|=6<<4; //CH3 PWM1 mode
TIM1->CCMR2|=6<<12; //CH4 PWM1 mode
TIM1->CCMR1|=1<<3; //CH1 preload enable
TIM1->CCMR1|=1<<11; //CH2 preload enable
TIM1->CCMR2|=1<<3; //CH3 preload enable
TIM1->CCMR2|=1<<11; //CH4 preload enable
TIM1->CCER|=1; //enable OC1
TIM1->CCER|=1<<4; //enable OC2
TIM1->CCER|=1<<8; //enable OC3
TIM1->CCER|=1<<12; //enable OC4
TIM1->CCER|=0<<1; //oc1 active high
TIM1->CCER|=0<<5; //oc2 active high
TIM1->CCER|=0<<9; //oc3 active high
TIM1->CCER|=0<<13; //oc4 active high
TIM1->BDTR|=1<<15; //enable OC,BDTR mode=1
TIM1->BDTR|=1<<14; //enable auto output
TIM1->EGR|=1;
TIM1->CR1|=1<<7; // enable ARPE
TIM1->CCR1=CCR1;
TIM1->CCR2=CCR2;
TIM1->CCR3=CCR3;
TIM1->CCR4=CCR4;
TIM1->CR1|=1; //enable timer1
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
不好意思,误导大家了。代码是正确的。供大家参考。
一周热门 更多>