Forums

PWM output behaviour

Started by pe1rcl June 14, 2008
Aloha,

I'm pwm oto drive 3 led's (RGB). I'm using PWM1, PWM2 and PWM5 output
of an lpc2148.

The pwm outputs work well, but only if the pwmmr value is not equal
to 0 or to the pwmmr0 register. When these values are selected i have
a 0% or 100% dutycycle, but unpredictable which one. Also the
behaviour this behaviour differs from which output is selected.

Do i something wrong, or is there more known on this behaviour?

Many thanks,
Richard Dols

I use the following code for the pwm outputs
PWMMCR = 0x0000084B; //Reset timer on MR0 match,generate interrupt
PWMPR = 0x00000010; //prescaler value
PWMMR0 = 0x00000100; //30Khz cycle rate (crystal 12Mhz)
PWMPCR |= 0x00002600; //enable pwm
PWMMR1 = green; //value between 1 and 255
PWMMR2 = blue; //value between 1 and 255
PWMMR5 = red; //value between 1 and 255

An Engineer's Guide to the LPC2100 Series

Hi, im also working with lpc2148 and i am also trying to figure out
its PWM so i can dimm the backlight of my lcd.

My pwm implementation is not working and i dont know why yet, but i
can see you missed 2 important things in your code .

1. When you write to the match registers, the value you just wrote
will not be actually correspondent to the value on the PWM output
untill you write certain bits on the PWM latch enable register (
PWMLER ).

2. After you configure everything, you must reset and start counter
via the PWMTCR register.

i got this information reading the LPC214x User Manual that i DLed
from NXP.
Did you get the PWM to work ? mine is still going bad, but i cant find
the problem ...
greetings from Rio de Janeiro,
Lucas

--- In l..., "pe1rcl" wrote:
>
> Aloha,
>
> I'm pwm oto drive 3 led's (RGB). I'm using PWM1, PWM2 and PWM5 output
> of an lpc2148.
>
> The pwm outputs work well, but only if the pwmmr value is not equal
> to 0 or to the pwmmr0 register. When these values are selected i have
> a 0% or 100% dutycycle, but unpredictable which one. Also the
> behaviour this behaviour differs from which output is selected.
>
> Do i something wrong, or is there more known on this behaviour?
>
> Many thanks,
> Richard Dols
>
> I use the following code for the pwm outputs
> PWMMCR = 0x0000084B; //Reset timer on MR0 match,generate interrupt
> PWMPR = 0x00000010; //prescaler value
> PWMMR0 = 0x00000100; //30Khz cycle rate (crystal 12Mhz)
> PWMPCR |= 0x00002600; //enable pwm
> PWMMR1 = green; //value between 1 and 255
> PWMMR2 = blue; //value between 1 and 255
> PWMMR5 = red; //value between 1 and 255
>

There is a working PWM example in the demo code at http://jcwren.com/arm

--jc

On Tue, Sep 23, 2008 at 12:49 PM, senhoruilson wrote:

> Hi, im also working with lpc2148 and i am also trying to figure out
> its PWM so i can dimm the backlight of my lcd.
>
> My pwm implementation is not working and i dont know why yet, but i
> can see you missed 2 important things in your code .
>
> 1. When you write to the match registers, the value you just wrote
> will not be actually correspondent to the value on the PWM output
> untill you write certain bits on the PWM latch enable register (
> PWMLER ).
>
> 2. After you configure everything, you must reset and start counter
> via the PWMTCR register.
>
> i got this information reading the LPC214x User Manual that i DLed
> from NXP.
>
> Did you get the PWM to work ? mine is still going bad, but i cant find
> the problem ...
>
> greetings from Rio de Janeiro,
> Lucas
> --- In l... , "pe1rcl"
> wrote:
> >
> > Aloha,
> >
> > I'm pwm oto drive 3 led's (RGB). I'm using PWM1, PWM2 and PWM5 output
> > of an lpc2148.
> >
> > The pwm outputs work well, but only if the pwmmr value is not equal
> > to 0 or to the pwmmr0 register. When these values are selected i have
> > a 0% or 100% dutycycle, but unpredictable which one. Also the
> > behaviour this behaviour differs from which output is selected.
> >
> > Do i something wrong, or is there more known on this behaviour?
> >
> > Many thanks,
> > Richard Dols
> >
> > I use the following code for the pwm outputs
> > PWMMCR = 0x0000084B; //Reset timer on MR0 match,generate interrupt
> > PWMPR = 0x00000010; //prescaler value
> > PWMMR0 = 0x00000100; //30Khz cycle rate (crystal 12Mhz)
> > PWMPCR |= 0x00002600; //enable pwm
> > PWMMR1 = green; //value between 1 and 255
> > PWMMR2 = blue; //value between 1 and 255
> > PWMMR5 = red; //value between 1 and 255
> >
>

I lied, I used the PWM in a different project.

#define configCPU_CLOCK_HZ ((unsigned int) 48000000)
#define LCD_PWM_FREQ 20000

SCB_PCONP |= SCB_PCONP_PCPWM0;
PCB_PINSEL1 |= PCB_PINSEL1_P021_PWM5;

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

This configures the PWM to set the contrast level.

The code fragment below sets the contrast level as a percentage:

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

lcdContrastPercentage = percentage;

PWM_MR5 = ((configCPU_CLOCK_HZ / LCD_PWM_FREQ) * (percentage / 2)) / 100;
PWM_LER |= PWM_LER_M5L;

return 0;
}

(No doubt Yahoo has graciously stripped useful formatting spaces).

The register definitions do some from the LPC210x.h header file in the
http://jcwren.com/arm demo code.

--jc

On Tue, Sep 23, 2008 at 2:00 PM, J.C. Wren wrote:

> There is a working PWM example in the demo code at http://jcwren.com/arm
>
> --jc
> On Tue, Sep 23, 2008 at 12:49 PM, senhoruilson wrote:
>
>> Hi, im also working with lpc2148 and i am also trying to figure out
>> its PWM so i can dimm the backlight of my lcd.
>>
>> My pwm implementation is not working and i dont know why yet, but i
>> can see you missed 2 important things in your code .
>>
>> 1. When you write to the match registers, the value you just wrote
>> will not be actually correspondent to the value on the PWM output
>> untill you write certain bits on the PWM latch enable register (
>> PWMLER ).
>>
>> 2. After you configure everything, you must reset and start counter
>> via the PWMTCR register.
>>
>> i got this information reading the LPC214x User Manual that i DLed
>> from NXP.
>>
>> Did you get the PWM to work ? mine is still going bad, but i cant find
>> the problem ...
>>
>> greetings from Rio de Janeiro,
>> Lucas
>> --- In l... , "pe1rcl"
>> wrote:
>> >
>> > Aloha,
>> >
>> > I'm pwm oto drive 3 led's (RGB). I'm using PWM1, PWM2 and PWM5 output
>> > of an lpc2148.
>> >
>> > The pwm outputs work well, but only if the pwmmr value is not equal
>> > to 0 or to the pwmmr0 register. When these values are selected i have
>> > a 0% or 100% dutycycle, but unpredictable which one. Also the
>> > behaviour this behaviour differs from which output is selected.
>> >
>> > Do i something wrong, or is there more known on this behaviour?
>> >
>> > Many thanks,
>> > Richard Dols
>> >
>> > I use the following code for the pwm outputs
>> > PWMMCR = 0x0000084B; //Reset timer on MR0 match,generate interrupt
>> > PWMPR = 0x00000010; //prescaler value
>> > PWMMR0 = 0x00000100; //30Khz cycle rate (crystal 12Mhz)
>> > PWMPCR |= 0x00002600; //enable pwm
>> > PWMMR1 = green; //value between 1 and 255
>> > PWMMR2 = blue; //value between 1 and 255
>> > PWMMR5 = red; //value between 1 and 255
>> >
>>
>>
>>

Please select from one of the following:
1) This solved my problem, but I didn't feel a need to indicate such.
2) This was not the answer I was looking for, and I gave up.
3) I lost interest, and the time someone invested in answering my question
was wasted.
4) This was homework, and I didn't want the professor to see I got an answer
I needed.
5) I was hit by a truck, and am now a quadriplegic and cannot type (note
from doctor required).

Answering this simple questionnaire can improve the help providing process
for future questions.

Thank you for your participation.

--- In l..., "J.C. Wren" wrote:
>
> Please select from one of the following:
> 1) This solved my problem, but I didn't feel a need to indicate such.
> 2) This was not the answer I was looking for, and I gave up.
> 3) I lost interest, and the time someone invested in answering my question
> was wasted.
> 4) This was homework, and I didn't want the professor to see I got an answer
> I needed.
> 5) I was hit by a truck, and am now a quadriplegic and cannot type (note
> from doctor required).
>
> Answering this simple questionnaire can improve the help providing process
> for future questions.
>
> Thank you for your participation.
>
>

JC,
I hope you don't get tired of giving a helping hand (for noobs &
hobbyist alike), I'm tinkering with pwm on lpc2138 and I'm having a
hardtime understanding the manual. Thanks to your post (after
countless search) I am closer to getting a grasp of it.

Good deal on the understanding. There is some example code for PWM usage in
the LPC2148 demo code at http://jcwren.com/arm
The 2138 and 2148 PWM function should be identical.

--jc

On Wed, Apr 1, 2009 at 7:53 PM, mhel wrote:

> --- In l... , "J.C. Wren"
> wrote:
> >
> > Please select from one of the following:
> > 1) This solved my problem, but I didn't feel a need to indicate such.
> > 2) This was not the answer I was looking for, and I gave up.
> > 3) I lost interest, and the time someone invested in answering my
> question
> > was wasted.
> > 4) This was homework, and I didn't want the professor to see I got an
> answer
> > I needed.
> > 5) I was hit by a truck, and am now a quadriplegic and cannot type (note
> > from doctor required).
> >
> > Answering this simple questionnaire can improve the help providing
> process
> > for future questions.
> >
> > Thank you for your participation.
> >
> >
> >
> > JC,
> I hope you don't get tired of giving a helping hand (for noobs &
> hobbyist alike), I'm tinkering with pwm on lpc2138 and I'm having a
> hardtime understanding the manual. Thanks to your post (after
> countless search) I am closer to getting a grasp of it.
>
>
>