Discussion in "ARM Development" started by    bonois_dailleurs    Sep 5, 2010.
Sun Sep 05 2010, 11:51 AM
#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, 03:19 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.
Tue Sep 07 2010, 11:02 PM
#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, 06:14 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.
Wed Sep 08 2010, 08:29 PM
#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 !!
Wed Sep 08 2010, 08:50 PM
#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.
Wed Sep 08 2010, 10:16 PM
#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 ??

Wed Sep 08 2010, 10:20 PM
#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;
Wed Sep 08 2010, 10:24 PM
#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 !!!
Thu Sep 09 2010, 07:05 PM
#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 Thu Sep 09 2010, 07:05 PM ]
Tags PWM example armarm LPC23xx pwm codeLPC2387 pwm examplepwm sample code lpc23xx lpc2387 lpc2378

Get Social

Information

Powered by e107 Forum System

Conversation

Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051
scena
Tue May 19 2020, 10:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 07:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 01:39 PM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 10:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 12:55 PM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 05:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 04:58 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 78, Members: 0 ...

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

Members: 38215
Newest member: Mirza123