Andy,
Have you used the Pololu AVR library before? As a first step, I recommend you try playing around a bit with the library (the sample programs are a good place to start).
Are you writing your programs in AVR Studio? If so, I recommend using the library’s C functions, not the C++ ones. You can find the OrangutanPulseIn C functions in the header file:
libpololu-avr/pololu/pulsein.h
You can get access to those functions by including <pololu/orangutan.h> in your program. All other library functions are documented in the command reference.
I am going to try to document the OrangutanPulseIn library tomorrow (which would include writing a sample program to demonstrate how to use it), but in case I don’t find the time for this, I’ll give you a quick example program so you can get started trying it out. This example causes the Orangutan to monitor pulses on pins PC0, PC1, PC2, and PC3. Since these are RC pulses, we set the maximum pulse duration to 26ms using the argument MAX_PULSE_26MS, which gives us pulse measurements with 0.4us resolution (see the header file for possible maximum pulse durations; longer durations yield lower-resolution readings).
Note that this example is intended for the Orangutan SV, so it uses LCD functions to display the pulse data. You should replace the LCD functions with some other feedback mechanism if you want to run it on your Baby Orangutan. For example, if you have a Pololu programer, use it as a USB-to-serial adapter to send data serially from the Baby Orangutan to your computer.
#include <pololu/orangutan.h>
const unsigned char pins[] = { IO_C0, IO_C1, IO_C2, IO_C3 };
int main()
{
clear(); // clear LCD
pulse_in_init(pins, 4, MAX_PULSE_26MS); // can only measure pulses
up to 26 ms long, but gives 0.4 us resolution
while (1) // main loop
{
pulse_in_update(); // you should call this function in your main
loop at least once per MAX_PULSE_XXMS ms
struct PulseInputStruct pi = get_pulse_info(0); // get info for
pulses on pin IO_C0
if (pi.curPulseWidth == 0xFFFF)
{
// IO line has been in the same state for longer than we can time
(e.g. it is held high or low)
lcd_goto_xy(0, 0);
if (pi.inputState)
print("line=5V ");
else
print("line=0V ");
}
else if (pi.newPulse == HIGH_PULSE)
{
lcd_goto_xy(0, 0);
print_unsigned_long(pi.lastHighPulse); // print the length of
the most recently received high pulse in units of 0.4 us
print(" ");
}
}
}
The comments in the sample program should help you follow what is going on, but if anything is still unclear, please ask.
- Ben