This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help with PWM in LPC2148 to drive dc motor

#include <LPC21xx.h>

void Speed11(void);

unsigned int i;
unsigned char flag=0,flag1;

void PWM_Init(void)
{ PWMPR = 0x00000000; //PRESCALER

PWMPCR = 0x00002000; //select PWM5 single edge and PWM2 enabled PWMMCR = 0x00000003; //PWM'S are free running, no interrupts PWMMR0 = 30000; //setup match register 0 count

PWMMR5 = 0x00000100; //setup match register 5 count for PWM channel 1 PWMLER = 0x000000FF; //enable shadow copy register PWMTCR = 0x00000002; //RESET COUNTER AND PRESCALER PWMTCR = 0x00000009; //enable PWM and counter
}

int main(void)
{

PINSEL1 =0x00000400; //PWM channel 5 is selected

PWM_Init();

while(1) { Speed11(); }
} void Speed11(void)
{ while(1) {

for(i=0;i<=3000;i++); // delay if(flag == 0x00) { PWMMR5 = PWMMR5+200; PWMLER = 0x000000FF;

if(PWMMR5 >= 37000) { flag1 = 0xff; flag = 0xff;

} }

else if(flag1 == 0xff) {

PWMMR5 = PWMMR5-100; PWMLER = 0x000000FF;

if(PWMMR5 <= 1280) { flag = 0x00; flag1 = 0x00;

} }
} }

This is the code that was given to me which helps in driving a dc motor using lpc2148. I understood most part of the code. However I am having trouble in analyzing the function Speed11(); .

I know that it turns the motor on & off. The if part switches the motor off and else if part switches the motor on. But I have trouble understanding what factors are making the motor on & off. Please help me!!!!

0