Webcontrol PLC intermittent reset

ndliu

Member
I have been on and off working on my webcontrol PLC based home monitoring system over last 4 months, by reading manual and posts from experts, I gradually got a grasp on PLC programming and started building up the functionalities of my system to meet our needs.  Now the complexity of program or hardware have reached to a point that Webcontrol PLC won't run more than 2 days without a reset. The reset happens intermittently, both during daytime and nighttime, but more in night than day.  I tried everything that have posted on this board to address the possible causes of reset, such a larger power supply, separate relay board PS from CPU board PS, add MCG Model DLP-20-6V15 Data Line Surge Protector for all 8 digital input, add AC power surge protector, add grounding wire to house ground, add fan to cool CPU, but nothing seem made a difference.  Now, I suspect something wrong with CPU or firmware.  It seems to me that the longer complex program resets earlier and more frequently than shorter simple program.  Since I have only 1 board, I could not confirm it is board problem.   Hope CAI Support or expert can help me to debug.
 
The program has following functions: Auto close garage door at night or any time when no car in garage more than 10min, Monitor Garage open event during Away_From_Home hours, mainly for confirming kids get off school and enter home,  Time stamp on events that people was found on driveway, garage door being opened,  people entered garage, water usage monitoring, taking account of odd day/even day during sprinkler season, also monitor wet basement and gas/co alert. 
 
The list and description for I/Os and variables are following:
 
DI_01: Watermeter pulse input,   0.1 gallon per pulse 
DI_02: Garage Lower Limit Switch, 1 is at close position.
DI_03: Garage Upper Limit Switch, 1 is at open position.
DI_04: Car presence detection, 1 is have at lease 1 car in garage, implies adult at home.
DI_05: Motion sensor inside Garage, 1 is people found in garage, do not want to close garage door when small kids still playing inside garage
DI_06: Driveway motion sensor, 1 is people found on driveway, used for time stamp for now, but could be used to trigger security camera in future.
DI_07: Wet basement
DI_08: Gas/CO alert
 
 
VAR1 for homestate:  0 for Night (21pm-06am), 1 for Away_From_Home(9am-4pm), and 2 for Wake_At_Home, taking into account of weekday and weekends.
VAR2 for flags: Bit1 for Garage Auto Close failed, Bit2 (not used), Bit3 People found inside garage, Bit4 high water usage email alert 
VAR3: timestamp when garage opens. It is an easy reading timestamp, 163456 means 16:34:56.  I would love to use the built in "CT" timestamp, but only found out it is HEX number in decimal looking. Without converting, I could not figure out what time it is.
VAR4: free
VAR5: timestamp when people enter garage
VAR6: timestamp when people found on driveway
VAR7: Mark watermeter position at beginning of the day, use it for daily water usage monitoring.
VAR8: water usage from the beginning of the day
 
RAM1 used for tracking HOUR changes
Ram2 used for tracking Day changes
RAM 3 for temporary calculation.
RAM4 is used for temporary calculation.
RAM5 used to flag Garage door from close to open for 1 machine cycle. 
RAM6 is used for flip bit.
RAM7 is free
RAM8 store CTS at Beginning of Day, use to calc VAR3, VAR5, VAR6 time stamps.
 
OP1 is used for Close or Open garage door
OP2 is free, 
OP3 is free
OP4 is used for gas presence indicator, stays On for 3605 seconds for hourly routine to catch the signal.
OP5 is a 5min On_Timer when inside Garage has people
OP6 is a 5min On_Timer when Driveway has people
Op7 is free
OP8 is free
 
 
To prevent PLC accidentally opens garage door during reset or power-up, I added a hardware interlock that is controlled by Garage Upper Limit switch, which only allows PLC closes garage door, but not open it.  It works very well.  
 
Below is the program, sorry for the long posting.  
 
*********Start of PLC Program*************

START
CALLSUB INITIA
LOOP1:
CALLSUB DAILY
CALLSUB HOURLY
CALLSUB DR_WAY_MT
CALLSUB GARAGE_MT
CALLSUB GAS_MT
CALLSUB OPEN_CHK
CALLSUB CHKDOOR
GOTO LOOP1
END

INITIA:
SET VAR4 0
SET RAM1 0
SET RAM3 0
SET RAM4 0
SET OP4 0
SET OP5 0
DELAY 4000
MUL CH 60 RAM8
ADD RAM8 CM RAM8
MUL RAM8 60 RAM8
ADD RAM8 CS RAM8
SUB CTS RAM8 RAM8
SET RAM2 CDAY
DIV COUNTER 10 VAR7
ANDB VAR2 7 VAR2
EMAIL EM7
RET

DAILY:
TSTNE RAM2 CDAY
GOTO DAILYCHK
RET

DAILYCHK:
SET RAM2 CDAY
SET RAM8 CTS
DIV COUNTER 10 VAR7
ANDB VAR2 7 VAR2
RET

WATERUSE:
DIV COUNTER 10 RAM3
SUB RAM3 VAR7 VAR8
TSTGE CMONTH 7 RAM3
NOP
TSTLE CMONTH 9 RAM4
NOP
AND RAM3 RAM4 RAM3
TSTEQ RAM3 0
GOTO EVEN_DAY
MOD CDAY 2 RAM3
TSTEQ RAM3 1
GOTO ODD_DAY
GOTO EVEN_DAY
ODD_DAY:
TSTGT VAR8 UROM3
CALLSUB ONE_EM4
RET

EVEN_DAY:
TSTGT VAR8 UROM2
CALLSUB ONE_EM4
RET

ONE_EM4:
ANDB VAR2 8 RAM3
TSTGT RAM3 0
RET

EMAIL EM4
ORB VAR2 8 VAR2
RET

GAS_MT:
TSTEQ IP8[10000] 1
SET OP4[3605000] 1
RET

DR_WAY_MT:
TSTEQ IP6 1
CALLSUB DRW_T1
ADD VAR6 500 VAR6
DIV VAR6 10000 RAM3
MOD VAR6 10000 RAM4
DIV RAM4 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
MOD VAR6 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
ADD RAM3 RAM8 RAM3
TSTEQ RAM3 CTS
SET OP6 0
SUB VAR6 500 VAR6
RET

DRW_T1:
MUL CH 10000 RAM3
MUL CM 100 RAM4
ADD RAM3 RAM4 RAM3
ADD RAM3 CS VAR6
SET OP6 1
RET

GARAGE_MT:
TSTEQ IP5 1
CALLSUB GM_T1
ADD VAR5 500 VAR5
DIV VAR5 10000 RAM3
MOD VAR5 10000 RAM4
DIV RAM4 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
MOD VAR5 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
ADD RAM3 RAM8 RAM3
TSTEQ RAM3 CTS
SET OP5 0
SUB VAR5 500 VAR5
RET

GM_T1:
MUL CH 10000 RAM3
MUL CM 100 RAM4
ADD RAM3 RAM4 RAM3
ADD RAM3 CS VAR5
SET OP5 1
RET

HOURLY:
TSTNE RAM1 CH
GOTO HOURCHK
RET

HOURCHK:
SET RAM1 CH
CALLSUB HMSTATUS
TSTLT T1 480
EMAIL EM6
TSTEQ IP7 1
EMAIL EM3
TSTEQ OP4 1
EMAIL EM5
CALLSUB WATERUSE
RET

HMSTATUS:
TSTGE CH UROM1 RAM3
NOP
MUL RAM3 2 RAM3
TSTLE CH 6 RAM4
NOP
ORB RAM3 RAM4 RAM3
MUL RAM3 2 RAM3
TSTGE CH 9 RAM4
NOP
ORB RAM3 RAM4 RAM3
MUL RAM3 2 RAM3
TSTLE CH 16 RAM4
NOP
ORB RAM3 RAM4 RAM3
MUL RAM3 2 RAM3
TSTGE CDW 2 RAM4
NOP
ORB RAM3 RAM4 RAM3
MUL RAM3 2 RAM3
TSTLE CDW 6 RAM4
NOP
ORB RAM3 RAM4 RAM3
TSTGT RAM3 15
SET VAR1 0
TSTGT RAM3 15
GOTO HM_END
TSTEQ RAM3 15
SET VAR1 1
TSTEQ RAM3 15
GOTO HM_END
SET VAR1 2
ANDB VAR2 13 VAR2
HM_END:
RET

CHKDOOR:
TSTEQ IP2 1
ANDB VAR2 8 VAR2
TSTEQ IP2 1
RET

TSTEQ IP2[600000] 0
GOTO CONTINUE
RET

CONTINUE:
TSTEQ OP5 1
RET

TSTEQ VAR1 0
CALLSUB CLOSENOW
TSTEQ IP2 1
RET

TSTEQ IP4[120000] 0 RAM4
CALLSUB CLOSENOW
RET

CLOSENOW:
ANDB VAR2 1 RAM3
TSTGT RAM3 0
RET

SET OP1[500] 1
DELAY 60000
TSTEQ IP2 1
EMAIL EM1
TSTEQ IP2 0
CALLSUB ONE_EM2
RET

ONE_EM2:
EMAIL EM2
ORB VAR2 1 VAR2
RET

OPEN_CHK:
XOR IP3 RAM6 RAM5
AND RAM5 IP3 RAM5
SET RAM6 IP3
AND IP3 RAM5 RAM5
TSTEQ RAM5 1
CALLSUB OPEN_T1
ADD VAR3 300 VAR3
DIV VAR3 10000 RAM3
MOD VAR3 10000 RAM4
DIV RAM4 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
MOD VAR3 100 RAM4
MUL RAM3 60 RAM3
ADD RAM3 RAM4 RAM3
ADD RAM3 RAM8 RAM3
TSTEQ RAM3 CTS
CALLSUB ENTER_CHK
SUB VAR3 300 VAR3
RET

OPEN_T1:
MUL CH 10000 RAM3
MUL CM 100 RAM4
ADD RAM3 RAM4 RAM3
ADD RAM3 CS VAR3
RET

ENTER_CHK:
TSTEQ VAR1 2
RET

TSTEQ IP4[30000] 1
RET

TSTEQ OP5 1 RAM3
NOP
TSTEQ IP4 0 RAM4
NOP
AND RAM3 RAM4 RAM4
TSTEQ RAM4 1
GOTO ENTER_EM
RET

ENTER_EM:
EMAIL EM8
DELAY 1000
ORB VAR2 4 VAR2
RET

*********End of PLC Program*************
 
 
Build date: May 02 2013, 23:32:28
 
<firmware>v03.02.17d</firmware>
<op1>0</op1>
<op2>0</op2>
<op3>0</op3>
<op4>0</op4>
<op5>0</op5>
<op6>0</op6>
<op7>0</op7>
<op8>0</op8>
<ophex>0x00</ophex>
<var1>0</var1>
<var2>0</var2>
<var3>215325</var3>
<var4>0</var4>
<var5>221037</var5>
<var6>214849</var6>
<var7>53</var7>
<var8>0</var8>
<ip1>0</ip1>
<ip2>1</ip2>
<ip3>0</ip3>
<ip4>1</ip4>
<ip5>0</ip5>
<ip6>0</ip6>
<ip7>0</ip7>
<ip8>0</ip8>
<ts1>68.7 F</ts1>
<ts2>68.7 F</ts2>
<ts3>70.3 F</ts3>
<ts4>unbound</ts4>
<ts5>unbound</ts5>
<ts6>unbound</ts6>
<ts7>unbound</ts7>
<ts8>unbound</ts8>
<tstat1>ok</tstat1>
<tstat2>ok</tstat2>
<tstat3>ok</tstat3>
<tstat4>unbound</tstat4>
<tstat5>unbound</tstat5>
<tstat6>unbound</tstat6>
<tstat7>unbound</tstat7>
<tstat8>unbound</tstat8>
<romcode1>28A37BA70400</romcode1>
<romcode2>28B06AA80400</romcode2>
<romcode3>28A079A70400</romcode3>
<romcode4>000000000000</romcode4>
<romcode5>000000000000</romcode5>
<romcode6>000000000000</romcode6>
<romcode7>000000000000</romcode7>
<romcode8>000000000000</romcode8>
<boundromcode1>28A079A70400</boundromcode1>
<boundromcode2>28B06AA80400</boundromcode2>
<boundromcode3>28A37BA70400</boundromcode3>
<boundromcode4>000000000000</boundromcode4>
<boundromcode5>000000000000</boundromcode5>
<boundromcode6>000000000000</boundromcode6>
<boundromcode7>000000000000</boundromcode7>
<boundromcode8>000000000000</boundromcode8>
<hs1>65 %</hs1>
<aip1>0</aip1>
<aip2>0</aip2>
<aip3>0</aip3>
<aip4>0</aip4>
<aip5>0</aip5>
<aip6>0</aip6>
<aip7>0</aip7>
<aip8>0</aip8>
<urom1>20</urom1>
<urom2>600</urom2>
<urom3>5000</urom3>
<urom4>0</urom4>
<tdso>25</tdso>
<counter>544</counter>
<fcounter>0</fcounter>
<date>10/06/2013</date>
<time>22:39:19</time>
<datetime>10/06/2013 22:39:19</datetime>
<ipaddr>192.168.1.15</ipaddr>
<macaddr>xx:xx:xx:xx:xx:xx</macaddr>
<name>WEBPLC1511</name>
<builddate>May 02 2013, 23:32:28</builddate>

</response>
 
Any test result?  I rewrote the program in a couple different ways, still have the same intermittent reset problem.  Any suggestion on how to track it down?
 
The board is running your PLC code, but how to tell the board is resetting? 
You used counter in it to count some pulses, what kind of frequency do you count?
 
Hi CAI_Support,
Thanks for loading my program into the testing board.  When board resets, it runs INITIA once before enters main loop (LOOP1).  There is "Email EM7" command in INITIA, I will receive EM7 email, which indicates board has been reset.  I use the counter to measure water usage, the total number of pulse ranges from 3000 to 30000 per day, the frequency is lower than 10Hz.
 
I also have experienced no web response from board.  The board asks login and password, but nothing goes beyond that.  The LED is still blinking. 
 
I am Ok to purchase another board, but would like to know whether the reset is hardware related or software related.  
 
Thanks!!!
 
In your code, you have these lines:
 
DAILY:
TSTNE RAM2 CDAY 
GOTO DAILYCHK  
RET   

DAILYCHK:
 
If CDAY is not equal RAM2, PLC execution will jump to DAILYCHK  without RET.
In the PLC program handling, this will push down the stack pointer where it was executed.
The depth of stack pointer is limited. In our document, it stayed we handle up to 7 level stack pointer.
When it goes beyond 7 level, the RET may not get back to where you wanted to return, because the pointer lost.
 
That might be the cause of your code looked like reset, because the pointer for RET might lost.

 
 
There is a RET at the end of DAILYCHK so there is no path for it to skip RET because it is a GOTO not a CALL.
 
Because the DAILYCHECK is like this
DAILYCHK:
SET RAM2 CDAY 
SET RAM8 CTS 
DIV COUNTER 10 VAR7
ANDB VAR2 7 VAR2
RET  
 
That RET is the first to execute,  If he used
CALLSUB DAILYCHECK
 
then I would agree there is no problem. But goto will leave the stack not cleaned, because the DAILYCHECK's RET acted as DAILY's RET.
 
DAILYCHK is just a label as part of subroutine DAILY.  It is not its own subroutine.  So all code paths of DAILY lead to a single RET.  Not seeing a problem.
 
Okay. The space in between the lines made me thinking they are two subroutines.
I load his program in a board running, without same input, I can not tell if I had the problem he is having.
The firmware he has is very stable, I thought the only possible cause is call stack overflow, i.e. made more than 7 callsubs before popping the call stack.
 
In the past a few days, after board resets, it also lost the PLC program and Notification parameters that were stored in EEPROM.  
Is it an indication that the board is dying?  In term of programming, I have checked the callsub stacks, I do not think I went beyond 7.   Very frustrated with board reset.
 
Back
Top