Quality RTOS & Embedded Software

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




Loading

How to PWM(50Hz) using FreeRTOS

Posted by SnEAky on March 18, 2010
Hello,

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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists