143 of 307
ZBasic System Library 133 ZX Microcontroller Family InputCaptureEx Type Subroutine Invocation InputCaptureEx(pin, data, count, flags) InputCaptureEx(pin, data, count, flags, timeout) Parameter Method Type Description pin ByVal Byte The input capture pin to use. data ByRef array of UnsignedInteger The array in which pulse width information will be stored. count ByVal int16 The number of pulse widths to store. This should be no larger than the number of entries in the passed array. flags ByVal Byte A value of zero requests that a falling edge begin the capture process while a value of 1 indicates a rising edge. All other values are reserved. timeout ByVal integral If non-zero, this parameter specifies a timeout value that, if exceeded, will terminate the input capture process. Discussion This routine collects timing data from a pulse train applied to the specified input capture pin and stores it in the specified array. The stored data reflects the width of the successive high and low portions of the pulse train. If any segment is longer than can be represented in a 16-bit value, the stored value will be 65535 (&Hffff) and the immediately following value, if any, will be meaningless. Prior to commencing the input capture process all of the elements of the data array are initialized with the value 65534 (&Hfffe). This fact can be used to determine the actual number of timing data stored in the array during input capture. The stored values represent the number of I/O Timer ticks (by default about 67.8ns for 14.7MHz devices) measured for each segment of the pulse train. However, the value of Register.TimerSpeed1 may be changed to allow longer pulse widths to be measured. See the section on Timers for more information. If the optional timeout parameter is specified and is non-zero, the Input Capture process will be terminated if N * 65536 I/O Timer ticks occur (where N is the value of the timeout parameter) before the specified number of datapoints has been stored. This gives a range of possible timeout values from about 4.5mS to 290 seconds with a resolution of 4.5mS (using the default value of Register.TimerSpeed1) for 14.7MHz devices. The calling task will be suspended until the specified number of datapoints has been stored, the timeout value is exceeded or the task is resumed using ResumeTask(). Other tasks will be allowed to run but you must be careful to not call any routines that may disable interrupts for long periods of time because that could interfere with the accuracy of the input capture timing. Resource Usage This routine utilizes a timer to collect the timing information of the pulse train. The table below indicates which timer is used and the corresponding input pin for the supported channels. The corresponding timer busy flag (e.g. Register.Timer1Busy) will be set True for the duration of the input capture operation. Also, on the ZX-24, ZX-24a, ZX-24p and ZX-24n the input capture pin is common with PortC bit 0. This means that you should set pin 12 to be an input (either tri-state or pull-up) when you want to use InputCapture() so that it doesn’t interfere with the pulse train to be measured. This routine cannot be used at the same time as OutputCapture() or OutputCaptureEx() when that routine requires the same timer.