Hello,
Yes, or the other way around depening on the polarity of the feedback signal in relation to the polarity of the drive signal. SoYou have a desired value (setpoint), you take an incoming ADC reading & subtract it from your desired value....the PID sub routine then gets called & it returns a value of pid_out ?
Am I right so far?!!
pid_Error = Setpoint - ActualValue
or
pid_Error = ActualValue - SetPoint
That is really up to you ;-)Ok, what to do with pid_out?
Yes, from my understanding of your application your input signal (setpoint) ranges from 0 to 255 and you want the output of the filter to range from 0 to 255 as well. The direction bit in this case is set when the filter wants negative output, not decreasing but negative, something you can't get with your setup.I'm wondering how I translate the "Direction = pid_Out.15" to be increment/decrementof thedigital pot ...or does it not matter - ie will the value of pid_out just be a value that I can write direct to the digital pot?
So, what you need to do is to clamp the output to 0 with something like:Also, to clamp the output to a maximum of 255 you should set pid_Out_Clamp to 255. Or, which is actually better because it gives the filter more "resolution", set it to 1024 and then divide the final output by 4 before writing it to the pot.Code:If pid_Out.15 THEN pid_Out = 0
Good luck!
/Henrik.




Bookmarks