Orborde
18-04-2005, 17:52
That's the best description I could think of to describe this problem. I have the following code:
void Elbow_Targetize_PID(void) {
unsigned int current;
signed int error, output;
current = Get_Analog_Value(elbow_pot); // measure the elbow potentiometer
elbow_motor = 127; // just to be safe
// (elbow_target_abs is a global variable describing the goal state of the
// potentiometer. It is set up this way to make the elbow's usage roughly
// in line with that of the PWMs and such
error = ((signed int) elbow_target_abs) - ((signed int) current);
//yes, I know I'm cast-crazy...
output = (error >> 3); // quickly divide by 8
output = output * 2; // and multiply by two (I have no idea why I did this)
// kick the output out of the deadband
if (output < 0) output -= 7;
if (output > 0) output += 7;
// finally, assign the end result to the motor (it's backwards)
elbow_motor = (unsigned char) (127 - output);
// the output gets limited later by a safety function, though it occurs
// to me that I should do it in here to avoid problems
}First, yes, I know it's just a P, not a PID, controller. Sue me.
At any rate, the problem is in the bolded lines. They don't seem to be getting executed at all. I've checked it several times and it still doesn't seem to do it. Now, the elbow control works fine despite this, but it still worries me. I can only guess that those few lines are being "optimized" away for some reason by mcc18. I even put the same function into another development environment and tested it, and it worked as expected. What gives?
I'm using Master Software 10 and mcc18 2.40 with MPLAB 7.00.
Maybe I'm crazy. Could someone else try this function to see if the problem shows its hairy face?
void Elbow_Targetize_PID(void) {
unsigned int current;
signed int error, output;
current = Get_Analog_Value(elbow_pot); // measure the elbow potentiometer
elbow_motor = 127; // just to be safe
// (elbow_target_abs is a global variable describing the goal state of the
// potentiometer. It is set up this way to make the elbow's usage roughly
// in line with that of the PWMs and such
error = ((signed int) elbow_target_abs) - ((signed int) current);
//yes, I know I'm cast-crazy...
output = (error >> 3); // quickly divide by 8
output = output * 2; // and multiply by two (I have no idea why I did this)
// kick the output out of the deadband
if (output < 0) output -= 7;
if (output > 0) output += 7;
// finally, assign the end result to the motor (it's backwards)
elbow_motor = (unsigned char) (127 - output);
// the output gets limited later by a safety function, though it occurs
// to me that I should do it in here to avoid problems
}First, yes, I know it's just a P, not a PID, controller. Sue me.
At any rate, the problem is in the bolded lines. They don't seem to be getting executed at all. I've checked it several times and it still doesn't seem to do it. Now, the elbow control works fine despite this, but it still worries me. I can only guess that those few lines are being "optimized" away for some reason by mcc18. I even put the same function into another development environment and tested it, and it worked as expected. What gives?
I'm using Master Software 10 and mcc18 2.40 with MPLAB 7.00.
Maybe I'm crazy. Could someone else try this function to see if the problem shows its hairy face?