![]() |
Weird Disappearing Commands
That's the best description I could think of to describe this problem. I have the following code:
Code:
void Elbow_Targetize_PID(void) {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? |
Re: Weird Disappearing Commands
Quote:
I can spot several chances for errors in this code. First: >>3 works great for positive numbers, but will only give you headaches if the number you're shifting is negative. (I'm almost positive. ;) I'll leave it as an exercise for the student to demonstrate yea or nay.) Second, if you're expecting the lines in questions to only do something when output is between -6 and +6 (as your comment seems to indicate that you might), you're wrong! Third, if output starts out between -6 and -1, it will first have 7 subtracted from it, and then immediately have 7 added back in! Do any of those sound like it might explain the behavior/symptom you're seeing? |
Re: Weird Disappearing Commands
Quote:
Quote:
Quote:
Quote:
I'm sure I missed something, though. When I posted this, I had momentarily forgotten my motto, "No matter how irrational the problem seems, it's always your own dumb fault." Thanks for the help. Feel free argue with and make fun of me if my logic is fatally flawed. |
Re: Weird Disappearing Commands
Quote:
|
Re: Weird Disappearing Commands
Just for giggles, why not try changing the divided by 8 and multiply by 2 into a divide by four? It will probably be about the same, and even if it's not I don't think the nanoseconds will be noticable. ;)
P.S. Casts are good. I had at least 3 times where I'd test something for literal hours, only to find that my original code was fine. All I had to do was add casts for things which the compiler should have been able to easily handle on its own... :rolleyes: |
Re: Weird Disappearing Commands
Quote:
What I am getting at is that the speed controllers have a built in deadband of +/- 10, not 7, centered on 127. In other words, 7 doesn't quite kick you out of the deadband region. But expanding your numbers too far could lead to an unsafe/uncontrollable situation where it will never find a stationary position. :ahh: Try increasing the value +/- 1 at a time. :D And, by the way, let us know how it turns out!!! |
| All times are GMT -5. The time now is 04:41. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi