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

Interrupts, semaphores, priority management and PWM

Posted by ndsmith34 on June 25, 2015

I am a little out of my depth and could use some guidance.

My goal is to drive a stepper motor using a PWM signal. Each motor movement will be a specific number of pulses. I am also implementing an acceleration profile, which means that the period between pulses will change at the beginning and end.

The main players are: MotorStart() – a function that initializes and starts the PWM and sets the initial case for the switch statement inside MotorProfile. MotorProfile – a task that calculates the period for the next PWM pulse. MotorUpdate – a task that updates the PWM parameters at the proper time.

In MotorTask I call MotorStart() which kicks off the PWM. The rest of the program is driven by interrupts.

Each rising edge on the PWM trips an interrupt that in turn calls a notification that gives the MotorProfile_sem semaphore that unblocks MotorProfile. This calculates the period for the next PWM pulse. I do it in this way because I am using TI’s Halcogen code generator and cannot modify the ISR.

Then, an endofperiod interrupt triggers a different notification that gives the MotorUpdate_sem semaphore that unblocks MotorUpdate, which updates the PWM signal.

However, my notification functions are not being called and the PWM is never being updated. I can see that the PWM signal is being output on a scope. Sample snippets of code are below.

vSemaphoreCreateBinary(MotorProfile_sem);
vSemaphoreCreateBinary(MotorUpdate_sem);

xSemaphoreTake(MotorProfile_sem, 10);
xSemaphoreTake(MotorUpdate_sem, 10);

xTaskCreate(MotorTask, (signed char*) "MotorTask", 512, NULL, 1, NULL);	
    xTaskCreate(MotorProfile, (signed char*) "MotorProfile", 512, NULL, 3, NULL);
xTaskCreate(MotorUpdate, (signed char*) "MotorUpdate", 512, NULL, 2, NULL);
    vTaskStartScheduler();

void MotorUpdate (void *p) { while(xSemaphoreTake(MotorUpdatesem, portMAXDELAY) != pdTRUE); pwmSetSignal(hetRAM2, pwm0, motor_drive); } …

void MotorStart (void) // Called to start motor movement { motordrive.duty = 30; motordrive.period = 68374; motorstate = 'a'; pwmSetSignal(hetRAM2, pwm0, motordrive); pwmStart(hetRAM2, pwm0); }

My main questions are: Am I handling the PWM correctly? Are pwmSetSignal and pwmStart redundant? What are my task, semaphore, and interrupt/notification mistakes?


Interrupts, semaphores, priority management and PWM

Posted by ndsmith34 on June 26, 2015

The main issue was that when I transformed my tasks from functions I forgot to make them infinite loops.


[ 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