LPC1114/1343 and servo control


Lately working on a new 4WD “table-top” robotic platform based on LPC1114 and I had to do some research on implementing PWM using timers. Once got it working I though of getting a piece of code to handle pan and tilt servos straight from the tracking module, something like CMUCAM module does.

With this feature, some of the CTS modules will be able to control the pan and tile servos and do tracking or manually control the position of the camera while doing streaming or image capture.

Anyway, roughly the code looks something like:

void pwmInit(void){
    // on 32 bit timer
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);          

    // setup output          
    LPC_IOCON->JTAG_TDO_PIO1_1  &= ~0x07;
    LPC_IOCON->JTAG_TDO_PIO1_1  |= 0x03;        /* Timer1_32 MAT0 */

    LPC_IOCON->JTAG_nTRST_PIO1_2 &= ~0x07;
    LPC_IOCON->JTAG_nTRST_PIO1_2 |= 0x03;       /* Timer1_32 MAT1 */

    // Setup the external match register
    LPC_TMR32B1->EMR = (1<<EMC0) | MATCH0 | (1<

    //Enable the selected PWMs and enable Match3           
    LPC_TMR32B1->PWMC = MATCH3 | MATCH0 | MATCH1;

     // Set prescaler
     LPC_TMR32B1->PR  = ((SystemCoreClock/PWM_FREQUENCY)/1024)-1;

     // Set PWM period on MATCH3
     LPC_TMR32B1->MR3 = 0x2800;
     LPC_TMR32B1->MR0 = 0x00;

     // Set match control register
     LPC_TMR32B1->MCR = 1<<10;            

     // Reset pwm            
     LPC_TMR32B1->TCR = 3<<0;             

     // Enable pwm             
     LPC_TMR32B1->TCR = 1<<0;
}

The rest is  just plain simple.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s