Simple oneshot

todster

Active Member
What's the simplest 1 shot to construct for a webcontroller? When the state changes it should be recognized 1x at the time of transition and be ignored until the next rise from lo to hi or vice versa. A latch isn't what I'm looking for.
 
Could you use the counter feature on the WebControl 3.2.15 and later firmware? That counter is from low to high state change capture. You can SET the counter value to zero in PLC after you processed that.
 
When input state changes, counter recorded that. When your logic get chance to see if there is any one shot happened, you just check the counter value with your last stored value, if that is bigger, you will see it. Not very clear what you want to accomplish. If you could tell us, we can help you figure out a way to do it, maybe
 
We don't know how long you want your pulse to be.... so I offer something pretty wide.
Inline comments should explain my thought processes - if not, just ask.

Code:
start
   set ram1 ip1	 # read current input
   xor ram1 ram2 ram2  # ram2 is set only if state change
   and ram1 ram2 ram2  # ram2 is set only if state change AND rising edge
   tstgt ram2 0    # is ram2 set?
   add cts 20 ram3   # re-trigger timer to expire 20 seconds from now
   set ram2 ram1    # save current input state for next scan

  # Here is the test you use to see when the timer expires
   tstgt ram3 cts op1    # set output 1 while the timer is running
   set op2 ip3	  # or do any other command you like here that will only run while the timer is running.
end
 
What I want is to be able to do something for 1 scan or cycle. Then when the state changes do it again. Something like email or using the webset as a hearbeat, using webset to set an op or var remotely. When the webset is used it continuously sends the get and floods the network. Same thing for the heartbeat. I also would like the one shot to be reusable and generic to where it could be used by multiple referrers. Say if want to use all 8 websets and have 1 shots so all 8 are not flooding the network. My other thought was an xor with a delay so that it's off for [xxx] and then blips on then back off for [xxxx]. My biggest desire is the heartbeat between webcontrol boards and the webset.
 
What I want is to be able to do something for 1 scan or cycle. Then when the state changes do it again.

Ahh.

In that case, the crux of my code (above) is the key to it.

Code:
   set ram1 ip1		# read current input
   xor ram1 ram2 ram2  # ram2 is set only if state change
   and ram1 ram2 ram2  # ram2 is set only if state change AND rising edge
   set ram2 ram1	   # save current input state for next scan

.... rest of your code continues

end

Anywhere you want to do something only on the leading edge of an event (and you may do this multiple times)
eg:
tsteq ram2 1 # trigger?
email EM1 # yes, so send email

and/or

tsteq ram2 1 # trigger?
set op8 1 # turn on alarm


and/or

tsteq ram2 1 # trigger?
add var1 5 var1 # extend timeout if triggered


etc etc.

If you have many input type events to process (rather than many places to test for one trigger event) let me know and I'll work something for that instead.
 
Here's an alternative way

Code:
	set  ram2 ip1	# get input 1
	mul ip2 2 ram1  # align bits for input 2
	add ram1 ram2 ram2  # add to flag
	mul ip3 4 ram1  # align bits for input 3
	add ram1 ram2 ram2
	mul ip4 8 ram1  # align bits for input 4
	add ram1 ram2 ram2
	mul ip5 16 ram1
	add ram1 ram2 ram2
	mul ip6 32 ram1
	add ram1 ram2 ram2
	mul ip7 64 ram1
	add ram1 ram2 ram2
	mul ip8 128 ram1
	add ram1 ram2 ram2   # ram2 now has 8 bits mirroring the 8 inputs

	xorb ram2 ram3 ram1  # ram1 now has 1 bits for every changed input
	andb ram1 ram2 ram1  # ram1 now has 1 bits for every rising edge only
	set ram3 ram2			  # save all 8 input states for next scan

	# your code goes here. Test each bit of ram1 to see if it just changed to "on"
	orb ram1 1	 # test input 1
   (do whatever)

	orb ram1 128  # test input 8
   (do whatever)

etc etc.


The register has no debouncing, so assumes conditioned input, and will only go high for ONE SCAN on each rising edge of the input.
 
I like the alternative. :P I was also thinking of a flasher for the heartbeat by doing something like this:
Code:
ANDB CTS 64 RamX
which would give me every other 64 seconds. I need to use the hearbeat to send a webset to other boards. Any board that looses comm from another board will set an error. I thought about also passing a bit to set an alarm for conditions but the heartbeat will probably suffice. I'm monitoring my freezers. Needless to say losing an entire summers worth of veggies, fruit, or meat hurts.
I'm used to programming PLC controllers in ladder logic. Having to think like this comes a bit more slowly. I also thougth of using RIO (remote I/O) on my AB SLC500 and encode the temps and status in a parallel stream from the WC outputs to the I/O inputs. The analog inputs for AB are super pricey.
 
Code:
	set ram2 ip1	# get input 1
	mul ip2 2 ram1 # align bits for input 2
	add ram1 ram2 ram2 # add to flag
	mul ip3 4 ram1 # align bits for input 3
	add ram1 ram2 ram2
	mul ip4 8 ram1 # align bits for input 4
	add ram1 ram2 ram2
	mul ip5 16 ram1
	add ram1 ram2 ram2
	mul ip6 32 ram1
	add ram1 ram2 ram2
	mul ip7 64 ram1
	add ram1 ram2 ram2
	mul ip8 128 ram1
	add ram1 ram2 ram2 # ram2 now has 8 bits mirroring the 8 inputs

	xorb ram2 ram3 ram1 # ram1 now has 1 bits for every changed input
	andb ram1 ram2 ram1 # ram1 now has 1 bits for every rising edge only
	set ram3 ram2			 # save all 8 input states for next scan

	# your code goes here. Test each bit of ram1 to see if it just changed to "on"
	orb ram1 1	 # test input 1
(do whatever)

	orb ram1 128 # test input 8
(do whatever)

etc etc.
To take this even further and more useful as well. This also has the makings of a BSL or a BSR. Just not sure how to do this, yet. I don't need it, just see another idea someone else might need.
Thanks RossW. In case no one else has said it, your input and knowledge on this forum is appreciated.
 
Here's my test
Code:
START
begin:
SET RAM2 IP1
MUL IP2 2 RAM1
ADD RAM1 RAM2 RAM2
MUL IP3 4 RAM1
ADD RAM1 RAM2 RAM2
MUL IP4 8 RAM1
ADD RAM1 RAM2 RAM2
MUL IP5 16 RAM1
ADD RAM1 RAM2 RAM2
MUL IP6 32 RAM1
ADD RAM1 RAM2 RAM2
MUL IP7 64 RAM1
ADD RAM1 RAM2 RAM2
MUL IP8 128 RAM1
ADD RAM1 RAM2 RAM2
XORB RAM2 RAM3 RAM1
ANDB RAM1 RAM2 RAM1
SET RAM3 RAM2
ANDB RAM1 2 VAR2
ANDB RAM1 8 VAR4
ANDB RAM1 4 VAR3
ANDB RAM1 16 VAR5
SET VAR6 RAM1
SET VAR7 RAM2
SET VAR8 RAM3
ANDB RAM1 1 var1    # I changed the test to andb. ( banging my head here until the duh hit me :blush: , orb will place either or both in)

bnz send
set var7 111111  # to see where flow was going
goto begin
send:
webset url1 1
set var8 121212   # to see where flow was going
goto begin
END
This works. Thanks for the idea Ross. The webset sends 1x (3-5 times actually cuz you can see the switch bounce)
 
This works. Thanks for the idea Ross. The webset sends 1x (3-5 times actually cuz you can see the switch bounce)

If you are not particularly concerned about the response speed, and you ARE concerned about the contact bounce, and assuming you don't get any really fast input pulses (that is, an input will always change state for more than say, 100ms) then I would just add a delay of at least your worst-case contact bounce, in to the loop. Eg, if you see contact bounce for 20ms, then add a delay 25 in at the start.

This way, the program simply can't scan through, process and be back again while the contact is still bouncing. Its crude, but it works.
 
Actually the bounce was because I was poking a wire from 5v to the input :nono: . Is a delay better than using the [xxx] on the input itself or is it dependant on the usage and desired scan times? In a PLC I'll use a timer and then latch it with the timer done bit. The latched bit is then used as the input. In my case I'll be monitoring a temp sensor. I'm thinking of leaving a several degrees spread to help with the flutter as well as the Tx[xxx]. The freezers will be a slow running system as they will all be sending heartbeats to each other every so often as well as a pass/fail bit. I may just use the heartbeat as the pass/fail as well. If the freezer is thawing, then don't send heart beat to the other freezers. All 3 will be able to email individually as well.
 
Back
Top