201 of 323
ZBasic System Library 191 ZX Microcontroller Family OutputCaptureEx Type Subroutine Invocation OutputCaptureEx(pin, intervals, count, flags) OutputCaptureEx(pin, intervals, count, flags, repeatCount) Parameter Method Type Description pin ByVal Byte Specifies the waveform output pin. intervals ByRef array of int16 The lengths of successive segments of the output waveform. count ByVal any int The number of entries in the intervals array (1-65535). flags ByVal Byte Configuration bits controlling the generation process. repeatCount ByVal any int The number of times to repeat the pattern (1-65535). Discussion This subroutine produces a series of precisely timed logic levels on the specified pin allowing you to produce an arbitrary waveform. Each entry in the intervals array specifies a time interval, in units of the I/O Timer clock period (by default, about 67.8ns for devices running at 14.7MHz), for each segment of the waveform. When called, the specified 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 specified 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 the output 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. If the optional repeatCount parameter is not given a repeat count of 1 is assumed. If the repeat count is 1 the intervals array should generally have an odd number of values. This allows the output to end in the same state as it started. If the repeat count is greater than one the intervals array should generally have an even number of values. This allows the output waveform to repeat at the same logic levels. Also, when the waveform is repeated the last interval of the last cycle is omitted so that the output ends up in the same state as it started. The calling task will be suspended during the waveform generation process. If another task disables interrupts, the accuracy of the generated waveform will suffer. Due to processing overhead, the smallest pulse width that can be accommodated is about 6.8µS. This corresponds to a value of about 100 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 output pin during preparation for waveform generation, the output pin should either be configured as an input or as an output in the desired starting state prior to the call. If you configure it as an input 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. Although this subroutine can be invoked specifying the hardware OutputCapture pin (see the table below) or any other I/O pin, the behavior when using a general I/O pin may be slightly different than when using the hardware OutputCapture pin. The hardware OutputCapture pin uses features of the hardware to toggle the I/O pin while for general I/O pins the pin is toggled in software by directly setting the corresponding PORTx bit. During periods of high interrupt load the hardware toggling will be more accurate.