Thanks Ben, I had missed those. I seem to have the frequency counter part working just fine on two pins now, but I am still having trouble measuring the delay between the two. Again, the input on each pin is a square wave of about 30 hz (from two different sources) and the goal is to measure their phase difference. For the purpose of troubleshooting, I have stripped out all of the working parts and re-written a short bit to just show the start time of each input and then to display the difference between them. I have tried a few different versions of this, but I am not getting the result I need. Usually both inputs report the same time or very close to it and the difference jumps around, and is never correct when verified with a scope. I’m sure I’m just using the commands wrong, but I’m out of ideas. Any help would be appreciated.
Kirk
Below is a sample of one non-working version. Compiles without errors or warnings, but does not produce the correct result.
#include <pololu/orangutan.h>
const unsigned char pulseInPins[] = { IO_C0, IO_C1 };
int main()
{
pulse_in_start(pulseInPins, 2);
set_digital_input(IO_C0, PULL_UP_ENABLED);
set_digital_input(IO_C1, PULL_UP_ENABLED);
clear(); // clear LCD
time_reset();
while (1) // main loop
{
struct PulseInputStruct pulse_info;
//Select pin 0 (IO_C0) as input
//Read last Pin Change time for Pin 0 in ticks and convert to milliseconds
//Set start_time variable to last Pin Change time for Pin 0 in milliseconds
get_pulse_info(0, &pulse_info);
long start_time = (pulse_to_microseconds(pulse_info.lastPCTime)/1000);
//Select pin 1 (IO_C1) as input
//Read last Pin Change time for Pin 1 in ticks and convert to milliseconds
//Set stop_time variable to last Pin Change time for Pin 1 in milliseconds
get_pulse_info(1, &pulse_info);
long stop_time = (pulse_to_microseconds(pulse_info.lastPCTime)/1000);
//Display Values of start_time and stop_time
lcd_goto_xy(0, 0);
print_long(start_time);
lcd_goto_xy(9, 0);
print_long(stop_time);
if (start_time > stop_time)
{
long delta = (start_time - stop_time);
lcd_goto_xy(0,1);
print("-");
print_unsigned_long(delta);
}
else
{
long delta = (stop_time - start_time);
lcd_goto_xy(0,1);
print("+");
print_unsigned_long(delta);
}
delay_ms(500);
}
}