Cool Henrik, I think I may have a use for this
Ok, this is a whole new area to me, here's what I think I've grasped wrt how this works ....
You 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?!!
Ok, what to do with pid_out?
For my intended use, I want to control a 256 step digital SPI pot (which alters the magnitude of an analog signal - an AGC in essence)...I have a 'desired value' ADC sample (a simple 8 bit ADC sample of the wiper from a std analogue pot ittingt between VCC & Gnd) that I want the signal to 'hit', but obviously the digital pot needs to either increment or decrement towards getting the signal to meet the desired value - 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?
What do I need to tweak with this bit...
I’m controlling my digital pot like thus…Code:Main_Loop: gosub adc pid_Error = Setpoint - ADValue 'Calculate the error Gosub PID 'Result returned in pid_Drive Direction = pid_Out.15 'Set direction pin accordning to sign pid_Out = ABS pid_Out 'Convert from two's comp. to absolute how to control the digital pot here?!!! Pause 10 'Wait.... Goto Main_Loop '...and do it again.
I’m figuring it’s just a case of something like GOSUB write_VR1 & then within there having the data byte be pid_out?Code:write_VR1: LOW CS SSPBUF = VR1_Select 'put the command byte into SSPBUF gosub letclear SSPBUF = VR1_Position 'put the data byte into SSPBUF gosub letclear high CS RETURN letclear: IF PIR1.3 = 0 Then letclear ' wait for SPI interupt flag PauseUs 10 ' 25uS fudge factor PIR1.3 = 0 ' clear buffer full status Return
Hand holdng warmly accepted!





Bookmarks