Control SH based on outside temperature in OTGW?

This Forum is about the Opentherm gateway (OTGW) from Schelte

Moderator: hvxl

Post Reply
erikg
Starting Member
Starting Member
Posts: 6
Joined: Sat Apr 25, 2020 10:23 am

Control SH based on outside temperature in OTGW?

Post by erikg »

I use an Evohome thermostat to regulate the temperature in each room separately. Due to differences in the temperature responses the temperatures in some rooms fluctuate quite a bit. I managed to solve this by using the OTGW and limit the maximum boiler temperature by setting SH based on the outside temperature. I use a simple curve with a SH of 60deg below -10deg, a SH of 35deg above +15deg and a straight line in between.

At this moment the outside-temperature-compensation is done by running a simple python script on a Raspberry Pi connected to the OTGW, executed every 10 min with a cron job.

Since it is possible to connect a temperature sensor device directly to the OTGW, I was wondering if it is possible to let the PIC in the OTGW do this outside-temperature-compensation directly without the need for a Raspberry Pi.

Reason being to simplify the system, minimize dependencies and make it as reliable as possible.
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Control SH based on outside temperature in OTGW?

Post by hvxl »

I have no experience with OTC (Outside Temperature Compensation), but if it is as simple as you say it should even be possible for a lowly PIC to handle that.

Now normally, doing something like this would require performing some division math. The PIC doesn't have a division instruction. So doing division would require coding a subroutine, taking many programming words, which are scarce. But the exact numbers you use mean that for every degree the outside temperature rises, the maximum central heating setpoint is lowered by one degree. So, hardcoding your numbers would only require some add and/or subtract operations. You might just be able to fit that in the remaining free space.
Schelte
erikg
Starting Member
Starting Member
Posts: 6
Joined: Sat Apr 25, 2020 10:23 am

Re: Control SH based on outside temperature in OTGW?

Post by erikg »

Ok, sounds like a nice challenge to try this in the PIC. I have experience with several scripting languages but assembly is new to me.

I am thinking to take the following steps:

- Hardcode it in such that SH is set with every update of OT using the simple formula without the limits
- Add the limits: below -10deg and above 15deg
- Add a user interface command to enable/disable it
- Make it user-configurable (can the PIC do multiplication with a factor of eg 0.8?)

Any tips on my approach?
And any hints where in the code I should add/modify things?
Can I upload the program via otmonitor?
Waht happens if I have a bug? Can I still reprogram via otmonitor?

Thanks, Erik
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Control SH based on outside temperature in OTGW?

Post by hvxl »

The code starting at label 'MessageID57' deals with sending the maximum central heating water temperature to the boiler. The first two instructions distinguish between request and response. So after that is where you would put your code.

You can upload the code using otmonitor, just as you would firmware you obtain from the otgw web site. Bugs in your code do not affect this functionality, as long as you don't mess with the 3 lines starting at label 'ResetVector'. If you really break the firmware, the worst that should happen is that otmonitor is unable to upgrade the firmware fully automatically and it will ask you to manually reset the OTGW. Once you do that (within a minute), the firmware update will proceed.

The only way to brick the PIC in such a way that you will need a PIC programmer to recover is if something goes wrong (otmonitor or the PC it's running on crashes, otgw loses power) when programming the first couple of bytes. Programming the PIC happens by erasing 32 words of programming memory, and then loading them again one by one. If the erasing is done, but the reloading fails, the self-programming ability is lost. (Actually, otmonitor even tries to avoid that situation by first erasing the 2nd row of 32 words and put a jump to the self-programming code there. When the first row is erased, it contains 0x3FFF, which translates to "ADDLW -1" commands. So, in the described situation, the PIC should run through that first row without doing much, and then jump to the self-programming code anyway.)

I've used this method to do all my OTGW development pretty much from the start and don't think I ever needed to resort to using a PIC programmer to recover from loading faulty firmware.
Schelte
erikg
Starting Member
Starting Member
Posts: 6
Joined: Sat Apr 25, 2020 10:23 am

Re: Control SH based on outside temperature in OTGW?

Post by erikg »

Thanks for the tips. I managed to reprogram the OTGW with my modified code. That works indeed very intuitive.

As a first test I set SH to OT + offset, where offset is a constant.

I have a few more questions on the code:
- I used only maxchsetpoint1 and outside1 for now. What is the meaning of maxchsetpoint2 and outside2?
- Any special things I need to do when OT is negative?
- When I add the code at label 'MessageID57' it seems to be executed when SH is set from the serial interface but not when OT is set. What should i do to trigger an update of SH when OT changes?
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Control SH based on outside temperature in OTGW?

Post by hvxl »

That was quick!

By adding an offset to the outside temperature you get a higher water temperature the warmer it gets. That's the wrong way around. I expected you would have to do: 50 - OT.

Opentherm messages contain a 16-bit data value, so you need 2 bytes to store such a value. I very creatively called these two bytes maxchsetpoint1 and maxchsetpoint2 for the Max CH water setpoint, and outside1 and outside2 for the outside temperature. Both MessageID 27 (outside temperature) and 57 (Max CH water setpoint) are formatted as f8.8, meaning byte1 contains the integer part (and sign), and byte2 contains the fractional part.

Because the values are in two's complement format, you should not need to do anything special for negative outside temperatures.

By just changing the code at label 'MessageID57', the OTGW will only replace the data value when the thermostat sends MessageID #57, and possibly even limited to when it's a Write-Data request. However, if you set the MaxHeatSetpoint flag (bsf MaxHeatSetpoint), the OTGW will send a Write-Data request for MessageID57 in the next available alternative slot. This is what the code that processes the SH serial command does. So you would do the same thing when the outside temperature changes, i.e. in the StoreOutTemp subroutine.
Schelte
erikg
Starting Member
Starting Member
Posts: 6
Joined: Sat Apr 25, 2020 10:23 am

Re: Control SH based on outside temperature in OTGW?

Post by erikg »

Thanks!

I will look into using the pairs of variables for 16-bit 2-complement calculation.

In the meantime I got the idea working by only using on outside1 & maxchsetpoint1 (my boiler uses rounded temperature for this setting anyhow).

I added 2 variables maxchsetbase and maxchsetcoef that represent the offset at 0 deg outside temperature and the slope for outside temperature dependency. They can be changed by the user via the serial interface ('SH' redefined & 'OC' newly created). Both are 1 byte only.

It works except that changed variables do not survive a power down/up. Do you know how I can store those 2 bytes in EPROM and read them during initialisation?
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Control SH based on outside temperature in OTGW?

Post by hvxl »

Check out the SaveSettings and ReadEpromData subroutines.
Schelte
erikg
Starting Member
Starting Member
Posts: 6
Joined: Sat Apr 25, 2020 10:23 am

Re: Control SH based on outside temperature in OTGW?

Post by erikg »

I got it working!

With a DS18B20 temperature sensor attached to the OTGW The outside-temperature-compensation works stand alone on the OTGW. So no dependency on a working router, internet or other components.

It sets the SH parameter based on the outside temperature from the sensor (or from a manually set OT). The opentherm thermostat uses this SH as maximum water temperature and scales back based on its own regulation loop.

The curve is a straight line between -10 degC and +15 degC with a user-configurable offset at zero deg (using the existing SH setting) and slope (using a new setting: OC). Below -10 degC and above +15 degC the SH temperature is constant.

In order to fit it in the RAM and ROM of the microcontroller I had to remove (comment-out) a few lines of the existing code. As a result a DS18S20 temperature sensor does not work with the modified code.

Although I made the code for personal use it is available for anyone who is interested.
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Control SH based on outside temperature in OTGW?

Post by hvxl »

Congratulations! It didn't take you long to get the hang of programming assembly.
Schelte
Post Reply

Return to “Opentherm Gateway Forum”