OK, I am no programming Guru, so I am asking for help.
I am coding a simple torque limiting function. I have very carefully checked my work, yet when I “Build All”, MPLAB says I made a Syntax error. When I comment out the entire function, the error goes away. Please take a look at it and comment to your hearts content. The error is on line 111, which is where my first “if” takes place.
/******************************************************** ****************************
* Function name: Torque_Limit
*
* Purpose: Reduce max torque to allow smoother driving transitions
*
* Called from: autonomous./Autonomous(), and teleop.c/Teleop()
*
* Arguments: Target value from code or joystick, Previous value of pwm,
* Max change (MAXTORQUE). DO NOT FORGET TO STORE FINAL PWM VALUE TO CORRECT
* VARIABLE (lastpwmXX) WHEN RETURNED!!!
*
* Returns: (int) pwm value
*
*
**************************************************************************************/
int Torque_Limit (int target, int previous)
{
int setpmw;
if((target - previous) > MAXTORQUE)
{
setpwm = (previous + MAXTORQUE);
}
else if((previous - target) > MAXTORQUE)
{
setpwm = (previous - MAXTORQUE);
}
else
{
setpwm = target;
}
return setpwm;
}
I tried the comment out … The error moves to the new “if” statement.
That shows that both those if statements have the same error. Probably not an imbalanced { } from above. (You can remove the /* comment */). I’m still thinking the #define MAXTORQUE isn’t being seen by this file.
If you change MAXTORQUE to 100 does the error go away?
(I’m also imagining poor billbo911 running from the computer with mplab all the way across the room to the computer with internet access.)
Yes, bob.h included.
No, it doesn’t go away when defined locally.
Yes, bob.h is included.
No semi-colon on definition. BUT!!! We have a winner!!! The line looked like this “#define MAXTORQUE = 100” The equal sign killed it.
Not the problem. Tried both ways. Problem solved above!
THANK YOU EVERYONE for helping me find this problem.!!
Note to self: “=” good in variable declaration, bad in definition.