External control timout - proposed solution

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

Moderator: hvxl

External control timout - proposed solution

Postby WimW » Sun Jun 21, 2020 9:50 am

Hello forum,

I would love your feedback on the proposed code below. I am not a coder though I have done some coding, so a critical look would be much appreciated.

The purpose is to have a 5-minute timeout on the CS command. That means: a CS command only remains valid for 5 minutes. After that, it is reset to 0, which means that the thermostat's control setpoint message will be relayed unaltered. I am building an external control system, but in case communication is lost, the CS should automatically be cancelled.

So here is my proposed solution. What do you think?

Code: Select all
;#######################################################################
; Peripheral use
;#######################################################################

;TWOSEC contains the number of timer 0 overflows (with a 1:64 prescaler)
;that happen in roughly 2 seconds. This is the time the error LED will stay
;lit after an error has been detected.
                constant TWOSEC=2*ONESEC
;FIVEMIN is the timeout for the external control system when
;CS override is cancelled
                constant FIVEMIN=300*ONESEC     ;Wim

...

;Variables for longer lasting storage
ExtCtrlIdleCounter      res 1   ;Wim

...

;########################################################################
; Main program
;########################################################################
   
...

                movlw   ONESEC
                movwf   SecCounter      ;Initialize second counter

                movlw   FIVEMIN ;Wim
                movwf   ExtCtrlIdleCounter      ;Wim - Inilialize timeout

...

; IdleTimer is called whenever timer 0 overflows
IdleTimer       bcf     INTCON,TMR0IF   ;Clear Timer 0 overflow flag
                decfsz  SecCounter,F    ;Decrease second counter
                goto    IdleTimerJ1
                decfsz  ExtCtrlIdleCounter,F    ;Wim - Decrease timeoutcounter
                goto IdleTimerJ0        ;Wim
                clrf    controlsetpt1   ;Wim
                clrf    controlsetpt2   ;Wim - Cancel external control
                movlw   FIVEMIN         ;Wim
                movwf   ExtCtrlIdleCounter      ;Wim - Reset timeoutcounter
IdleTimerJ0             ;Wim
                btfsc   BoilerAlive     ;Ever received a message from boiler?

...

;************************************************************************
; Parse commands received on the serial interface
;************************************************************************

...

SetCtrlSetpoint call    GetFloatArg
                skpnc
                return
                btfsc   NegativeTemp    ;Check for a negative value
                retlw   SyntaxError     ;Negative temperatures are not allowed
                movwf   controlsetpt1
                movfw   float2
                movwf   controlsetpt2
                movlw   FIVEMIN ;Wim - reset ext. control timeout timer
                movwf   ExtCtrlIdleCounter      ;Wim - good external command received
                goto    CommandFloat
WimW
Starting Member
Starting Member
 
Posts: 5
Joined: May 2020

Re: External control timout - proposed solution

Postby hvxl » Mon Jun 22, 2020 12:45 pm

A good attempt. But have you tested this? I'm asking because it doesn't look to me like it will do exactly what you intend.

You define FIVEMIN as the number of timer 0 overflows in 5 minutes, but you count the number of times SecCounter reaches 0, i.e. the number of seconds.

Actually, counting the seconds is a good idea, because the PIC is an 8-bit processor and your FIVEMIN value (18300) is way too big to fit in 8 bits. So your FIVEMIN value should really be 300, not 300*ONESEC. But 300 is still a bit too big for a single byte. The easiest solution is to settle for FOURMIN; 240 fits in 8 bits. (By using your current definition of FIVEMIN, you actually load your counter with 124 (the lower 8 bits of 18300). So the control setpoint is cleared after a little more than 2 minutes.)

Once you cleared the control setpoint, you reload the ExtCtrlIdleCounter. This serves no useful purpose. So you can skip that step and save 2 program words.
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1303
Joined: June 2010

Re: External control timout - proposed solution

Postby WimW » Fri Jun 26, 2020 1:55 pm

A big thank you to hxvl! The timeout works.

I corrected my mistakes as posted below for the sake of anyone who would like to use this. All the lines with "Wim" in the comments are additions.

It reports that it builds successfully but the build.vbs produces an "invalid root in registry key" on line 67. I am assuming that this does not cause any functional problems. I don't see any.

Now in contrast with earlier testing, the CS command doesn't activate the boiler. I'm starting with the assumption that the current high outside temperature or high room temperature influences some control logic inside the boiler. That might not be a problem since my external control is not supposed to be useful in summer. I hope it's not a sign of a more general system fault. There are no error messages on the boiler or the thermostat but Opentherm Monitor shows an occasional error 03.

Any comments are much appreciated!


Code: Select all
;#######################################################################
; Peripheral use
;#######################################################################


;TWOSEC contains the number of timer 0 overflows (with a 1:64 prescaler)
;that happen in roughly 2 seconds. This is the time the error LED will stay
;lit after an error has been detected.
      constant TWOSEC=2*ONESEC

;Wim - EXTCTRLTIMEOUT is timeout for the external control system after which
;Wim - the "CS" command is cancelled
      constant EXTCTRLTIMEOUT=200   ;Wim - seconds

...

;Variables for longer lasting storage
ExtCtrlIdleSecs    res 1   ;Wim

...

;########################################################################
; Main program
;########################################################################
   
...

      movlw   ONESEC
      movwf   SecCounter   ;Initialize second counter

      movlw   EXTCTRLTIMEOUT   ;Wim
      movwf   ExtCtrlIdleSecs   ;Wim - Initialize timeout
   
...   
      
; IdleTimer is called whenever timer 0 overflows
IdleTimer   bcf   INTCON,TMR0IF   ;Clear Timer 0 overflow flag
      decfsz   SecCounter,F   ;Decrease second counter
      goto   IdleTimerJ1
      decfsz   ExtCtrlIdleSecs,F   ;Wim - Decrease timeoutcounter
      goto IdleTimerJ0   ;Wim
      clrf   controlsetpt1    ;Wim
      clrf    controlsetpt2   ;Wim - Cancel external control
IdleTimerJ0      ;Wim
      btfsc   BoilerAlive   ;Ever received a message from boiler?
      
...
      
;************************************************************************
; Parse commands received on the serial interface
;************************************************************************      
      
...

SetCtrlSetpoint   call   GetFloatArg
      skpnc
      return
      btfsc   NegativeTemp   ;Check for a negative value
      retlw   SyntaxError   ;Negative temperatures are not allowed
      movwf   controlsetpt1
      movfw   float2
      movwf   controlsetpt2
      movlw   EXTCTRLTIMEOUT ;Wim - reset ext. control timeout timer
      movwf   ExtCtrlIdleSecs   ;Wim - good external command received
      goto   CommandFloat
WimW
Starting Member
Starting Member
 
Posts: 5
Joined: May 2020

Re: External control timout - proposed solution

Postby hvxl » Mon Jun 29, 2020 12:10 pm

Don't guess. Check the logs to see what happens.

Most boilers don't have an outside temperature sensor. Even the ones that do should just report the value to the thermostat. Then it's up to the thermostat what to do with that information. So the boiler won't alter its behavior because of high outside temperatures. They also normally don't look at the room temperature.

The only reason an Opentherm compliant boiler would not switch on for a certain control setpoint, is if the water temperature is already close to, or higher than the requested temperature.

The build.vbs script updates the build number and date and time. If it fails, the information reported by PR=A and PR=B will not reflect your private version.
Schelte
hvxl
Senior Member
Senior Member
 
Posts: 1303
Joined: June 2010

Re: External control timout - proposed solution

Postby WimW » Mon Jun 29, 2020 6:55 pm

Again thank you, hvxl

Today the boiler does get active when a higher CS is requested.

FYI, there is indeed an outside temperature sensor. And I had indeed set the CS request 20 °C higher than the current boiler water temperature.

I will start working on the control system now. If it should run into the situation again, I will activate the OTmonitor and its logging function and try to figure it out.
WimW
Starting Member
Starting Member
 
Posts: 5
Joined: May 2020


Return to Opentherm Gateway Forum

Who is online

Users browsing this forum: No registered users and 1 guest