Page 174 of 346 Start Back Next End ZBasic System Library 162 ZBasic Microcontrollers 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 (i.e. 1/F_CPU or 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. Due to the overhead of servicing the input capture interrupt and possible RTC interrupts the shortest interval (high or low segment) that can be reliably measured corresponds to about 300 CPU cycles (about 21µs for 14.7MHz devices). If an input waveform had a 50% duty cycle this would correspond to about 24KHz. Additional interrupt sources may increase the minimum interval that can be measured reliably. 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. See the section Input Capture Timers for information on the valid input capture pins and the timer associated with each and the ISRs utilized for native mode devices.