Cannot find my signal on logic analyzer of keil uVision for LPC2148

1.2k Views Asked by At

I am trying to run my PWM program on keil for lpc2148. This has 10% duty cycle. However, I can see the signal on Port0 (P0.21). Here is my code. I am quite confident it is right.

#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 Please help.

2

There are 2 best solutions below

2
Clifford On

The Keil debugger's "logic analyser" tool watches specific global variables via SWO trace. Your code has no global variables and you have not stated what you are monitoring.

On real hardware only global variables can be monitored. Peripheral registers and I/O pins can only be monitored in simulation as specified at https://www.keil.com/support/man/docs/uv4/uv4_db_dbg_logicanalyzer_restrictions.htm

To get a trace that follows your PWM, you will need to implement a PWM interrupt handler that either copies the state of the output pin to a global, or (better) reads the PWMIR register and copies that to a global variable and/or sets the global to the state inferred by the PWMIR register. Then you monitor the global variable rather than the pin directly.

For example:

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;
}

And you can then monitor pwmout and/or pwmmatch in the logic analyser.

I am not familiar with your specific microcontroller so the above may need some tweaking. Obviously you will also need to enable the interrupt handler - something like:

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 */

but I am just copying existing examples - no guarantees.

Finally at the end of your main() add an infinite loop to prevent main() from terminating into who knows where:

for(;;)
{
    // do nothing
}
0
Sanchit On

Yes, the code is right, but to observe the waveform using the Keil logic analyzer, you need to specify the correct port pin notation. Instead of using "P0.21" you should use "PORT0.21".

I have attached the Screenshot

Then press enter and see the results.

Here is the result