Specifications

40
Curtis 1310 Manual, Rev. B
5 — VCL
All switch inputs are automatically debounced by the VCL operating system.
This prevents noisy contacts or contact bounce from causing erroneous events
in your VCL code. The debounce time can be varied from 0 to 32 milliseconds
in 4ms steps, using this function:
Setup_Switches(5); 20 milliseconds
If this line is not in the VCL code, the default debounce time is set at 16 ms.
The previous example “polls” the switch inputs at the the time the state
-
ment VCL is run. If there is a need to read fast inputs, the VCL will need to
poll these inputs very often in order not to miss a correct reading. Sometimes
it is not possible to run the VCL fast enough. Big programs or push buttons
cause the switch state to be easily missed.
SW_#_UP and SW_#_DOWN variables (where # = 1 through 26) give
VCL a better way to catch fast transients on the inputs. The “up” and “down
terms are based on the action of a pushbutton that is pushed down to turn
something on.” The 1310 samples the switch states 250 times per second.
Any input that has changed state from Off to On will set the corresponding
SW_#_DOWN variable. Any switch that has changed state from On to Off will
set the corresponding SW_#_UP variable. It is vital to note that once the bit is
set, it is not cleared by the corresponding variable. An input going off (released)
will not clear the SW_#_DOWN bit and likewise a switch being pushed down
(on) will not clear the SW_#_UP bit. It is this feature that allows the VCL code
to run less often and still detect input changes, even after the event occurs.
Once the VCL code has detected the change, it can clear the bit to allow the
next detection. The example below illustrates a push button interface.
If (SW_1_UP = ON)
{
;put code here to run when switch 1 is OFF (up & released)
SW_1_UP = OFF
;clear the bit so we can detect the button release
}
If (SW_1_DOWN = ON)
{
;put code here to run when switch 1 is ON (down & pressed)
SW_1_DOWN = OFF
;clear the bit so we can detect the next button press
}
Note that these bits are always checked to be ON, even for the switch off state.
Think of it not as the state of the input, but as the transition of the input.
In the first line, the VCL checks to see if it is true that the button went Off
(up). Normally, software is written to clear it (OFF) after reading it so that
the next state can be caught. Also note that it is entirely possible that both the
SW_#_UP and SW_#_DOWN bits are set. This simply means that the input
went both On and Off within the time it took for the VCL code to return to
these lines of code.