Discussion in "ARM Development" started by    bonois_dailleurs    Sep 5, 2010.
Sun Sep 05 2010, 11:51 AM
hi everybody ,
i'm working on PHILIPS NXP LPC2378, arm7TDMI and i'm using" keil microvision 4" as an IDE for debugging and simulating my programs

i started working on PWM unit but i couldn't make a general idea about it's role
i will make a summary of what i learn't and if you find something wrong in what i will say please tell me

*)PWM unit has 6 chanals (outputs) and a capture input
*)each channal if working in pwm mode can generate a wave (pulse) in which we can configure dutty cycle (match registers) and it's starting "ending" time (single edge mode or double edge mode)
*)PWM unit can also work as a timer and generate events(interruption) or count cycles

i followed this knowmedges and i wrote a small program just to see the result in real
but when i tried to simulate using the logic analyser i couldn't find what to put to indicate the true chanal

i'll join the program with this thread , take a glance and tell me please what's wrong

Tue Sep 07 2010, 03:19 PM
you have to first configure pin select block for using Port pin as PWM o/p.

you forgot to configure MCR register, configure it to reset on match.
you forgot to enable the counter too, so it wont be able to count and generate PWM for you.

make those changes and try again.
Tue Sep 07 2010, 11:02 PM
#include <LPC23xx.H>

void intrr()
PINSEL2 |= 0x20 ;// select the function pwm for P1.18 pin
FIO1DIR |= 0x4000 ;//configure the direction"output" for P1.18
PWM1PCR |= 0x200 ; //enable PWM1.1 output and select it's function "single edge"
PWM1TCR |= 0x9 ;//enable pwm mode and the counter
PWM1MCR |= 0x10 ;//reset on match with pWM1MR1
PWM1MR0 = 100 ;//
PWM1MR1 = 50 ; // duty time = 50%
PWM1LER = 0x3 ;//make match registers values effectif

void main()
intrr() ;

when debugging the counter is counting without resetting , so do i need to write an isr in which i will reset the counter ???
i'm still confused !!!

thank you for your help
Wed Sep 08 2010, 06:14 PM
when in single edge PWM, timer should be reset at MR0 not MR1.

so MCR should be configured to reset at MR0. make change and try again. and let me know if you start to see o/p on logic analyzer.
Wed Sep 08 2010, 08:29 PM
no , in single edge mode the PWM1.1 is reset by PWMMR1
http://www.keil.com/dd/docs/datashts/philips/lpc23xx_um.pdf (page 565) !!!

but this is not the problem , please follow me the counter starts counting without resetting so i think we should write an interrupt routine which resets the counter

and at the same time , i doubt that this is not the purpose of pwm i mean why using pwm with interrupts ""it"s too complicated "" (i don't know if you understand me )

the idea that i have is the following :
1)single edge : create a wave which begins to the state of 1 and pmw1.x resets it
(x belongs to [1 --> 6])so if we have PWM1MR0 = 100 and PWM1MR1 = 20
we will have a wave in which teh duty cycle equals 20 %
2)double edge mode : we will have a wave but translated from the origin so we'll have to set it to 1 using a value of match and reset it using another value of match

(please correct and add knowledges so that i can make a generam idea this is how i understand

thank you in advance !!
Wed Sep 08 2010, 08:50 PM
I was not talking about PWM output i was talkin about PWM counter.

check PWM1MCR register bit 1: PWMTC will be reset if PWM1MR0 matches it.

reason we want this is.. at starting
your PWM o/p will be High, when PWMTC reaches MR1 it reset the o/p and when PWMTC reaches MR0, it sets the o/p and resets the PWMTC so that counter starts from 0 again.

thats how you will get an uninterrupted PWM signal.
Wed Sep 08 2010, 10:16 PM
PWM1MCR |= 0x3 ?????

i repeat my question , interrupt on match with MR0 means that we have to write an isr which will reset the pwm counter ??

Wed Sep 08 2010, 10:20 PM
NO! interrupt is for those who need it, in your case you just need to reset it thats all.
on every MR0 match reset the counter. thats all you need to do so you will set bit 1 of MCR register.

PWM1MCR |= 0x02;
Wed Sep 08 2010, 10:24 PM
void intrr()
PINSEL2 |= 0x20 ;// select the function pwm for P1.18 pin
FIO1DIR |=(1 << 18) ;//configure the direction"output" for P1.18
PWM1PCR |= 0x200 ; //enable PWM1.1 output and select it's function "single edge"
PWM1TCR |= 0x9 ;//enable pwm mode and the counter
PWM1MCR = 0x02 ;//reset on match with pWM1MR0
PWM1MR0 = 100 ;//
PWM1MR1 = 50;
PWM1LER = 0x3 ;//make match registers values effectif

not working , wave is not generated !!!
Thu Sep 09 2010, 07:05 PM
here is a small sample program i wrote. this is just for reference.

#include <LPC23xx.H>
 /* include for LPC23xx */

static void PWMInit(){
    /* considering LPC2387 */
    /* Select PWM1.2 output on P1.20 */
    PINSEL3 |= (0x2 << 8);

    /* reset PWM counter */
    PWM1TCR = 0x02;

    /* setup match control to reset on MR0 */
    PWM1MCR = 0x02;

    /* select single edge for PWM1.2 and enable PWM1.2 o/p */
    PWM1PCR = 1 << 10;

    /* setup PWM period */
    PWM1MR0 = 100;

    /* setup PWM duty cycle (50%) */
    PWM1MR2 = 50;

    /* start counter and enable PWM */
    PWM1TCR = 0x81;

    /* enable LER */
    PWM1LER = 0x04;

int main(){

[ Edited Thu Sep 09 2010, 07:05 PM ]
Tags PWM example armarm LPC23xx pwm codeLPC2387 pwm examplepwm sample code lpc23xx lpc2387 lpc2378

Get Social


Powered by e107 Forum System


No messages yet.



Thu Jun 25 2020, 03:46 PM
Mon Jun 22 2020, 03:03 PM
Tue Jun 16 2020, 05:10 PM
Sat Jun 13 2020, 09:43 PM
Thu May 21 2020, 12:44 PM
Thu May 21 2020, 01:28 AM
Wed May 20 2020, 07:05 PM
Wed May 20 2020, 11:52 AM


Guests: 75, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123