Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with generating PWM pulses on LPC2148 microprocessors

Status
Not open for further replies.

jeevanmgp

Newbie level 2
Joined
Jan 15, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,309
Hi, I am having some trouble with PWM on LPC2148 microprocessors. Pulses are not generated. It is a complete high signal. Here is the code I am using.
/* Oscillator frequency 12.000 Mhz */
/* Target board Keil MCB2100 */
/************************************************************/

#include "LPC214X.H"
#include "FreeRTOSConfig.h"


static int pwmPulseWidth = 2000;
static int pwmPercentage = 50;

int pwmDutyCycle (int percentage);
int pwmPulseWidthInMicroseconds (int us);
int pwmFrequency (int frequency);
void pwmInit (void);

//
//
//
int pwmDutyCycle (int percentage)
{
if ((percentage < 0) || (percentage > 100))
return -1;

PWM_MR5 = ((configCPU_CLOCK_HZ / pwmPulseWidth) * (pwmPercentage = percentage)) / 100;
PWM_LER = PWM_LER_M5L;

return 0;
}

//
//
//
int pwmPulseWidthInMicroseconds (int us)
{
unsigned int count = (configCPU_CLOCK_HZ / 1000000) * us;

if (count > PWM_MR0)
return -1;

PWM_MR5 = count;
PWM_LER = PWM_LER_M5L;

return 0;
}

//
//
//
int pwmFrequency (int frequency)
{
if ((frequency < 1) || (frequency >= (int) configCPU_CLOCK_HZ))
return -1;

PWM_MR0 = (configCPU_CLOCK_HZ / (pwmPulseWidth = frequency));
PWM_MR5 = ((configCPU_CLOCK_HZ / pwmPulseWidth) * pwmPercentage) / 100;
PWM_LER = PWM_LER_M5L | PWM_LER_M0L;

return 0;
}



void pwmInit (void)
{
SCB_PCONP |= SCB_PCONP_PCPWM0;
PCB_PINSEL1 = (PCB_PINSEL1 & ~PCB_PINSEL1_P021_MASK) | PCB_PINSEL1_P021_PWM5;

PWM_TCR = PWM_TCR_CR;
PWM_PR = 0;
PWM_MR0 = (configCPU_CLOCK_HZ / pwmPulseWidth);
PWM_MCR |= PWM_MCR_MR0R;
PWM_PCR |= PWM_PCR_ENA5;
PWM_TCR = (PWM_TCR_CE | PWM_TCR_PWME);

pwmDutyCycle (50);
}

void init_pll()
{
PLL0CFG = 0x00000025;
PLL0CON = 0x00000001;
PLL0FEED = 0x0000000AA;
PLL0FEED = 0x000000055;
while (!(PLL0STAT & 0x00000400));
PLL0CON = 0x00000003;
PLL0FEED = 0x0000000AA;
PLL0FEED = 0x000000055;
VPBDIV = 0x00000001;
}


void main()
{
init_pll();
pwmInit();
pwmFrequency (50);
pwmPulseWidthInMicroseconds(2000);
pwmDutyCycle(50);
while(1)
{


}

}
 

Re: PWM in LPC2148

HI

You need to setup the I/O pin as peripheral to see PWM out put
Also add some notes to your code it will be easy to understand

All the best

Bobi
 

Re: PWM in LPC2148

Configure ur PINSEL register for PWM output..
By default those bits configured for GPIOs.
 

Re: PWM in LPC2148

Configure ur PINSEL register for PWM output..
By default those bits configured for GPIOs.

Even i am having the same problem. I even set PINSEL1 to take pin p0.21 as PWM5.

When i simulate it inside keil i see that the PWM is working. When i check it inside the peripheral for PWM i see the PWM5 going on and off. But there is no signal in the real hardware.

I am been stuck for a while on this. Could somebody please help me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top