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;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
void TIM1Init(void)
{ TIM1_CR1 = 0x00; //暂时关闭定时器
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0x03; //分频
TIM1_ARRH = 0x00;
TIM1_ARRL = 0xC8; // 重载值
TIM1_RCR = 0x00; // 重复功能
TIM1_CCMR3 = 0x68; //PWM模式
TIM1_CCER2 = 0x10; //使能 通道3
TIM1_CCR3H = 0x00;
TIM1_CCR3L = 0x64; //占空比
TIM1_BKR = 0x80; //松开刹车
TIM1_EGR = 0x01; //更新寄存器
TIM1_CR1 = 0x81; //启动定时器
}
试试这个
谢谢,已经解决.
STM8S比较简单,暂时不考虑用库函数. 问题已经解决,谢谢.
能提供一个完整的工程吗?
一周热门 更多>