Discussion in "ARM Development" started by    v_victory    Aug 25, 2011.
Thu Aug 25 2011, 04:24 pm
#1
Hi

I am using LPC2388 as target device . I configured Port1.28 as PWM output . below is the sample code , i am not able to see any wave form on oscilloscope.Please guide how to do it.

#include <LPC23xx.H>

static void PWM()
{
PINSEL3 |= 0x20 ;// select the function pwm for P1.18 pin
PWM1TCR = 0x02; /* reset PWM counter */
PWM1MCR = 0x02 ;//reset on match with PWM1MR0
PWM1PCR = 0x200 ; //enable PWM1.1 output and select it's function "single edge"
PWM1MR0 = 100 ;//
PWM1MR1 = 50;
PWM1TCR = 0x09 ;//enable pwm mode and the counter
PWM1LER = 0x03 ;//make match registers values effectif

}

}

int main(){
PWM();
while(1);

}

Thanks in advance
victory
Fri Aug 26 2011, 11:21 pm
#2
I hope you have idea how fast your PWM is gonna work.. try to increase these values a bit.. how much is your PWM clock?
Mon Aug 29 2011, 09:44 am
#3
Hi Ajay

Thanks for the reply , my code is working now (mistake is PWM1LER should be 0x02) .
I have one more doubt i am writing PWM1MR0 =100 , this means what like pulse width is 100usec or 100 pulses. please clarify this.

In my next experiment i my looping back the same signal and want t o measure the pulse width .But i am not able to read the values ,i shorted P1.28 and P3.24 , please guide how to do it.Below is the code

#include <LPC23xx.H>

volatile unsigned int cap_count;
//----------------------------------------------------------------------------------
/* generating PWM */
static void PWMInit(){
PINSEL3 |= 0x20 ;// select the function pwm for P1.18 pin
PWM1TCR = 0x02; /* reset PWM counter */
PWM1MCR = 0x02 ;//reset on match with pWM1MR0
PWM1PCR |= 0x200 ; //enable PWM1.1 output and select it's function "single edge"
PWM1MR0 = 100 ;// pulse width
PWM1MR1 = 50; //duty cycle : 50%
PWM1TCR = 0x09 ;//enable pwm mode and the counter
PWM1LER = 0x02 ;//make match registers values effect
}

//-----------------------------------------------------------------------------------
/* Measuring the Pulse width*/
/* shorting p1.28 and p3.24*/
void Timer1_cap_init(void) {
PINSEL7=0x00020000; /*Capture input on port p3.24 */
T0PR=0x00000018; /* input clock for timer1 :120kHz */
T0TCR=0x02; /* reset the counter*/
T0CCR=0x05; /* count on every rising edge */
T0TCR = 0x01; /*Enable the counter */
}

//------------------------------------------------------------------------------------
int main(){
PWMInit();
Timer1_cap_init();
//cap_count = T0CR0;
while(1){
cap_count = T0CR0; //reading the pulse width.

}

}

//-------------------------------------------------------------------------------------

Thu Sep 01 2011, 02:37 pm
#4
100 means till your TC counts 100. which will be equal to 100 * 1/Tclock in time.

Your pulse is way too small. I am not looking deeply into your code just make sure you start and stop capture triggered by external event.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm