212 of 318
ZBasic System Library 202 ZX Microcontroller Family PulseOut Type Subroutine Invocation PulseOut(pin, duration, level) Parameter Method Type Description pin ByVal Byte The pin on which a pulse width will be generated. duration ByVal int16 or Single The width of the generated pulse. level ByVal Byte The desired pulse logic value (low = 0, high = 1). Discussion This routine first makes the specified pin an output. (However, for practical purposes, you should generally make the pin an output and set it to the desired state before calling this routine.) Then it sets the pin to the active state (as indicated by the level parameter), waits the specified time and then sets the pin back to the inactive state. The pin will be left configured as an output. The pulse width may be specified by a Single value with units of seconds and a resolution of approximately 1.085µs (however, due to processing overhead, the shortest pulse that can be generated is slightly less than 2us). Alternately, the pulse width may be specified by an Integer or UnsignedInteger value with units of 2 x I/O Timer ticks (by default, 1.085µs). Note, however, that Register.TimerSpeed2 may be modified to adjust the I/O Timer tick rate. If this is done, the Single value will have to be scaled proportionally. If the output pin is specified as zero, this routine does not generate a pulse but will delay for approximately the specified period of time. This may be useful for generating a delay with better precision than can be obtained by using Delay() or Sleep(). Moreover, generating a delay in this manner does not cause the task to lose control. Resource Usage This routine uses the I/O Timer and interrupts are disabled during the pulse generation. However, RTC ticks will be accumulated during the pulse generation and the RTC will be updated when the process is complete. If the pulse is too long characters being sent or received on serial channels 3-6 may be garbled. Example Dim width as Integer Call PutPin(12, zxOutputLow) Call PulseOut(12, 2, 1) ' generate a positive pulse about 2µS long Call PulseOut(0, 1e-5, 0) ' generate a delay of about 10µS Compatibility In the BasicX implementation the RTC will lose time if the pulse is too long. The BasicX implementation does not support adjustable timing resolution.