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

ExperimenterUK
Sun Oct 13 2019, 12:23 AM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 12:18 PM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 09:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 10:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 09:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 06:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 02:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 08:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 09:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 09:44 PM
@praveen123. Can you give a link to the project ?

Downloads

Comments

DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM
ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM

Online

Guests: 40, Members: 0 ...

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

Members: 38102
Newest member: DeepakBGattani
Forum Activity
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...