Hi,
That's not all the code, is it? I don't see any values being assigned to TotalRate and/or TotalTime1 etc anywhere, or am I missing it?
You have TotalRate and TotalTime1(etc) declared as LONGS, while pid_Error is a WORD. I'm not 100% sure but I think that might be part of the problem because when subtracting two longs you end up with a LONG but pid_Error will only "get" the lower 16bits of that result which makes it go all wrong (I think). Try changing TotalRate and TotalTime to WORD size variables and see what happends.
Next thing, you have
Code:
pid_Out = ABS pid_Out
Duty1 = pid_Out
If your drive system is one quadrant, ie you can supply power in one direction only (which is true if you have for example a single low side MOSFET switching the motor) then this won't work very well because when pid_Out becomes negative, ie the regulator loop wants to reverse/break the motor the ABS will make it positive and instead apply power to the motor - not good.
What you need to do, if you have a single quadrant system, is to not allow the output to swing negative. Something like:
Code:
If pid_Out.15 Then pid_Out = 0
That should make pid_Out go more or less positive but never negative.
/Henrik.
Bookmarks