Library
#include
<PULSE.bas> '
PBASIC library, these routines were written for ARMexpress, and included for
general reference
Interface
' duration in microseconds
' timeperiod in milliseconds
' duty 0-255
FUNCTION COUNT (pin, timeperiod)
FUNCTION PULSIN (pin, level)
SUB PULSOUT (pin, duration)
SUB PWM (pin, duty, timeperiod)
FUNCTION RCTIME (pin, state)
Description
COUNT the number of pulses low-high-low or
high-low-high on pin over a timeperiod of milliseconds,
returning the FUNCTION value.
PULSIN measures an input pulse on pin at
level, returning the value in microseconds. The IO direction of
pin will be set to input. If pin is already at level when
PULSIN is called it will wait to a transition to the opposite level. PULSIN will wait 1 second for pin
to go to level. The minimum pulse that can be measured is 1
microseconds. If pin does not go to level or remains at level
longer than 1 second 0 is returned..
PULSOUT will generate an output pulse on pin for
duration microseconds. The IO direction of pin will be set to
output. The level of the output will be switched, driven for duration
microseconds, then switched back to its initial level. The minimum pulse period
is 1 microseconds.
PWM will generate a pulse corresponding to
an analog signal on pin for timeperiod in milliseconds with
a duty cycle of 0 to 255. A duty cycle of 255 corresponds to an
output value of 100%. The IO direction of the pin will be set to output, the PWM
pulse train is output, and then the pin is set to tri-state (input). If the
pin is connected to an RC filter, then the voltage will stay on the capacitor
for a period of time determined by the load.
RCTIME will measure the time which pin remains
at level, returning the value in microseconds(us). The minimum time
measured is 1 microseconds. If pin is not at level when RCTIME is
called -1 is returned. If pin remains at level longer than 1
second 0 is returned.