Question implementing PID logarithm in one's automated home brewery

EccentricDyslexic

New member
Joined
Oct 7, 2013
Messages
2
Programming Experience
Beginner
Hi peeps,

i have had my automated brewery up and running for a couple of years but have always had issues with maintaining the mash tun at the required temperature. Currently i use the following code-
PrivateSub tmrRIMs_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRIMs.Tick


Dim nextCheck AsInteger = 200



SelectCaseTrue


Case RIMS_CurrentTemp <= (desiredtemp - 1.7) ' CONSTANT ON

nextCheck = 1000

heaterIsOn =
True



Case RIMS_CurrentTemp >= (desiredtemp - 1.6) AndAlso RIMS_CurrentTemp < (desiredtemp - 0.6)


If heaterIsOn Then

nextCheck = 400

heaterIsOn =
False


Else

nextCheck = 600

heaterIsOn =
True


EndIf



Case RIMS_CurrentTemp >= (desiredtemp - 0.5) AndAlso RIMS_CurrentTemp < (desiredtemp - 0.2)


If heaterIsOn Then

nextCheck = 500

heaterIsOn =
False


Else

nextCheck = 500

heaterIsOn =
True


EndIf



Case RIMS_CurrentTemp >= (desiredtemp - 0.1) AndAlso RIMS_CurrentTemp < (desiredtemp + 0.1) ' TARGET TEMP


If heaterIsOn Then

nextCheck = 750

heaterIsOn =
False


Else

nextCheck = 250

heaterIsOn =
True


EndIf





Case Else'temp is too high

nextCheck = 1000

heaterIsOn =
False


EndSelect


setHeaterState(heaterIsOn)

tmrRIMs.Interval = nextCheck

As you can see, it is very simple and herein is where the problem is. I want to change this code so it functions as a errrr function with a variable passed to it between 0 and 100 to relate to how much time per second in percentage time the heater ellement is powered on. ie 0% = off 60% = on for 600ms/off for 400ms and of course 100% means on all the time.
Then i want to implement a PID sub every second to monitor the temperature of the flow of fluid past the element (downstream) and see how close it is to the desired temperature and make adjustments to the function above to keep the flow at the temperature i set it to.

I would really appreciate some help doing this from you guys, firstly i think it would be good to work with this piece of code so that it functions as a errrr function with an input of 0 - 100%.

Thanks in advance peeps!

Steve
 
Your switching frequency should be lower than 1Hz (1 per second). You can check the temperature more often, but if you turn the element on and off once per second, the element will never get to heat up properly. Also I don't think you really need a classic PID controller for this, since you can correct actively. PID controllers are useful in actual thermostat feedback loops. What you can do however is keep an history of previous readings.
 
Hi Herman,

the switching frequency is between 100ms and 1000ms in the above code, but the temperature measurement is taken every second at the moment, but this should be increased to allow enough time for there to be a change in temperature, id say 2-3 seconds. Ideally need a auto tune sub set up so that once there is a continuous temperature for say 10 seconds with very little change, then turn on the heater element and see how long it takes for a temperature increase to be detected. This needs to be done every brew session as the flow rate will change every time. once that measurement has been established, the temperature can be taken and the PID makes an appropriate adjustment to the heat required. Does that make sense?

Steve
 
Back
Top