void TIM1Init(void)
{
//Set the Prescaler value
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0x03;
TIM1_CR1 &= 0xEF; //UP_CONTER
//Set the Autoreload value
TIM1_ARRH = 0x00;
TIM1_ARRL = 0xC8; //200
TIM1_RCR = 0x00;
TIM1_CCMR3 = 0x60; //PWM MODE 3
TIM1_CCER1 = 0x01; // OPEN OC1
TIM1_CCR3H = 0x00;
TIM1_CCR3L = 0x64; //占空比
TIM1_OISR |= 0x00; /* Idle state set */
TIM1_IER = 0x01; /* Enable TIM1 update interrupt. */
TIM1_CR2 &=~0x01; /* disable Capture/Compare Preloaded Control. */
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM1_BKR |= 0x48;
//TIM1_BKR |= 0x40;
TIM1_DTR = 0x04; /* Dead time (1s/16MHz)*2*4 = 500ns */
TIM1_BKR |= 0x10; /* Break enable */
TIM1_BKR |= 0x20; /* Break polarity High */
TIM1_BKR |= 0x40; /* Automatic output enable */
TIM1_BKR |= 0x01; /* LockLevel_1 */
/* Main Output Enable */
TIM1_BKR |= 0x80; /* Output enable */
TIM1_BKR = 0x80;
TIM1_EGR = 0x01;
TIM1_CR1 = 0x01;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
能提供一个完整的工程吗?
一周热门 更多>