Discussion in "ARM Development" started by    bonois_dailleurs    Sep 5, 2010.
Sun Sep 05 2010, 05:21 pm
#1
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, 08:49 pm
#2
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.
Wed Sep 08 2010, 04:32 am
#3
#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() ;
while(1);
}

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, 11:44 pm
#4
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.
Thu Sep 09 2010, 01:59 am
#5
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 !!
Thu Sep 09 2010, 02:20 am
#6
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.
Thu Sep 09 2010, 03:46 am
#7
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 ??

Thu Sep 09 2010, 03:50 am
#8
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;
Thu Sep 09 2010, 03:54 am
#9
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 !!!
Fri Sep 10 2010, 12:35 am
#10
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(){
    PWMInit();
    while(1);
}


[ Edited Fri Sep 10 2010, 12:35 am ]
Tags PWM example armarm LPC23xx pwm codeLPC2387 pwm examplepwm sample code lpc23xx lpc2387 lpc2378

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am