Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 6 months ago.
pwm,double edge control pwm,interrupt
i tried one program for double edge control of pwm4 pin.....but i m not getting double edge output...its just acting as a single edge control pwm and its falling edge depending only on match register 3(MR3)!!!!!......please help... code is attached.....
2 Answers
11 years, 6 months ago.
thanks Erik.....i modified program and avoided other pwm pins...same problem after modifying!!!...
11 years, 6 months ago.
In you code you write to bit 4 and 5 of the LER register, while you need bit 3 and 4. That should be the issue. As reference, this is what I used to test it, I just connected it to LED4 instead:
#include "mbed.h" void PWMInit(); int main (void) { PWMInit(); while(1) { LPC_PWM1->MR3 = 8000; LPC_PWM1->MR4 = 8100; LPC_PWM1->LER |= (1<<3) | (1<<4) ; } } void PWMInit() { LPC_SC->PCONP |= 1 << 6; // enable power for PWM1 LPC_SC->PCLKSEL0 |= 1 << 12; // PCLK_PWM1 = CCLK LPC_PWM1->MR0 = 16000; // PWM freq = CCLK/16000 LPC_PWM1->MCR |= 1 << 1; // Reset timer on Match0 LPC_PINCON->PINSEL3 |= (2 << 14 ); // P2.4 works as PWM1 output LPC_PINCON->PINMODE3 |= 2 << 14; // enable neither pull up nor pull down LPC_PWM1->PCR |= 1 << 4; // Configure channel 4 as double edge controlled PWM LPC_PWM1->PCR |= 1 << 12; // Enable PWM channel 4 output LPC_PWM1->MR0 = 16000; // PWM freq = CCLK/16000 LPC_PWM1->TCR = (1 << 0) | (1 << 3); // enable timer counter and PWM }
(Really for such stuff the code tags are easiest, just don't forget to put them on a seperate line).
thanks erik.....i am using lpc 1768....still now i am getting 50% duty cycle pwm at pwm4 (24thpin)!!!...depending only on MR3 value
posted by 09 Jun 2013pin 24 is pwm3, not pwm4. It shouldn't be doing anything at all since PWM channel 3 shouldn't be activated, but pin23 is pwm4. See: http://mbed.org/users/synvox/notebook/lpc1768-pinout-with-labelled-mbed-pins/
posted by 09 Jun 2013thank you very much Erik.. I activated PWM pin...its working....:)...but how can I activate motor control PWM pin in lpc1768???
posted by 09 Jun 2013The motor control PWM is a seperate block from the normal PWM. I have no experience with it myself, but one major issue is that you cannot use the mbed board for it: it also has seperate pins, and most of them won't be available (connected internally for other usages, or simply not connected to any output pin). So unless you have another LPC1768 board you cannot use it.
This probably is a useful place also to start: http://mbed.org/forum/mbed/topic/685/
posted by 09 Jun 2013
Please put
posted by Erik - 09 Jun 2013<<code>> and <</code>>
around your code. Also it is best to keep it is asimple as possible, and right now your PWM IRQ has no function, so it is better to leave it out.