delay toggle and counting

pittom

Active Member
I got a alarm system working but want to put safety for op3 and op2.They are hooked up to key chain remotes and turn on for delay 1000 then off (toggle). Want it setup uncase i turn op2 or op3 on manually, to turn off delay 1200 this way it won't mess up my RESET
 
 
 
RESET:
DELAY 9000   
SET OP3 1  
DELAY 1000   
SET OP3 0  
DELAY 50   
SET OP2 1  
DELAY 1000   
SET OP2 0  
RET  
 
1 more question about counting,every time door opens ip1 goes from 0 to 1 for 10s then back to 0.
Want to keep track how man times door opens and put into var.
 
Don't know how your keychain remote is wired to the WC board, is that through a TTL input?  If so, you can setup your RESET routine that skip SET OP2 and SET op3 when input is not on.
 
To best count the pulses, you can use counter feature.  Please make sure debounce the switch noise when using counter feature, since counter feature can count fast pulses higher than 2MHz, if the switch is not debounced, it will have a lot of false count.  Also, please note the counter counts when input from High to Low, then Low to high phase.  If the switch is not wired correctly, you may miss the first count.
 
when door opens the led lightsand is wired to ip1 to ip6,led will stay on so have to turn unit(not cai)off then on to clear led. to do that i wired 1 keychain to ttl3 for off and the other keychain ttl2 for on.
 
the keychain #2 has on button shorted and #3 has off button shorted. ttl output is wired were the + battery was and WC - to where the - battery was. when ttl goes hi it gives power to keychain
 
now when door opens led goes on, then goes to CALLSUB RESET delay 9000 gives me time to see led then triggers on the disarm keychain for delay 1000(delay gives unit time to turn off)then turns disarm keychain off and turns arm keychain on for delay 1000 then turnes arm keychain off and all ready for door to open again
 
not to confusing i hope
 
[sharedmedia=gallery:images:554]
[sharedmedia=gallery:images:553]
[sharedmedia=gallery:images:555]
 
I got the count to work,don't know if there is a better way
 
 
 
CK_HDOOR:
              TSTEQ IP1 1 ---i added this and
              INC VAR1   ------this workes:)
              TSTEQ IP1 1  
              CALLSUB RESET   
              TSTEQ IP2 1 
               inc var2
               tsteq ip2 1 
              CALLSUB RESET 
             ret
 
pittom said:
I got a alarm system working but want to put safety for op3 and op2.They are hooked up to key chain remotes and turn on for delay 1000 then off (toggle). Want it setup uncase i turn op2 or op3 on manually, to turn off delay 1200 this way it won't mess up my RESET
 
 
 
RESET:
DELAY 9000   
SET OP3 1  
DELAY 1000   
SET OP3 0  
DELAY 50   
SET OP2 1  
DELAY 1000   
SET OP2 0  
RET  
 
1 more question about counting,every time door opens ip1 goes from 0 to 1 for 10s then back to 0.
Want to keep track how man times door opens and put into var.
 
 
 
I don't know what else happens with the rest of the code.  But once the "Reset" subroutine starts, it will take more than 11 seconds before it ends.  That means that any other code you have that responds to anything or needs to respond to an input won't work.  Using "delay" can cripple the rest of a program.
 
It is usually better to use the non-blocking delay or use the total second counter to count out the seconds for a future event.
 
The below code will do the reset, it can't get interrupted once started, and your start-end code will keeping cycling while the reset happens.
 
Code:
START    
	TSTEQ whatever you want to trigger the reset  
	CALLSUB RESET   
	TSTEQ RAM1 CTS  
	CALLSUB RESET1   
	END    

RESET:
	TSTGE RAM1 CTS  
	RET    

	SET RAM1 CTS  
	ADD RAM1 9 RAM1 
	RET    

RESET1:
	TSTEQ OP3[1100] 0    (edit, changed from 1000 to 1100)
	INC RAM1   
	TSTEQ OP3[1100] 0  
	SET OP3[1000] 1  
	TSTEQ OP3[50] 0  
	SET OP2[1000] 1  
	RET
 
pittom said:
I got the count to work,don't know if there is a better way
 
 
 
CK_HDOOR:
              TSTEQ IP1 1 ---i added this and
              INC VAR1   ------this workes:)
              TSTEQ IP1 1  
              CALLSUB RESET   
              TSTEQ IP2 1 
               inc var2
               tsteq ip2 1 
              CALLSUB RESET 
             ret
 
 
Exactly what are you wanting to count?
 
Your current code is going to count an opening, then it won't count an opening again until the long subroutine is done. 
 - if it opens/closes several times in that 11+ seconds it will only count it as 1
 - if the other door opens during that 11 seconds, it won't get counted at all
 - if the door stays open, it will get counted a second time after 11 seconds.
 
The following code will count a door opening one time each time either door goes from closed to open.  It won't count again until the door closes.  
 
The reset subroutine will run when either door opens, provided the reset is not already running.  if it is already running, it will only run once, even if the door is left open or if the other door is opened during the 11 seconds or so.
 
Code:
START    
	TSTEQ RAM1 CTS  
	CALLSUB RESET1   
	TSTEQ IP1 1  
	CALLSUB DOOR1   
	TSTEQ IP1 0  
	SET RAM2 0  
	TSTEQ IP2 1  
	CALLSUB DOOR2   
	TSTEQ IP2 0  
	SET RAM3 0  
	END    

RESET:
	TSTGE RAM1 CTS  
	RET    

	SET RAM1 CTS  
	ADD RAM1 9 RAM1 
	RET    

RESET1:
	TSTEQ OP3[1100] 0  
	INC RAM1   
	TSTEQ OP3[1100] 0  
	SET OP3[1000] 1  
	TSTEQ OP3[50] 0  
	SET OP2[1000] 1  
	RET    

DOOR1:
	TSTEQ RAM2 1  
	RET    

	INC VAR1   
	SET RAM2 1  
	CALLSUB RESET   
	RET    

DOOR2:
	TSTEQ RAM3 1  
	RET    

	INC VAR2   
	SET RAM3 1  
	CALLSUB RESET   
	RET
 
Back
Top