先上代码
[mw_shl_code=c,true]void TIM1_PWM_init(u16 arr,u16 psc)
{
RCC->AHB1ENR|=1<<0; //??PA?±??
GPIO_set(GPIOA,PIN8,GPIO_MODE_AF,GPIO_OTYPE_PP,GPIO_SPEED_100M,GPIO_PUPD_NONE);//PA8?????????????ì??????100M??????????
GPIO_AF_set(GPIOA,8,1);//°?PA8???????¨?±?÷1
RCC->APB2ENR|=1<<0; //??TIM1?±??
TIM1->ARR=arr;
TIM1->
SC=psc;
TIM1->CCMR1&=~(0X07<<4);
TIM1->CCMR1|=0X06<<4;//PWM????1
TIM1->CCMR1|=1<<3;//?¤×°??????
TIM1->CR1|=1<<7;//×???×°??????
TIM1->CR1|=1<<4;//?ò??????????
TIM1->CCER&=~(1<<1);//?????????§
TIM1->CCER|=1<<0;//PWM????????
TIM1->BDTR|=1<<15;//????OC OCN
TIM1->CCR1=100;
TIM1->EGR|=1<<0;//???????ù???????÷
TIM1->CR1|=1<<0;//??TIM1?¨?±?÷
}[/mw_shl_code]
这是输出波形
放大后频率,占空比都很正常,但是把时基调成2.5ms就会看到上面的波形,这是什么原因呢?而且那个空隙很有规律会随着PSC的变化而变化,这是什么原因呢?
一周热门 更多>