Page 232 of 346 Start Back Next End ZBasic System Library 220 ZBasic Microcontrollers PulseIn (subroutine form) Type Subroutine Invocation PulseIn(pin, level, var) Parameter Method Type Description pin ByVal Byte The pin on which a pulse width will be measured. level ByVal Byte The expected pulse logic value (high = 1). var ByRef Single The variable to receive the pulse width value. Discussion This routine waits for the input pin to be in the idle state (the opposite of that specified by the level parameter), waits for it to change to the specified logic level and then measures the time that it stays at that level. The pulse width is stored in the specified variable and has units of seconds with a default resolution as shown in the table below. PulseIn 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 The pin is made an input if it is not already so. If the awaited logic transition never occurs or if the pulse width exceeds the maximum representable width the stored result will be zero. The timing resolution may be adjusted using Register.TimerSpeed2. However, if this is done, the resulting pulse width value will need to be scaled proportionally. Resource Usage This routine uses the I/O Timer and interrupts are disabled during the pulse measurement. However, RTC ticks will be accumulated during the pulse measurement and the RTC will be updated when the process is complete. Example Dim width as Single Call PulseIn(12, 1,width) ' measure a positive-going pulse Compatibility The BasicX implementation does not support adjustable timing resolution.