在线时间2 小时
UID112496
ST金币0
蝴蝶豆0
注册时间2009-2-26
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c

各位高手,最近遇到一个STM8 PWM输出的怪问题, 我在初始化里配置TIM1 为PWM 输出模式, 输出的脉冲是用来供给步进电机细分驱动器的,每次TIM1更新中断时重新对ARR,CCR 赋初值。 但是系统经常是过一段时间,ARR就变成0了,查了好久也不知道是什么原因造成的,请大家帮忙看一下,下面是初始化程序 ,和中断处理程序
void InitTime1(void)
{
/******************************************
***********************************************/
TIM1->CCMR1 |= 0x78; /* Output mode PWM2.TIM_CNT>TIM_CCR时,输出有效电平,使能预装载 */
//TIM1->CCMR1 |= 0x70; /* Output mode PWM2.TIM_CNT>TIM_CCR时,输出有效电平,使能预装载 */
TIM1->CCER1 |= 0x03; /* CC polarity high,enable PWM output */
TIM1->ARRH = 0x07; /* Freq control register: ARR */
TIM1->ARRL = 0xD0; /* Freq control register: ARR */
TIM1->CCR1H = 0x03; /* Dutycycle control register: CCR */
TIM1->CCR1L = 0XE8; /* Dutycycle control register: CCR */
TIM1->BKR |=0X80; //MOE =1;主输出使能
//TIM1->RCR=200;
TIM1->RCR=10;
TIM1-> SCRH = 00;
//TIM1-> SCRL = 0x1F; ///32分频=16M/32=500KHZ
TIM1-> SCRL = 0x07;//8分频=16M/8=2000KHZ
TIM1->CR1 |= 0x81; /* Enable TIM3. TIM3->ARR通 过预装载寄存器缓冲 */
//TIM1->CR1 |= 0x01; /* Enable TIM1. TIM3->ARR立 即写入影子寄存器 */
TIM1->IER |= 0x01; //充许更新中断 UIE
}
#ifdef _COSMIC_
@far @interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
#else /* _RAISONANCE_ */
void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void) interrupt 11
#endif /* _COSMIC_ */
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
//-----共100 cycle 共6.25us
unsigned int waittabletemp;
unsigned int ccrtemp;
//--------------------------------------------------//
//----------------------------------------------//
//-------------------------------------
TIM1->CR1 &= (~0x01); //关闭计数器
#if ACC_CELE_EN==1
if(ArrTemp!=0) //==0时不执行
{
switch(AccCeleState)
{
case 0 :{
TIM1->ARRH = (u8)(ArrTemp>>8);
TIM1->ARRL = (u8)ArrTemp;
ccrtemp=ArrTemp>>1;
TIM1->CCR1H =(u8)(ccrtemp>>8); //Dutycycle control register: CCR
TIM1->CCR1L = (u8)(ccrtemp);
break;
}
case 1 :{ //加速
waittabletemp=WaitTable[ArrLastI+ArrLastI2];
TIM1->ARRH = (u8)(waittabletemp>>8);
TIM1->ARRL = (u8)waittabletemp;
ccrtemp=waittabletemp>>1;
TIM1->CCR1H =(u8)(ccrtemp>>8); //Dutycycle control register: CCR
TIM1->CCR1L = (u8)(ccrtemp);
if((ArrLastI+ArrLastI2++)==ArrI)
{
ArrLastI2=0; //复位
AccCeleState=0; //转为匀速
ArrTempLast=ArrTemp;
}
break;
}
case 2 :{ //减速
waittabletemp=WaitTable[ArrLastI-ArrLastI3];
TIM1->ARRH = (u8)(waittabletemp>>8);
TIM1->ARRL = (u8)waittabletemp;
ccrtemp=waittabletemp>>1;
TIM1->CCR1H =(u8)(ccrtemp>>8); //Dutycycle control register: CCR
TIM1->CCR1L = (u8)(ccrtemp);
if((ArrLastI-ArrLastI3++)==ArrI)
{
ArrLastI3=0; //复位
AccCeleState=0; //转为匀速
ArrTempLast=ArrTemp;
}
break;
}
}
}
#endif
//----------------------------------------------------
TestRcr++;
TIM1->SR1 &= ~0x01;
TIM1->CR1 |= 0x01; //开计数器
}
|
<
|