Start Back Next End
  
ZBasic System Library
213
ZBasic Microcontrollers
OutputCapture
Type
Subroutine
Invocation
OutputCapture(intevals, count, flags)
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 (i.e. 1/F_CPU, 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 90 CPU cycles
(6µS at 14.7MHz).  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 at 14.7MHz.  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
See the Resource Usage sub-section Output Capture Timers for information about the output pin and, for
native mode devices, the ISRs that will be included in the application.
Compatibility
For ZX devices running at 14.7MHz, since the CPU runs at twice the rate as the BasicX CPU, the units of
the pulse width are half as long.  If you need to generate longer pulse widths, you may set the value of
Register.TimerSpeed1 so that a slower timer clock rate is used.  Also, the BasicX documentation
indicates that if the I/O Timer is already in use, that use will be terminated and the waveform generation
will be performed.
See Also
Previous page Top Next page