本帖最后由 clz918 于 2014-1-10 13:38 编辑
现在用T4的CH1/PB6输出脉冲,下面的代码可以看到T4的2个中断,也就是Y2Y3在不断取反,应该已经比较了,我不确定这时OC1ref有没有动作, PB6没有输出。问题可能出在那里呢? void GPIO_Configuration(void) { RCC->APB2ENR|=0XFFFF; //GPIO CLOCK EN; RCC->APB1ENR|=0Xffffffff; //GPIO CLOCK EN; //4 INPUT;3 OUT PUT B 特殊输出 GPIOB->ODR=0XFFFF; GPIOB->CRL=0x3BB44444; AFIO->MAPR=0X04004850; } void start_timer4(unsigned long data_in) { unsigned long data1=0,data2=0; data1=(data_in>>16) &0x0000ffff; data2=data_in/(data1+1); TIM4->ARR=data2; TIM4->PSC=data1; TIM4->CR1|=0x01; } void Timer4_Init(void) { RCC->APB1ENR|=1<<2;//TIM4 clock enable TIM4->ARR=65535; //periode TIM4->PSC=0; //timer clk=72/(psc+1) TIM4->DIER|=1<<0; TIM4->DIER|=1<<6; TIM4->CCR1=30000; TIM4 ->CCMR1 |= 7 <<4; //设定引脚输出模式 TIM4 ->CCMR1 |= 1<<3; //允许预装载 TIM4 ->CCER |= 1<<0; //OC1 输出使能 TIM4->DIER |=1<<1; MY_NVIC_Init(7,0,TIM4_IRQn,4); start_timer4(72000); }
unsigned int datat1=0;
void TIM4_IRQHandler(void) { if ((TIM4->SR & 0x0001) != 0) { Y2++; start_timer4(20000); TIM4->SR &= ~(1<<0); } if ((TIM4->SR & (1<<2)) != 0) { Y3++;
datat1=TIM4->CCR1;
datat1=datat1+10000;
TIM4->CCR1=datat1; TIM4->SR &= ~(1<<2); } } |