在 keil uVision for LPC2148 的逻辑分析仪上找不到我的信号

问题描述

我正在尝试在 keil 上为 lpc2148 运行我的 PWM 程序。这具有 10% 的占空比。但是,我可以在 Port0 (P0.21) 上看到信号。 这是我的代码。我非常有信心这是正确的。

#include<lpc214x.h>

int main()

{
PINSEL0=0x00000000; // P0.0 to P0.15 pins of PORT0 as GPIO
PINSEL1=0x00000400; // P0.21 Pin of PORT0 as PWM
PINSEL2=0x00000000; // P1.16 to P1.31 pins of PORT1 as GPIO
/*Configure the PLL block and set the cclK and PCLK at 60 MHz */
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0Feed=0xaa;
PLL0Feed=0x55;
while (!(PLL0STAT & 0x00000400));
PLL0CON=0x03;
PLL0Feed=0xaa;
PLL0Feed=0x55;
VPBDIV=0x01;
/* Setup and initialize the PWM block */
PWMPCR=0x00; // Single Edge PWM Mode
PWMPR=60000-1; // Resolution of PWM is set at 1 mS
PWMMR0=10; // Period of PWM is 10 mS
PWMMR5=1; // pulse width of PWM5 is 1 mS
PWMMCR= (1<<1); // PWMTC is reset on match with PWMMR0
PWMLER= (1<<5)| (1<<0); // Update Match Registers PWMMR0 and PWMMR5
PWMPCR= (1<<13); // Enable PWM5 output
PWMTCR= (1<<1); // Reset PWM TC and PWM PR
PWMTCR= (1<<0)| (1<<3); // Enable PWM Timer Counters and PWM Mode
//PWMMR5 = 1;
//PWMLER = (1<<5); //Update Latch Enable bit for PWMMR5
}

screenshot

请帮忙。

解决方法

Keil 调试器的“逻辑分析器”工具通过 SWO 跟踪监视特定的全局变量。您的代码没有全局变量,并且您没有说明您正在监控的内容。

在真实硬件上可以监控全局变量。外设寄存器和 I/O 引脚只能在模拟中按照 https://www.keil.com/support/man/docs/uv4/uv4_db_dbg_logicanalyzer_restrictions.htm

中的规定进行监控

要获得跟随 PWM 的跟踪,您需要实现一个 PWM 中断处理程序,它将输出引脚的状态复制到全局,或者(更好)读取 PWMIR 寄存器并将其复制到全局变量和/或将全局变量设置为 PWMIR 寄存器推断的状态。然后你直接监控全局变量而不是管脚。

例如:

volatile bool pwmout = 0 ;
volatile bool pwmmatch = 0 ;

__irq void PWM_ISR( void )
{
    pwmmatch = PWMIR  ;

    if( (PWMIR & 0x0001) != 0 )  // MR0 = 1
    {
        pwmout = 1 ;
    }
    else if ( PWMIR & 0x0020 )  // MR5 = 1
    {
        pwmout = 0 ;
    }
    PWMIR = 0 ; // clear interrupt

    VICVectAddr = 0x00000000;
}

然后您可以在逻辑分析器中监控 pwmout 和/或 pwmmatch

我不熟悉您的特定微控制器,因此上述内容可能需要进行一些调整。显然,您还需要启用中断处理程序 - 类似于:

VICVectAddr0 = (unsigned) PWM_ISR; /* PWM ISR Address */
VICVectCntl0 = (0x00000020 | 8); /* Enable PWM IRQ slot */
VICIntEnable = VICIntEnable | 0x00000100; /* Enable PWM interrupt */
VICIntSelect = VICIntSelect | 0x00000000; /* PWM configured as IRQ */

但我只是复制现有示例 - 不能保证。

最后在 main() 的末尾添加一个无限循环,以防止 main() 终止于 who know where:

for(;;)
{
    // do nothing
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...