I am running into an issue that when I pass parameters to a function from a task, the variable is not accessible and the data turns out to be zero.
I have tried to make the params pointers to the functions within the task. Make them global and pass them as a pointer to the function from the task. Both of these items failed, and when I try to use the variable under any circumstance the darn thing equates to zero.
I am trying to create a PWM pulse that I can vary with a simple function. However, because this param is not accessible it turns out to be zero so the PWM gets set to zero.
I have tried it without the Mutex and still no change. When I step through the code with the device running, the parameter "nVal" is shown as "not within scope" and so I cannot see the data.
This is driving me nuts...... I have never had this type of problem with C51, so I am really scratching my head over this one.
Anyone see anything obvious that I may be doing wrong?
Here is the function:
void MotorPWMSet (MOTOR Mot, int* nVal) { static unsigned long ulPeriod;
ulPeriod = 0;
// Wait for permission os_mut_wait (g_MotMutex, 0xffff);
if (*nVal > 49) nVal = nVal + 49; else if (*nVal < 1) nVal = 50 + nVal; else nVal = nVal + 50;
g_ulMotPeriod = (g_ulSysMotClkPeriod) * (*nVal / 100); Mot.ulPulseWidth = g_ulMotPeriod; *** I know this does nothing, was just trying to see if the information would get passed and it does not. ***
ulPeriod = g_ulMotPeriod;
// // Lockout updates // tsk_lock (); PWMPulseWidthSet(Mot.REG.PWM_Base, Mot.REG.PWM_Out, g_ulMotPeriod);
// // UnLock updates // tsk_unlock ();
// Allow another task to access os_mut_release (g_MotMutex); }
Calling Code:
__task void tskRun (void) { // unsigned long ulPeriodL, ulPeriodR; // double dblIncL, dblIncR;
// ulPeriodL = ulMotPeriod; // ulPeriodR = ulMotPeriod;
RIT128x96x4Clear();
// dblIncL = 0.99; // ulPeriodL = ulPeriodL * dblIncL; // // dblIncR = 0.25; // ulPeriodR = ulPeriodR * dblIncR;
g_ucPeriodL = 35; g_ucPeriodR = 0;
RIT128x96x4StringDraw("Inside tskRun", 28, 32, 15);
MotorPWMSet (MotorL, &g_ucPeriodL);
while (1) { /* endless loop */
} }
Here are the global vars:
static int g_ucPeriodL, g_ucPeriodR;
Don't sigh. Most people probably did what I did - ignored your post completely because it wasn't fun to try to read the wrecked formatting.
=> when I pass parameters to a function from a task, the variable is not accessible and the data turns out to be zero.
static int g_ucPeriodL, g_ucPeriodR; // Here are the global vars: [...] __task void tskRun (void) // Calling Code: { MotorPWMSet (MotorL, &g_ucPeriodL); [...] void MotorPWMSet (MOTOR Mot, int* nVal) // Here is the function:
Thanks, but unfortunately that is not the fix. :(
I tried that about 3 hours ago.