EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

PWM for the NXP LPC2368

Started by stuper_duck March 19, 2008
I am hoping that someone could help me to understanding how to
generate a PWM Clock ouput.

In short:
I am attempting to generate a 1Mhz output using PWM1_5 of the
LPC2368 and I seem to be having some difficulty in getting the
registers setup correctly.

In more detail:
I am attempting to generate a clock (1Mhz 50% duty cycle) using
PWM1_5 for my output. The input to the 2368 uses 12Mhz xtal.

Any suggestions?

Here's a snippet of those settings:

void InitCPLD_Clk(void)
{
PWM1IR = 0; // Clear all Interrups
PWM1MR0 = 12; // Nearest setting to get 1mhz
PWM1MR5 = 6; // Toggle half way through
PWM1MCR = 0x10002; // Reset MRO and MR5 upon match
//PWM1TCR = 1; // Enable timer
PWM1TCR = 0x8; // Match --> Shadow Register
PWM1CTCR = 0; // Enable timer mode
PWM1PCR |= 1<<13; // Enable PWM5 Ouput
PWM1CCR = 0; // Disable Cap Control Features
}

Thanks in advance!

SD

=======================================================================Groups related to lpc2000
=======================================================================
msp430 (388 common members)
http://groups.yahoo.com/group/msp430?v=1&t=ipt&ch=email&pub=groups&slktr0&sec=recg
Computers & Internet/Hardware: Welcome to the MSP430 User's Group! The purpose of...

AVR-Chat (177 common members)
http://groups.yahoo.com/group/AVR-Chat?v=1&t=ipt&ch=email&pub=groups&slktr1&sec=recg
Microprocessors/Microcontrollers: A place for Atmel AVR Microcontroller users to sha...

LTspice (165 common members)
http://groups.yahoo.com/group/LTspice?v=1&t=ipt&ch=email&pub=groups&slktr2&sec=recg
Engineering/Electrical: Dedicated to the exchange of information about LTs...

Homebrew_PCBs (157 common members)
http://groups.yahoo.com/group/Homebrew_PCBs?v=1&t=ipt&ch=email&pub=groups&slktr3&sec=recg
Engineering/Electrical: Designing, making, etching, soldering, printed cir...

e-embedded (151 common members)
http://groups.yahoo.com/group/e-embedded?v=1&t=ipt&ch=email&pub=groups&slktr4&sec=recg
Internet/Internet Appliances: Open-membership mailing list for embedded system d...

An Engineer's Guide to the LPC2100 Series

I fought with this for a few hours also. I think the problem you have
is that you're resetting MR5 on match. This is from some LPC2148 code
I use to drive a 20Khz charge pump to create a negative bias voltage
for an LCD. If you need to reference the #defines for the various PWM
registers, I've put a copy of the header file I use at
http://jcwren.com/arm/lpc210x.h For a 50% duty cycle, pass in 50.

#define PWM_FREQ 20000 // In Hz
#define CPU_CLOCK_HZ 48000000 // In Jz

void initPWM (int percentage)
{
SCB_PCONP |= SCB_PCONP_PCPWM0;
PCB_PINSEL1 |= PCB_PINSEL1_P021_PWM5;

PWM_TCR = PWM_TCR_CR;
PWM_PR = 0;
PWM_MR0 = (CPU_CLOCK_HZ / PWM_FREQ);
PWM_MCR |= PWM_MCR_MR0R;
PWM_PCR |= PWM_PCR_ENA5;
PWM_TCR = (PWM_TCR_CE | PWM_TCR_PWME);
PWM_MR5 = ((CPU_CLOCK_HZ / PWM_FREQ) * percentage) / 100;
PWM_LER |= PWM_LER_M5L;
}

--jc

--- In l..., "stuper_duck" wrote:
>
> I am hoping that someone could help me to understanding how to
> generate a PWM Clock ouput.
>
> In short:
> I am attempting to generate a 1Mhz output using PWM1_5 of the
> LPC2368 and I seem to be having some difficulty in getting the
> registers setup correctly.
>
> In more detail:
> I am attempting to generate a clock (1Mhz 50% duty cycle) using
> PWM1_5 for my output. The input to the 2368 uses 12Mhz xtal.
>
> Any suggestions?
>
> Here's a snippet of those settings:
>
> void InitCPLD_Clk(void)
> {
> PWM1IR = 0; // Clear all Interrups
> PWM1MR0 = 12; // Nearest setting to get 1mhz
> PWM1MR5 = 6; // Toggle half way through
> PWM1MCR = 0x10002; // Reset MRO and MR5 upon match
> //PWM1TCR = 1; // Enable timer
> PWM1TCR = 0x8; // Match --> Shadow Register
> PWM1CTCR = 0; // Enable timer mode
> PWM1PCR |= 1<<13; // Enable PWM5 Ouput
> PWM1CCR = 0; // Disable Cap Control Features
> }
>
> Thanks in advance!
>
> SD
>


The 2024 Embedded Online Conference