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
}