本帖最后由 crazybee 于 2016-2-29 21:52 编辑
RCC_APB1ENR_bit.TIM3EN = 1;
TIM3_SMCR_bit.SMS = 0; //SLAVE MODE DISABLE
TIM3_PSC = 1; //48MHZ/2 = 24MHZ CK_CNT
TIM3_CR1_bit.DIR = 0; //Counter used as upcounter
TIM3_ARR = 255; //93.7KHZ 8bits
TIM3_CR1_bit.ARPE = 0; //no buffer
TIM3_CR1_bit.CMS = 0; //edge aligned mode pwm
TIM3_CCMR1_bit.OC1M = 6; //PWM MODE1
TIM3_CCMR1_bit.OC1PE = 1; //preload enable,will be active at update event.
TIM3_CCER_bit.CC1P = 0; //active high
TIM3_CCER_bit.CC1E = 1;
TIM3_CCR1 = 0;
TIM3_CCMR1_bit.OC2M = 6; //PWM MODE1
TIM3_CCMR1_bit.OC2PE = 1; //preload enable,will be active at update event.
TIM3_CCER_bit.CC2P = 0; //active high
TIM3_CCER_bit.CC2E = 1;
TIM3_CCR2 = 0;
TIM3_CR1_bit.CEN = 1;
TIM3_EGR_bit.UG = 1;
TIM3_CCR1 = 200;
TIM3_CCR2 = 200;
while(1);
用示波器测PB4,PB5 输出波形,会间隔大60ms 停止 20ms左右,又恢复正常,,,,,, 当上面的CCR 值 为100时,却正常了,这是什么原因,查ERRATA没说明,不会是IC BUG吧???、、
手册里的示例是:
/* (1) Set prescaler to 47, so APBCLK/48 i.e 1MHz */
/* (2) Set ARR = 8, as timer clock is 1MHz the period is 9 us */
/* (3) Set CCRx = 4, , the signal will be high during 4 us */
/* (4) Select PWM mode 1 on OC1 (OC1M = 110),
enable preload register on OC1 (OC1PE = 1) */
/* (5) Select active high polarity on OC1 (CC1P = 0, reset value),
enable the output on OC1 (CC1E = 1)*/
/* (6) Enable output (MOE = 1)*/
/* (7) Enable counter (CEN = 1)
select edge aligned mode (CMS = 00, reset value)
select direction as upcounter (DIR = 0, reset value) */
/* (8) Force update generation (UG = 1) */
TIMx->PSC = 47; /* (1) */
TIMx->ARR = 8; /* (2) */
TIMx->CCR1 = 4; /* (3) */
TIMx->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1
| TIM_CCMR1_OC1PE; /* (4) */
TIMx->CCER |= TIM_CCER_CC1E; /* (5) */
TIMx->BDTR |= TIM_BDTR_MOE; /* (6) */
TIMx->CR1 |= TIM_CR1_CEN; /* (7) */
TIMx->EGR |= TIM_EGR_UG; /* (8) */
|