Page 234 of 346 Start Back Next End ZBasic System Library 222 ZBasic Microcontrollers 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 as shown in the table below. Note, however, that due to processing overhead, the shortest pulse that can be generated is approximately 200 CPU cycles (13us at 14.7MHz). Alternately, the pulse width may be specified by an Integer or UnsignedInteger value with units as shown in the table below. 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. PulseOut Resolution Target I/O Scaling Resolution ZX devices running at 14.7456MHz True False 1.085 µS 0.542 µS all other targets n/a 1/F_TS2 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. Also, the BasicX implementation does not support adjustable timing resolution.