Need help with a code

BTCAD

Active Member
Hi,
It's supposed to be realy simple. I want to send an email when ip1 to high <= 58mins. Also set op1 to 1. The problem is that i receive false notification. POMPE_AL1: and  POMPE_AL3: are called for no reason. 
 
Can someone give me help to make my code more efficent and reliable?
 
 
 
Here is my code :
Code:
START    
	CALLSUB VARIABLE   
	TSTEQ IP1 0  
	SET RAM1 0  
	TSTEQ IP1 0  
	SET RAM2 0  
	TSTEQ IP1 0  
	SET RAM3 0  
	TSTEQ IP1 0  
	SET RAM4 0  
	CALLSUB POMPE_AL1   
	CALLSUB POMPE_AL3   
	CALLSUB POMPE_OK2   
	CALLSUB POMPE_OK4   
	END    

VARIABLE:
	TSTEQ IP1 1  
	SET VAR1 0  
	TSTEQ IP1 0  
	SET VAR1 1  
	RET    

POMPE_AL1:
	TSTEQ IP1[1000] 1  
	CALLSUB EMAIL1   
	RET    

POMPE_AL3:
	TSTEQ IP1[1000] 1  
	CALLSUB EMAIL3   
	RET    

POMPE_OK2:
	TSTEQ VAR1[3500000] 1  
	CALLSUB EMAIL2   
	RET    

POMPE_OK4:
	TSTEQ VAR1[3500000] 1  
	CALLSUB EMAIL4   
	RET    

EMAIL1:
	SET OP1 1  
	TSTEQ RAM1 0  
	EMAIL EM1   
	DELAY 5000   
	SET RAM1 1  
	RET    

EMAIL3:
	SET OP1 1  
	TSTEQ RAM3 0  
	EMAIL EM3   
	DELAY 5000   
	SET RAM3 1  
	RET    

EMAIL2:
	SET OP1 0  
	TSTEQ RAM2 0  
	EMAIL EM2   
	DELAY 5000   
	SET RAM2 1  
	RET    

EMAIL4:
	SET OP1 0  
	TSTEQ RAM4 0  
	EMAIL EM4   
	DELAY 5000   
	SET RAM4 1  
	RET
 
It seems your code calls POMPE_AL1 and AL3 in sequence, inside their test condition is same, so that both will be called sequentially.  But AL1 is always first executed before AL3.
 
this is what i want. but for no reason al1 and al3 are called. To day I received 36 message from al1 and al3. But nothing called them. So is my code skip some line or is my board reboot by it self?
 
Your main program has no LOOP: and a jump back to it.
 
Your requirements are unclear and your code is way too complicated for the simple job you want to do.
 
Try simplifying it by creating a subroutine for each email you want to send and the logic in your main routine.
You have subroutines that call subroutines and variable used that are not necessary.
 
If you only want periodic emails for a condition that will remain for a long period of time you will need "email sent" flags. You will need to clear them in your initialisation code before the LOOP: point and when finding the condition you are testing to be true, test them before sending an email and set them after sending the email. This way only one send will be done each time period you want and only when the input requires the emails.
 
I like to use the CTS contiguous second counter as a time slicer for doing multi-tasking. Then you can easily add more jobs without keeping track of time taken.
 
START
    SET RAM3 0  <flags cleared for email sent tracking
    SET RAM4 0
    CLR RAM5
LOOP:
     MOD CTS 100 RAM2
     BNE NOT100
     CALLSUB whatever <----happens every 100 seconds.
NOT100:
    MOD CTS 500 RAM2
    BNE NOT500
    CALLSUB whatever2 <--- happens every 500 seconds
NOT500:
     more code
     .....
     GOTO LOOP:
 
SUBROUTINE1:
    ,,,,
    RET
 
SUBROUTINE2:
    ....
    RET
 
END
 
odd...
 
Looks like the board reboot itself. 
 
 

start
tsteq ram1 0
callsub testem
end

testem:
email em1
delay 3000
set ram1 1
ret



 
 
 
psu 9vdc 0.5a
no pwr cycle. This is plugged to a constant 110vac outlet
 
I am not sure the END line actually terminates code operation.
After that the subroutine testem: would execute and RET causing an address to be pulled off the empty stack.
The address would be garbage and the CPU would then run amuck causing the OS to blow up, the watchdog to time out, and the board to reboot.
 
interresting, 
 
 
Should be better?
Code:
start
   tsteq ram1 0
   callsub testem
   nop

end

testem:
   email em1
   delay 3000
   set ram1 1
   ret
 
9V 0.5A power supply can not provide enough power, since any lower spike could cause CPU brown out thus reboot. 
 
For WC8 2.2.2 board, 9V 1A or 9V 2A is better.  Since power supply marked 0.5A that in most case are max current. When there is a spike on the power line, it may have output dip. Good quality power supply is very important for reliable setup.  Since you experienced reboot, it will be a good test to put different power supply to the test to see which one is better, and which one can cause reboot.
 
For WC32 and WC8 2.3.x board, they use switching power regulator, reduced demand to the power supply.  However, good quality power supply is still very important for reliable operation.
 
CAI_Support said:
For WC8 2.2.2 board, 9V 1A or 9V 2A is better.  Since power supply marked 0.5A that in most case are max current. When there is a spike on the power line, it may have output dip. Good quality power supply is very important for reliable setup.  Since you experienced reboot, it will be a good test to put different power supply to the test to see which one is better, and which one can cause reboot.
 
For WC32 and WC8 2.3.x board, they use switching power regulator, reduced demand to the power supply.  However, good quality power supply is still very important for reliable operation.
reduced demand to the power supply. 
 
Did you mean that we can use something like a 18vdc or 24vdc 2a as well?
 
For WC8 hw rev 2.3.8, you can use from 5V to 36V (absolutely not exceed 40V) DC power supply.  For WC32, it can use from 5V to 28V DC power supply.
 
start

LOOP:
tsteq ram1 0
callsub testem
GOTO LOOP


testem:
email em1
delay 3000
set ram1 1
ret

END


May need this.
 
IIRC the manual indicates a continuous loop but other have complained of problems with the subroutines in the PLC code  loop.
 
Try it to be sure.
 
Back
Top