How is it possible to control a servo motor using a 50Hz PWM. It’s for a LPCXpresso 1343. I’ve managed to port the FreeRTOS to 1343, but I have no idea how to use the timers.
Here is the code for a PWM init that does work without FreeRTOS:
/** Timer 16 / PWM Settings **/
// PWM output: 16bit_timer1
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); // Enable clock to timer 1
LPC_IOCON->PIO1_9 &= ~0x1F; // - remove bits 0,1 & 2 and pull resistors
LPC_IOCON->PIO1_9 |= 0x01; /* Timer1_16 MAT0 */ //- set bit 1
LPC_IOCON->PIO1_10 &= ~0x1F; // - remove bits 0,1 & 2 and pull resistors
LPC_IOCON->PIO1_10 |= 0x02; /* Timer1_16 MAT1 */
LPC_TMR16B1->MCR = 0x0400; /* Reset at MR3*/
LPC_TMR16B1->PR = 50; /* set prescaler 50*28800 = 72MHz */
LPC_TMR16B1->MR0 = 28800-2880; /* Match register 0 - pulse width
LPC_TMR16B1->MR1 = 7000; /* Match register 1 - no PWM - toggle test */
LPC_TMR16B1->MR3 = 28800;//14399; /* Match register 3 - cycle length */
LPC_TMR16B1->EMR = 0xC2; /* External Match register Settings for PWM channel have no effect.*/
LPC_TMR16B1->PWMC = 0x01; /* PWMC register -MAT0 is PWM. */
GPIOSetDir( 1, 9, 0 ); // Set as output
GPIOSetDir( 1, 10, 1 ); // set as output
LPC_TMR16B1->TCR = 1; // Enable timer 1
I want this code to work in FreeRTOS, but I have no idea how.
Can anyone help me ?