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.
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(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);
My main questions are:
Am I handling the PWM correctly? Are pwmSetSignal and pwmStart redundant?
What are my task, semaphore, and interrupt/notification mistakes?
The main issue was that when I transformed my tasks from functions I forgot to make them infinite loops.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.