Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT


How to PWM(50Hz) using FreeRTOS

Posted by SnEAky on March 18, 2010

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:

void PWM_init(void){
/** 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 ?

- SnEAky

RE: How to PWM(50Hz) using FreeRTOS

Posted by Dave on March 18, 2010
First get it working without FreeRTOS, then build up the application around it.

RE: How to PWM(50Hz) using FreeRTOS

Posted by SnEAky on March 18, 2010
It is already working without FreeRTOS like i said in my first post. I just have no idea how to make this work in FreeRTOS. I've put the init in setuphardware(); and i call that function in the main.
Next I start a task that will set the pulse width, but for some reason nothing happens, the output is just a logical '1' and nothing happens.

Any idea?

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS