Interrupts, semaphores, priority management and PWM

ndsmith34 wrote on Thursday, 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 end_of_period 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.


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);

void MotorUpdate (void *p)
while(xSemaphoreTake(MotorUpdate_sem, portMAX_DELAY) != pdTRUE);
pwmSetSignal(hetRAM2, pwm0, motor_drive);

void MotorStart (void) // Called to start motor movement
motor_drive.duty = 30;
motor_drive.period = 68374;
motor_state = ‘a’;
pwmSetSignal(hetRAM2, pwm0, motor_drive);
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?

ndsmith34 wrote on Friday, June 26, 2015:

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