servo motor

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

servo motor

588 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CortexM3 on Fri Jun 14 09:23:26 MST 2013
i am trying to get a servo motor to work with p2.1. can any1 help with check where the problem lies in the code? thank you

void init_servo()
{
    LPC_SC -> PCONP|=1<<6;
    LPC_PWM1 -> TCR=2; //reset pwm
    LPC_PWM1 -> IR= 0xff; //clear any pending int
    LPC_PINCON -> PINSEL4 = 0x4;//config P2.1 as pwm1.2
    LPC_PINCON -> PINMODE4 =0xA; //disable pullups for p2.1
}

void move_servo(int pulsewidth)
{
    LPC_PWM1 ->PR=SystemCoreClock/(4*1000000)-1; //50hz rate
    LPC_PWM1 ->MR0=20000; //20ms period
    LPC_PWM1 ->MR1=pulsewidth; //pulse width 600/1500/2400
    LPC_PWM1 ->MR2=19000; //for interrupt
    LPC_PWM1 ->LER=0x7;
    LPC_PWM1 ->MCR=0x2|(1<<6);
    LPC_PWM1 ->PCR=1<<9; //enable pwm1
    LPC_PWM1 ->TCR= (1<<3)|1; //pwm enabled
}
0 Kudos
Reply
1 Reply

533 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Jun 14 10:25:12 MST 2013

Quote: CortexM3
i am trying to get a servo motor to work with p2.1. can any1 help with check where the problem lies in the code?



If you are trying to run PWM2 (= P2.1) it's a good idea to enable PWM2 and use MR2
LPC_PWM1 ->[COLOR=Red]MR2=pulsewidth[/COLOR]; //pulse width 600/1500/2400

LPC_PWM1 ->PCR=1<<[COLOR=Red]10[/COLOR]; //enable [COLOR=Red]pwm2[/COLOR]
0 Kudos
Reply