I have a problem with a water heater that I am repairing. I am using an ESP8266 to control three 400V heaters (using 3 SSRs). I am using a DS18B20 sensor to read the temperature. However, the problem is the DS18B20 temperature sensor "pauses" the ESP8266 to read the temperature (for about 100ms). This time is quite large and prevents me from turning the SSRs on/off more often to better control the temperature of the heaters. I got information from another forum that you can read the temperature from the scratchpad rather than waiting for a fresh temperature reading (which is supposedly much faster). However, I still don't know if this would work and how to build such code. I am also thinking about whether it is not a good choice to choose ESP32 (two cores - one for SSRs, the other for temperature).
Someone can advise me how to solve this better? I would prefer to choose ESP8266 than to change to ESP32 (I already have the circuit ready), however, when there is no other choice I will think about this solution as well.
Slow down. The thermal mass will dampen your changes. You're over modulating the SSR's. 100mS is barely a handful of cycles of AC. Switching the SSR's only occurs at zero crossing every 120th/sec (~8mS), Let it run at it's natural speed and you might find it's closer than you think.
How much do you figure the water temperature can possibly change in 100mSec? Perhaps 0.01 degrees? And the accuracy of the DS18B20 is +/-0.5C, and that is only at temperatures no higher than 85C.
And, the DS18B20 is inherently quite slow. A 100mSec conversion time gets you only 9-bits of resolution. Go all the way to 12-bits, and conversion time goes up to 750mSec.
Trying to modulate the heaters at a 10Hz rate is nuts, and accomplishes absolutely nothing of value. I cannot imagine a scenario where modulating even once per second is not massive over-kill. Once every 10-30 seconds is probably more like it.
As for "pausing" the processor, I would expect the OneWire protocol would allow a conversion to be started, then the processor could go do something else until the conversion is complete, rather than spinning in a wait loop. I would look at the driver code to see if it supports that, and if it does not, I would modify the driver so it did.
What is your temp tolerance? You need an anticipating controller. What is the volume you are heating? .1s is pretty fast for any significant temp change. What is your temp range? Maybe you need a better/faster sensor. How/where is your temp probe located? Are you measuring surface or core temp? Surface temp is highly variable. Measure core temp for accuracy. Lemme guess: You're measuring the heater element temp and trying to control THAT, instead of measuring the mixed liquid temp, and using that as your control feedback.
1 second, full flow water, 18kW heaters and I get from 15C to 40C, 2 seconds all the time heating and I get about 60*C or more. This is why I need to control SSRs fast.
I use 9 bit resolution. Fast controll of heaters are very important in the instantaneous water heater. I added my code too to try edit it for better way.
If you cold help me with code, I would be very grateful.
Yes, you are right. The temperature tolerance is flow dependent. I monitor the flow and adjust the SSR switching frequency to get 40C. A better sensor is not needed, but definitely a faster sensor would be the best solution. However, I have a lot of DS18S20 sensors and would prefer to read the temperature digitally rather than analog (I wouldn't want to mess around with calibration). The temperature probe is on a copper tube after the output of three 400V heaters. I change the switching frequency of the heaters after 2 seconds for the temperature on the copper tube to stabilize (which works very well, but I miss switching the SSRs on/off more frequently).
For example: the heaters heat up 200ms and then 300ms off and I get 35C, and when the heaters heat up 300ms and then 300ms off I get 44C. In this situation, I am missing an intermediate value, such as 350ms of heating, which would definitely solve the problem.
And the measured temperature is the temperature of the already mixed liquid (at the output) and I aim to stabilize it, and for this it is necessary to turn the SSRs on and off more often.
I think that this can be very helpful for me. So how can I read it when data is ready to read? Should I use and if function and check if temperature data is ready to read?
As was stated, you use millis() to do the timing. Save the current value of millis() when the conversion is started, then read the temperature when the conversion is complete. The conversion time is based on how many bits of resolution the DS18B20 is configured for, 750mS for 12 bits, 375mS for 11 bits, 188mS for 10 bits, or 94mS for 9 bits. If you need to read the temperature more often, then use two or more sensors and stagger the readings.
Yea, I know that. I always use millis functions, never delays. But I asked only if I should use any if function to check if data from sensor is ready to get to send to microcontroller. But, now it looks like everything works good. Now my max time in loop is 30ms (every loop)!