199 of 323
ZBasic System Library 189 ZX Microcontroller Family OutputCapture Type Subroutine Invocation OutputCapture(values, count, firstPulse) Parameter Method Type Description intervals ByRef array of int16 The lengths of successive segments of the output waveform. count ByVal int16 The number of entries in the value array. flags ByVal Byte Configuration bits controlling the generation process. Discussion This subroutine produces a series of precisely timed logic levels on the OutputCapture pin (see table below) allowing you to produce an arbitrary waveform. Each entry in the intervals array specifies a time interval, in units of the I/O Timer period (by default, about 67.8ns for devices running at 14.7MHz), for each segment of the waveform. When called, the OutputCapture pin will be made an output and will be set to its initial state (the complement of the least significant bit of the flags parameter). When waveform generation is begun, the OutputCapture pin will be changed to the opposite state for the interval specified by the first intervals element, changed to the opposite state again for the interval specified by the second intervals element, etc. for as many elements as specified. The final state of OutputCapture pin depends on whether the count parameter is odd or even. If it is odd the final state will be the complement of the least significant bit of the flags parameter; if it is even the final state will be the same as the least significant bit of the flags parameter. The calling task will be suspended during the waveform generation process. If another task disables interrupts the accuracy of the generated waveform may suffer. Due to processing overhead, the smallest pulse width that can be accommodated is about 6µS. This corresponds to a value of about 88 in the data array at the default timer speed. If the system has a heavy interrupt load (e.g. serial channels 3-6 are open) the minimum pulse width for reliable operation may be significantly larger. The maximum pulse width using the default timer speed is about 4.4mS. If you need to generate longer pulse widths, you may set the value of Register.TimerSpeed1 so that a slower clock rate is used. To avoid unwanted logic transitions on the OutputCapture pin during preparation for waveform generation, the OutputCapture pin should be configured as an input prior to the call. You’ll probably need to employ a pullup or pulldown resistor on the pin to guarantee the desired logic state prior to the commencement of waveform generation. Resource Usage This routine uses the I/O Timer. If the timer is already in use the routine will return immediately without performing the waveform generation. Also, this routine cannot be used at the same time as InputCapture(). See the description of OutputCaptureEx() for information about ISR requirements.