Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   MPLAB syntax error?? No Way!! (http://www.chiefdelphi.com/forums/showthread.php?t=62480)

billbo911 25-01-2008 14:16

MPLAB syntax error?? No Way!!
 
1 Attachment(s)
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.

Code:

/******************************************************** ****************************
*        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;
}

See the screen shot for the error.

Joe Ross 25-01-2008 14:23

Re: MPLAB syntax error?? No Way!!
 
what is MAXTORQUE defined to?

mgurgol 25-01-2008 14:24

Re: MPLAB syntax error?? No Way!!
 
you are defining setpmw, but using setpwm after the if statements

Tom Line 25-01-2008 14:26

Re: MPLAB syntax error?? No Way!!
 
Yep.

Is that a valid return statement? I thought it should be return(variable);

Roger 25-01-2008 14:27

Re: MPLAB syntax error?? No Way!!
 
Silly question, but MAXTORQUE is defined globally somewhere? Hmm... is that a syntax error or something else?

If you comment out the first if thru to the else /*if .... else*/ so the else if is now an if, does the error drop down to that if or does it go away?

Roger 25-01-2008 14:33

Re: MPLAB syntax error?? No Way!!
 
The setpwm / setpmw error will crop up after this error is fixed.

Heh. I feel like I'm on a game show, with all these answers coming back.

billbo911 25-01-2008 14:33

Re: MPLAB syntax error?? No Way!!
 
Quote:

Originally Posted by Joe Ross (Post 685711)
what is MAXTORQUE defined to?

Currently MAXTORQUE is defined to a value of 100 in the bob.h file. It will be modified once we experiment a little.

Quote:

Originally Posted by mgurgol (Post 685712)
you are defining setpmw, but using septum after the if statements

OK, I corrected my spelling error (thank you), but am still getting the same error for the same line of code.

Joe Ross 25-01-2008 14:37

Re: MPLAB syntax error?? No Way!!
 
Quote:

Originally Posted by billbo911 (Post 685726)
Currently MAXTORQUE is defined to a value of 100 in the bob.h file. It will be modified once we experiment a little.

OK, I corrected my spelling error (thank you), but am still getting the same error for the same line of code.

Is there an include statement for bob.h in this file?

Did you put a semicolon or anything after #define MAXTORQUE 100

Roger 25-01-2008 14:38

Re: MPLAB syntax error?? No Way!!
 
Does this c file #include the bob.h file? Or is this file bob.c? If you (temporarily) define MAXTORQUE in this file does the error go away?

billbo911 25-01-2008 14:39

Re: MPLAB syntax error?? No Way!!
 
Quote:

Originally Posted by Roger (Post 685721)
Silly question, but MAXTORQUE is defined globally somewhere? Hmm... is that a syntax error or something else?

If you comment out the first if thru to the else /*if .... else*/ so the else if is now an if, does the error drop down to that if or does it go away?

Yep, MAXTORQUE is defined in bob.h.

I tried the comment out as you suggested before posting the question. The error moves to the new "if" statement.

Roger 25-01-2008 14:48

Re: MPLAB syntax error?? No Way!!
 
Quote:

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

billbo911 25-01-2008 14:49

Re: MPLAB syntax error?? No Way!!
 
Quote:

Originally Posted by Roger (Post 685732)
Does this c file #include the bob.h file? Or is this file bob.c? If you (temporarily) define MAXTORQUE in this file does the error go away?

Yes, bob.h included.
No, it doesn't go away when defined locally.


Quote:

Originally Posted by Joe Ross (Post 685730)
Is there an include statement for bob.h in this file?

Did you put a semicolon or anything after #define MAXTORQUE 100

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.

Quote:

Originally Posted by Tom Line (Post 685720)
Yep.

Is that a valid return statement? I thought it should be return(variable);

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.

billbo911 25-01-2008 14:51

Re: MPLAB syntax error?? No Way!!
 
Quote:

Originally Posted by Roger (Post 685743)

(I'm also imagining poor billbo911 running from the computer with mplab all the way across the room to the computer with internet access.)

Luckily, I have access on 2 side by side computers. It makes this much easier!:)


All times are GMT -5. The time now is 23:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi