ADI 技术
直播中

刘平

7年用户 240经验值
私信 关注
[问答]

我的ADuC7060的输出PWM脉冲输出异常,请问解决办法是什么,以下附上我的PWM测试程序

我打算使用ADuC7060的PWM1端口输出PWM脉冲,单端输出,占空比是50%,周期是100μS,在用Keil调试时能正常输出我所需要的PWM脉冲,后来断电后再上电却发现PWM输出异常,主要是占空比异常,周期还是正常的。后来我将官方的PWM程序烧写进去后再将我的PWM测试程序烧写到芯片中后又正常了,但是一断电再上电就出现异常了。
请问大虾这是什么造成的。解决方式是什么?

下面附上我的PWM测试程序:
int main(void)
{
     POWKEY1 = 0x1;
     POWCON0 = 0x78;     // Set core to max CPU speed of 10.24Mhz
     POWKEY2 = 0xF4;

// Initialize the GPIO pins for PWM mode
     GP0CON0 = BIT16;    // Select PWM1 output
     PWMCON = BIT0;  // PWM Standard mode, UCLK/2
     PWM0COM2 = 0x80;  // Configure PWM1 output low trigger time
     PWM0LEN = 0xFF;  // Configure PWM1 output high trigger time

while (1)
{
}
}

官方的PWM程序:
unsigned char bTripDetected = 0;
int main(void)
{
POWKEY1 = 0x1;
POWCON0 = 0x78;     // Set core to max CPU speed of 10.24Mhz
POWKEY2 = 0xF4;

// Initialize the GPIO pins for PWM mode
GP0CON0 = BIT16;    // Select PWM1 output
// GP1CON  = BIT8 + BIT12  // Select PWMSYNC and PWMTRIP functions
//   + BIT16 + BIT20  // Select PWM2, PWM3 output
//   + BIT24;   // Select PWM4 output
// GP2CON  = BIT0 + BIT4;  // Select PWM0 and PWM5 output

PWMCON = BIT0 + BIT10;  // PWM Standard mode, UCLK/2, PWM Trip interrupt enabled

ConfigurePWM();   // Call function to configure PWM
bTripDetected = 0;
IRQEN = BIT17;   // Enable PWM Trip interrupt source
while (1)
{
    if (bTripDetected == 1)
     {
      bTripDetected = 0;
      ConfigurePWM();
  }
}
}
void IRQ_Handler(void) __irq  // Unused in this application
{
   unsigned long IRQSTATUS = 0;
IRQSTATUS = IRQSTA;    // Read off IRQSTA register
if ((IRQSTATUS & BIT17) == BIT17) //If PWM trip interrupt source
{
   bTripDetected = 1;  // Set flag to re configure the PWM block
   PWMCLRI = 0xFF;  // Clear the PWM trip interrupt source
}
}
void ConfigurePWM(void)
{
   //Configure PWM0 for 20khz duty cycle
   // P0.4
PWM0COM0 = 0x80;  // Configure PWM0 output high trigger time
PWM0COM1 = 0xFF;  // Configure PWM0 output Low trigger time
// PWM0COM2 = 0x80;  // Configure PWM1 output low trigger time
PWM0LEN = 0xFF;  // Configure PWM1 output high trigger time
/* //Configure PWM2 for 10khz duty cycle
// P1.5
PWM1COM0 = 0xFF;  // Configure PWM2 output high trigger time
PWM1COM1 = 0x1FF;  // Configure PWM2 output Low trigger time
PWM1COM2 = 0xFF;  // Configure PWM3 output low trigger time
PWM1LEN = 0x1FF;  // Configure PWM3 output high trigger time
//Configure PWM4 for 40khz duty cycle
// P2.1
PWM2COM0 = 0x40;  // Configure PWM4 output high trigger time
PWM2COM1 = 0x80;  // Configure PWM4 output Low trigger time
PWM2COM2 = 0x40;  // Configure PWM5 output low trigger time
PWM2LEN = 0x80;  // Configure PWM6 output high trigger time
*/
}

回帖(2)

张虎豹

2018-10-31 16:23:27
您好,您的问题已经提交给ADI相关专家,将邀请专家尽快回答您的问题。谢谢!
举报

刘思思

2018-10-31 16:38:16
看了您的程序,没有什么问题,怀疑是您硬件的问题,您能将您的电路图贴出来看一下吗
举报

更多回帖

发帖
×
20
完善资料,
赚取积分