PID control thermostat.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

PID control thermostat.

#1 Post by igorka » 24 Jan 2023, 12:09

For a long time I had a desire to make a regulator working according to the Proportional Integral Differential regulation law, abbreviated as PID. I will not describe here how it is better than the classic relay with hysteresis, whoever is interested will find the answers himself. The only thing worth noting is that this regulator is used where high accuracy in maintaining the temperature (or other controlled parameter) is needed.
The classic PID controller uses floating point values ​​in its calculations and this option is better suited for ESP_Easy (due to the peculiarities of the mathematics implemented in the firmware), but initially I wrote code for an 8-bit microcontroller, where memory is limited as well as core speed, so the implementation is such.
Another interesting solution I think is how the load management is implemented, this is the "Bresenham's" algorithm. of course, you can apply PWM control or phase-pulse control, it all depends on the task and your imagination.
Important point! The "PID" function must be called with the same time period!
All coefficients P, I, D are selected individually, on a real object where the regulator will work!

Code: Select all

On System#Boot do
  let,1,27//scaling I
  let,2,0//working variable "Bresenham's"
  let,3,100//discreteness "Bresenham's"
  let,4,5//P_gain 
  let,5,1//I_gain
  let,6,0//D_gain
  let,7,1//Gain_scaling
  let,8,0//Feedback
  let,9,280//Setpoint
  let,10,0//PID_p
  let,11,0//PID_i
  let,12,0//PID_d
  let,13,0//PID_px
  let,14,0//PID_y
loopTimerSet,1,1//turn on the timer with a period of 1 second
endon
on Rules#Timer=1 do
  let,8,[termo_1#temperature]//it's not 280, it's 28.0. But you need to write without a comma!
  let,8,[var#8]*10//this is necessary in order not to lose the capacity of the temperature sensor.
  let,9,[var#9#F]//removes everything after the comma
  let,10,[int#9]-[int#8]//PID_p = Setpoint - Feedback
  let,10,[var#10#F]
  let,12,[int#10]-[int#13]//PID_d = PID_p - PID_px
  let,12,[var#12#F]
  let,13,[int#10]//PID_px = PID_p
  let,13,[var#13#F]
  let,14,[int#10]*[int#4]//PID_y = (PID_p * P_gain)
  let,14,[var#14#F]
  let,14,[int#14]+([int#11]*[int#5])/[int#1]//PID_y = PID_y + (PID_i * I_gain)/scaling I
  let,14,[var#14#F]
  let,14,[int#14]+([int#12]*[int#6])//PID_y = PID_y + (PID_d * D_gain)
  let,14,[var#14#F]
  //let,14,[int#14]+[int#12]//if you do not use the D component in the calculations, then you can write it like this
  //let,14,[var#14#F]
  let,14,[int#14]/[int#7]//PID_y = PID_y / Gain_scaling
  let,14,[var#14#F]
    if [int#14] > 100//control variable constraint. 100 because it is convenient to take for 100%
      let,14,100
        else 
    if [int#14] < 0//remove negative numbers
  let,14,0
    endif
    let,11,[int#11]+[int#10]
    let,11,[var#11#F]
  endif
    let,2,[int#2]+[int#14]//conversion of PID value value to power factor
  if [int#2]>=[int#3]
    let,2,[int#2]-[int#3]
   gpio,0,0//active level
   else
   gpio,0,1//low level
  endif
endon
Here are some heat curves. Unfortunately, I have nothing to do with high-quality graphics.
The state of rest.
The state of rest.
3.png (53.99 KiB) Viewed 7217 times
change the temperature setpoint to 28. Heating 100%
change the temperature setpoint to 28. Heating 100%
4.png (65.26 KiB) Viewed 7217 times
The PID controller starts to work and reduce the heating power.
The PID controller starts to work and reduce the heating power.
5.png (74.94 KiB) Viewed 7217 times
Typical overshoot for a PID controller.
Typical overshoot for a PID controller.
6.png (101.29 KiB) Viewed 7217 times
Stabilization mode with minimal temperature fluctuations, this is normal.
Stabilization mode with minimal temperature fluctuations, this is normal.
7.png (99.07 KiB) Viewed 7217 times
I changed the extension of the temperature graph (upper graph) so that the accuracy of the maintained temperature can be more clearly seen.
I changed the extension of the temperature graph (upper graph) so that the accuracy of the maintained temperature can be more clearly seen.
9.png (119.45 KiB) Viewed 7217 times
Last edited by igorka on 26 Jan 2023, 08:46, edited 2 times in total.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#2 Post by igorka » 24 Jan 2023, 12:27

Photo to understand the work of the "Bresenham's" algorithm:
25% power.
25% power.
output_25.png (28.02 KiB) Viewed 7212 times
50% power.
50% power.
output_50.png (20.73 KiB) Viewed 7212 times
75% power.
75% power.
output_75.png (26.38 KiB) Viewed 7212 times
99% power.
99% power.
output_99.png (23.91 KiB) Viewed 7212 times
At 50% (function call 1 time per second), 1 second on - one second off. And so on.

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#3 Post by TD-er » 24 Jan 2023, 12:27

There is still an mismatch in endif's in your code:

Code: Select all

  if [int#14] > 100//control variable constraint. 100 because it is convenient to take for 100%
    let,14,100
  else 
    if [int#14] < 0//remove negative numbers
      let,14,0
    endif
  else // <<<==== 2nd 'else', mismatch
    let,11,[int#11]+[int#10]
    let,11,[var#11#F]
  endif
I changed the indents, so you can see where the mismatch is.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#4 Post by igorka » 24 Jan 2023, 13:45

TD-er wrote: 24 Jan 2023, 12:27 There is still an mismatch in endif's in your code
This happened due to the fact that there was an error in the notepad, and there was code with comments :oops: :roll: . On ESP the code is flooded without error. Thank you for bringing this to our attention! In the first message removed unnecessary else.

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#5 Post by TD-er » 24 Jan 2023, 15:07

You have a lot of these:

Code: Select all

  let,14,[var#14#F]
However, you can also use the variable like this when referring it:

Code: Select all

  [var#14#F]
That may save quite a few lines of rules code.

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#6 Post by chromo23 » 25 Jan 2023, 17:52

Nice Idea,
i will try this soon...
I took the liberty to remove the unnecessary declaring of variables as TD-er suggested and did some formatting.
(You wouldn’t even need to declare variables with 0 at boot, but i guess you know that...)

Code: Select all

 On System#Boot Do
  Let,1,27    		//scaling I
  Let,2,0       	//working variable "Bresenham's"
  Let,3,100   		//discreteness "Bresenham's"
  Let,4,5       	//P_gain 
  Let,5,1       	//I_gain
  Let,6,0       	//D_gain
  Let,7,1       	//Gain_scaling
  Let,8,0       	//Feedback
  Let,9,280    		//Setpoint
  Let,10,0      	//PID_p
  Let,11,0      	//PID_i
  Let,12,0      	//PID_d
  Let,13,0      	//PID_px
  Let,14,0      	//PID_y
  LoopTimerSet,1,1    	//turn on the timer with a period of 1 second
Endon

On Rules#Timer=1 Do
  Let,8,[termo_1#temperature]    		//it's not 280, it's 28.0. But you need to write without a comma!
  Let,8,[var#8]*10                         	//this is necessary in order not to lose the capacity of the temperature sensor.
  Let,10,[var#9#F]-[int#8]            		//PID_p = Setpoint - Feedback
  Let,12,[var#10#F]-[int#13]        		//PID_d = PID_p - PID_px
  Let,13,[int#10]                          	//PID_px = PID_p
  Let,14,[int#10]*[int#4]              		//PID_y = (PID_p * P_gain)
  Let,14,[var#14#F]+([int#11]*[int#5])/[int#1] 	//PID_y = PID_y + (PID_i * I_gain)/scaling I
  Let,14,[var#14#F]+([var#12#F]*[int#6])	//PID_y = PID_y + (PID_d * D_gain)
  //Let,14,[int#14]+[int#12]         		//if you do not use the D component in the calculations, then you can write it like this
  Let,14,[var#14#F]/[int#7]         		//PID_y = PID_y / Gain_scaling
  If [var#14#F] > 100                  		//control variable constraint. 100 because it is convenient to take for 100%
    Let,14,100
  Else 
    If [var#14#F] < 0           		//remove negative numbers
      Let,14,0
    Endif
    Let,11,[int#11]+[int#10]
    Let,11,[var#11#F]
  Endif
  Let,2,[int#2]+[int#14]      			//conversion of PID value value to power factor
  If [int#2]>=[int#3]
    Let,2,[int#2]-[int#3]
    GPIO,0,0
  Else
    GPIO,0,1
  Endif
Endon

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#7 Post by igorka » 26 Jan 2023, 08:37

chromo23 wrote: 25 Jan 2023, 17:52 Nice Idea,
i will try this soon...
I took the liberty to remove the unnecessary declaring of variables as TD-er suggested and did some formatting.
(You wouldn’t even need to declare variables with 0 at boot, but i guess you know that...)
Greetings! If my code is useful to someone, I will only be happy. And of course I don't mind if you or someone else changes it to suit your needs or optimizes it. This is source code, so there are a lot of extra lines, so it's easier for me to visually track the execution sequence. I wrote about it here: viewtopic.php?p=62648#p62648
Before setting the P, I, D coefficients, you need to set I and D to 0, and start selection from P. A correctly adjusted P coefficient (I, D is still 0, this is the first stage of adjustment) will never allow the regulator to reach the set temperature, it will be slightly -a bit less. The second step will be the setting of the Integral component, the speed of reaching the operating mode depends on its value. I left the coefficient D equal to zero, an accuracy of 0.2 ° C was enough for me. Here you can clearly see how this or that coefficient affects:
Image
Please note that I have the reverse control logic! Where 0 is on and 1 is off.

Code: Select all

  Let,2,[int#2]+[int#14]      			
  If [int#2]>=[int#3]
    Let,2,[int#2]-[int#3]
    GPIO,0,0//active level
  Else
    GPIO,0,1//low level
  Endif
Endon

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#8 Post by TD-er » 26 Jan 2023, 08:59

Do you have a good source of information on how to tune the PID controller?
In a previous job, I have been working a lot with PID controllers to fine-tune motor controllers on CNC 3D measurement machines (so called geometric metrology).
However, I always found this tuning to be quite a lot of work and then started working on some auto-tuning algorithm.
But always did this on intuition, not hindered by any knowledge or being educated in this matter.
So it would be nice if I finally can really 'understand' PID tuning and maybe once make a module for it for ESPEasy. :)
Like I said, I do almost anything here on intuition.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#9 Post by igorka » 26 Jan 2023, 09:32

TD-er wrote: 26 Jan 2023, 08:59 Do you have a good source of information on how to tune the PID controller?
In a previous job, I have been working a lot with PID controllers to fine-tune motor controllers on CNC 3D measurement machines (so called geometric metrology).
However, I always found this tuning to be quite a lot of work and then started working on some auto-tuning algorithm.
But always did this on intuition, not hindered by any knowledge or being educated in this matter.
So it would be nice if I finally can really 'understand' PID tuning and maybe once make a module for it for ESPEasy. :)
Like I said, I do almost anything here on intuition.
I confess that I, like you, do it intuitively, and not using formulas from textbooks. Although there are quite a few good PID tuning guides on the internet. Also, the difficulty lies in the fact that I am in the Russian-speaking part of the Internet, it will probably be difficult for you to understand materials that are not in English. On the other hand, I also communicate with you through Google translator ...
Here the guy has implemented his PID library with autotuning function for Arduino.
https://alexgyver.ru/lessons/pid/
It would be cool if the PID was in ESP_Easy by default!!! :D

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#10 Post by TD-er » 26 Jan 2023, 09:56

Just added an GitHub Issue for it, to keep track of the links and ideas
https://github.com/letscontrolit/ESPEasy/issues/4482

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#11 Post by igorka » 26 Jan 2023, 14:01

TD-er wrote: 26 Jan 2023, 09:56 Just added an GitHub Issue for it, to keep track of the links and ideas
https://github.com/letscontrolit/ESPEasy/issues/4482
It's good, but I didn't use his examples. I just gave a link to this guy's site, as he does smart things and is passionate about it.

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#12 Post by TD-er » 26 Jan 2023, 14:03

Yep, I browsed through those pages and they looked practical enough for me to read again at a later time, when I will look into this PID feature.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#13 Post by igorka » 26 Jan 2023, 14:45

:idea: Made some changes to the code:

Code: Select all

 On System#Boot Do
  Let,1,27    		//scaling I
  Let,2,0       	//working variable "Bresenham's"
  Let,3,100   		//discreteness "Bresenham's"
  Let,4,5       	//P_gain 
  Let,5,1       	//I_gain
  Let,6,0       	//D_gain
  Let,7,1       	//Gain_scaling
  Let,8,0       	//Feedback
  Let,9,280    		//Setpoint
  Let,10,0      	//PID_p
  Let,11,0      	//PID_i
  Let,12,0      	//PID_d
  Let,13,0      	//PID_px
  Let,14,0      	//PID_y
  LoopTimerSet,1,1    	//turn on the timer with a period of 1 second
Endon

On Rules#Timer=1 Do
  Let,8,[termo_1#temperature]    		            //it's not 280, it's 28.0. But you need to write without a comma!
  Let,8,[var#8]*10                         	                    //this is necessary in order not to lose the capacity of the temperature sensor.
  Let,10,[var#9#F]-[int#8]            		           //PID_p = Setpoint - Feedback
  Let,12,[var#10#F]-[int#13]        		           //PID_d = PID_p - PID_px
  Let,13,[int#10]                          	                   //PID_px = PID_p
  Let,14,[int#10]*[int#4]              		           //PID_y = (PID_p * P_gain)
  if [int#11] < -100
    let,11,-100//i_min
      else
    if [int#11] > 2000
      let,11,2000//i_max
        endif
       else
      Let,14,[var#14#F]+([int#11]*[int#5])/[int#1]   //PID_y = PID_y + (PID_i * I_gain)/scaling I
  endif 
  Let,14,[var#14#F]+([var#12#F]*[int#6])	           //PID_y = PID_y + (PID_d * D_gain)
  //Let,14,[int#14]+[int#12]         		          //if you do not use the D component in the calculations, then you can write it like this
  Let,14,[var#14#F]/[int#7]         		         //PID_y = PID_y / Gain_scaling
  If [var#14#F] > 100                  		         //control variable constraint. 100 because it is convenient to take for 100%
    Let,14,100
  Else 
    If [var#14#F] < 0           		                         //remove negative numbers
      Let,14,0
    Endif
    Let,11,[int#11]+[int#10]
    Let,11,[var#11#F]
  Endif
  Let,2,[int#2]+[int#14]      			         //conversion of PID value value to power factor
  If [int#2]>=[int#3]
    Let,2,[int#2]-[int#3]
    GPIO,0,0
  Else
    GPIO,0,1
  Endif
Endon
An unpleasant feature was found out, if, for example, the regulator maintained the temperature (any value) around 28, then changed the setpoint [int#9] to 23 for hot, then for some time in the variable [int#11] there will be a large negative number. Because of this, if you change, for example, again to the same 28, then the output to the operating mode will be very long and "you can grow old or freeze. :lol: " In order to avoid this, I entered the minimum and maximum values of the variable [int#11] (these values are checked experimentally on the working object), they are like this for me ... By the way, they write about the limitations of the i - component in textbooks.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#14 Post by igorka » 31 Jan 2023, 08:55

The principles of regulation systems, their differences and features are simply described. With an emphasis on the PID controller. There is a link to the original source (Italian).
https://arduino.ru/forum/pesochnitsa-ra ... ent-512052

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#15 Post by igorka » 14 May 2023, 12:45

chromo23 wrote: 25 Jan 2023, 17:52 Nice Idea,
i will try this soon...
I took the liberty to remove the unnecessary declaring of variables as TD-er suggested and did some formatting.
(You wouldn’t even need to declare variables with 0 at boot, but i guess you know that...)
Hi, the topic has stalled. To be honest, I myself have lost interest in its further promotion :( . But still curious, have you tried PID in practice?

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#16 Post by chromo23 » 16 May 2023, 09:18

igorka wrote: 14 May 2023, 12:45 But still curious, have you tried PID in practice?
Unfortunately i did not find the time for this....

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#17 Post by chromo23 » 19 Jun 2023, 22:14

Ok.. i found some time and also some mistakes in the code (at least i think they are mistakes)

1. constraining "I":

your code:

Code: Select all

if [int#11] < -100 
    let,11,-100//i_min
      else
    if [int#11] > 2000
      let,11,2000//i_max
        endif
       else
      Let,14,[var#14#F]+([int#11]*[int#5])/[int#1]   //PID_y = PID_y + (PID_i * I_gain)/scaling I
  endif 
  
i think it should be like this:

Code: Select all

  If [int#11] < -100
    Let,11,-100//i_min
  Elseif [int#11] > 100
    Let,11,100//i_max
  Endif 
  
  Let,14,[int#14]+([int#11]*[int#5])/[int#1]  
  
2. constraining PID_y

your code:

Code: Select all

If [var#14#F] > 100                  		         //control variable constraint. 100 because it is convenient to take for 100%
    Let,14,100
  Else 
    If [var#14#F] < 0           		                         //remove negative numbers
      Let,14,0
    Endif
    Let,11,[int#11]+[int#10]
    Let,11,[var#11#F]
  Endif
should be like this?

Code: Select all

  If [int#14] > 100                  		                      //control variable constraint. 100 because it is convenient to take for 100%
    Let,14,100
  Elseif [int#14] < 0           		                         //remove negative numbers
    Let,14,0
  Endif
  
  Let,11,[int#11]+[int#10]
  // Let,11,[var#11#F]   <- i removed this because i don´t see the need to floor it when using int everywhere
  
igorka wrote: 26 Jan 2023, 14:45 Let,10,[var#9#F]-[int#8]
You also flooring values a lot. In my understanding "int" is doing the same thing so i changed everything to "int"

I used your code to test it on one of my coffee machines. I took ages to find the right values for P, I and D but it is doable and works quite reasonable for me.
I love ESPeasy for that purpose. I can quickly test things without the hassle of writing additional code. And with the power of easyfetch i can also easily build a test web-interface where i can set all the necessary variables. ;)
coffe_interface.png
coffe_interface.png (74.48 KiB) Viewed 5787 times
coffee_graph.png
coffee_graph.png (70.53 KiB) Viewed 5787 times

here the whole PID related code:

Code: Select all

On start Do
   Let,1,27    	    //scaling I
  Let,2,0            //working variable "Bresenham's"
  Let,3,100        //discreteness "Bresenham's"
  Let,4,1      	     //P_gain     //1
  Let,5,0       	   //I_gain     //0
  Let,6,25       	  //D_gain  //20
  Let,7,1       	   //Gain_scaling
  Let,8,0       	   //Feedback
  Let,9,95    	   //Setpoint
  Let,10,0     	    //PID_p
  Let,11,0      	  //PID_i
  Let,12,0      	  //PID_d
  Let,13,0      	  //PID_px
  Let,14,0      	  //PID_y
  LoopTimerSet,1,1    	//turn on the timer with a period of 1 second
Endon

On stop Do
   LoopTimerSet,1,0
Endon

On Rules#Timer=1 Do
  Let,8,[tempXX#temperature]*10		                                 	           
  Let,10,[int#9]*10-[int#8]            		                //PID_p = Setpoint - Feedback
  Let,12,[int#10]-[int#13]        		                //PID_d = PID_p - PID_px
  Let,13,[int#10]                          	              //PID_px = PID_p
  Let,14,[int#10]*[int#4]              		             //PID_y = (PID_p * P_gain)
  
  If [int#11] < -100                          
    Let,11,-100//i_min
  Elseif [int#11] > 100
    Let,11,100//i_max
  Endif 
  
  //Let,14,[int#14]+([int#11]*[int#5])/[int#1]       //PID_y = PID_y + (PID_i * I_gain)/scaling I
  Let,14,([int#11]*[int#5])/[int#1]+[int#14]       changed calculation...see next post
  Let,14,[int#14]+([int#12]*[int#6])	                //PID_y = PID_y + (PID_d * D_gain)
  //Let,14,[int#14]+[int#12]         		                 //if you do not use the D component in the calculations, then you can write it like this
  Let,14,[int#14]/[int#7]         		                     //PID_y = PID_y / Gain_scaling
  
  If [int#14] > 100                  		                      //control variable constraint. 100 because it is convenient to take for 100%
    Let,14,100
  Elseif [int#14] < 0           		                         //remove negative numbers
    Let,14,0
  Endif
  
  Let,11,[int#11]+[int#10]
  Let,2,[int#2]+[int#14]      			         //conversion of PID value value to power factor
  
  If [int#2]>=[int#3]
    Let,2,[int#2]-[int#3]
    //turn something on
    GPIO,2,0
  Else
    //turn something off
    GPIO,2,1
  Endif
Endon
Last edited by chromo23 on 21 Jun 2023, 01:06, edited 1 time in total.

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#18 Post by chromo23 » 20 Jun 2023, 15:56

maybe i found a bug?

this:

Code: Select all

 Let,14,[int#14]+([int#11]*[int#5])/[int#1]
example: Let,14,2+(-160*0)/30
var#14=0.066667


is not the same than this:

Code: Select all

 Let,14,([int#11]*[int#5])/[int#1]+[int#14] 
 
example: Let,14,(-160*0)/30+2
var#14=2

shouldn´t it be the same?

TD-er
Core team member
Posts: 9266
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: PID control thermostat.

#19 Post by TD-er » 20 Jun 2023, 17:32

Not sure if we should consider this a bug, but it is for sure not what you would expect.

I have to look into this, to see what is causing this and also what it takes to change this.

It is obvious the expression is parsed from left to right.
I know there is a function to determine precedence in evaluating calculations, so I would expect it to obey these precedence rules.
No idea why it doesn't.

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: PID control thermostat.

#20 Post by igorka » 20 Jun 2023, 20:27

Hello chromo23!
Unfortunately, I am now sorely lacking free time for hobbies. In addition, my prototype heater with a PID controller is not available to me... I also have a bad trait, namely, while I'm actively doing something, I remember everything, it's worth taking a break and you need to remember everything first, it's terrible.
From what immediately catches your eye, it is that your reworking of the code has the wrong direction to the side. Namely, I wrote the PID code for an eight-bit one in order to save memory and not load the controller with comma calculations, calculations with the int type were used, so the correct work will only be with integer logic!
The web interface looks cool! And I hope you don't control the heater via a relay...Sorry for such an uninformative answer.

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#21 Post by chromo23 » 20 Jun 2023, 21:53

igorka wrote: 20 Jun 2023, 20:27 Hello chromo23!
From what immediately catches your eye, it is that your reworking of the code has the wrong direction to the side.
I´m not sure what you mean by that but maybe you can elaborate when you find the time for that... for now it really works absolutely great. I never expected that.... :)
igorka wrote: 20 Jun 2023, 20:27 calculations with the int type were used, so the correct work will only be with integer logic!
I didn't do any changes that cause floating point numbers. All is still integer.
igorka wrote: 20 Jun 2023, 20:27 The web interface looks cool! And I hope you don't control the heater via a relay...
Thanks :) And i use a SSR (But with small resistive loads and the one second cycle a mechanical relay would be fine as well i guess)
igorka wrote: 20 Jun 2023, 20:27 Sorry for such an uninformative answer.
No worries...
igorka wrote: 20 Jun 2023, 20:27 The web interface looks cool!
...for me that sentence already justifies the whole post.... :D

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#22 Post by chromo23 » 02 Jul 2023, 20:06

I finished my little project of adding to a coffee machine I actually never wanted PID.
Sometimes i see something broken and its cheap and i have the urge to buy it, repair it and make it even better than it originally was. But actually i don´t really need it (I already have three coffee machines :roll: )

Here a short video of it in action :D
https://drive.google.com/file/d/1PxNTgt ... share_link

cm3000.jpeg
cm3000.jpeg (119.21 KiB) Viewed 5608 times
cm3000_1.jpg
cm3000_1.jpg (106.89 KiB) Viewed 5603 times

wiredcharlie
Normal user
Posts: 57
Joined: 28 Sep 2020, 13:58

Re: PID control thermostat.

#23 Post by wiredcharlie » 05 Jul 2023, 12:01

Nice work!

I have a coffee machine where I used a sort of fuzzy logic approach to temperature control, so I'd really like to try your PID. How did you tune the PID values?
What thermostat probe did you use?

User avatar
chromo23
Normal user
Posts: 842
Joined: 10 Sep 2020, 16:02
Location: germany

Re: PID control thermostat.

#24 Post by chromo23 » 06 Jul 2023, 09:34

wiredcharlie wrote: 05 Jul 2023, 12:01 How did you tune the PID values?
Trial and error... you have to find the right values for you. Therefore it is highly recommended to plot the temperature curve somehow. (I send the data to thingspeak to get a diagram)
My values are P=1 I=0 D=20.
I also determine if a shot was pulled (temperature sinks below a certain value) and turn off the heater for 30 seconds. This leads to significantly faster recovery time. (the pid wants to counteract the temperature drop but the boiler itself has stored a lot of energy and so the system overshoots significantly)
The sensor i use is a ds18b20 because i have so many of them from other projects and i have the steel tube encased version which was a perfect fit for attaching it to the boiler.
Downside is that it stops at 128°C. But for brewing that is totally fine. For steaming it is to low, but i figured, that PID for steaming is counterproductive.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests