User Manual
Reference
C++ methods are shown in red.
C/C++ functions are shown in green.
static unsigned char OrangutanPulseIn::start(const unsigned char pulse_pins[], unsigned char
num_pins)
unsigned char pulse_in_start(const unsigned char pulse_pins[], unsigned char num_pins)
Configures the AVR’s pin-change interrupts to measure pulses on the specified pins. The num_pins
parameter should be the length of the pulse_pins array. A nonzero return value indicates that the needed
memory could not be allocated.
The pulse_pins parameter should be the RAM address of an array of AVR I/O pin numbers defined using
the IO_* keywords provided by the library (e.g. IO_D1 for a pulse input on pin PD1). This function does
not configure the pulse_pins as digital inputs, which makes it possible to measure pulses on pins being
used as outputs. AVR I/O pins default to digital inputs with the internal pull-up disabled after a reset or
power-up.
Example
// configure pins PD0 and PD1 as pulse input channels
pulse_in_start((unsigned char[]) {IO_D0, IO_D1}, 2);
// configure pins PD0 and PD1 as pulse input channels
OrangutanPulseIn::start((unsigned char[]) {IO_D0, IO_D1}, 2);
static void OrangutanPulseIn::stop()
void pulse_in_stop()
Disables all pin-change interrupts and frees up the memory that was dynamically allocated by the
pulse_in_start() function. This can be useful if you no longer want state changes of your pulse-measuring
channels to interrupt program execution.
static void OrangutanPulseIn::getPulseInfo(unsigned char channel, struct PulseInputStruct*
pulse_info)
void get_pulse_info(unsigned char channel, struct PulseInputStruct* pulse_info)
This function uses the pulse_info pointer to return a snapshot of the pulse state for the specified channel,
channel. After get_pulse_info() returns, pulse_info will point to a copy of the PulseInputStruct that is
automatically maintained by the the pin-change ISR for the specified channel. Additionally, after the
copy is made, this function clears the newPulse flags (both high pulse and low pulse) in the original,
ISR-maintained PulseInputStruct. Since pulse_info is a copy, the pin-change ISR will never change the
pulse_info data. Working with pulse_info is especially useful if you need to be sure that all of your puse
data for a single channel came from the same instant in time, since pin-change interrupts are disabled
while the ISR-maintained PulseInputStruct is being copied to pulse_info.
The argument channel should be a number from 0 to one less than the total number of channels used
(num_pins-1); the channel acts as an index to the pulse_pins array supplied to the pulse_in_start()
function.
See the “Pulse Information Variables” section at the top of this page for documentation of the members
of the PulseInputStruct pulse_info, and see the pulsein1 sample program for an example of how to use
get_pulse_info() as the basis of your pulse-reading code.
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
8. Orangutan Pulse/PWM Inputs Page 32 of 65