Hi Mike,
There should be no need to edit the include file for this, I don't think.
All you need to do is calculate the error and send it to the PID-filter, it determines if the error is positive or negative, calculates the "drive" and returns it in the variable PID_Out. You never need to pass any "direction-bit" TO the PID-routine.
Now, if you're driving something like a heater where you can only deliver power in "one direction" (you can just add more or less heat, you can't remove it) then you simply look at the sign-bit of the PID_Out variable (PID_Out.15) and if it's set (meaning negative "drive" becuse the temperature is too high) you simply set the output to 0.
OR (and this is probably a better aproach)
Let's say you know that under normal conditions you need a duty cycle of ~30% to keep the temperature fairly constant. Now you look at the sign of the value in the PID_Out variable and depending on its state you either add or subtract the ABS value of PID_Out from whatever value corresponds to 30% duty cycle. Here you need to make sure you clamp the end value between 0 and 1023 before moving it to the duty cycle register.
Does this make sense?
/Henrik.
Bookmarks