PulseIn function

Hey everyone,

I have a project with a LM555 timer and need to calculate how much time it takes for an input to go from LOW to HIGH and then to LOW again.

Basically, I want to know the period of a square wave generated by the LM555 timer.

I did it with Arduino using the function Pulseln. But I need to do this using a Beaglebone and programming in C++ (Using QtCreator).

Is there a way to "open" the function PulseIn so I know what it does? Moreover, do you guys have any piece of code that might help me?

Thank you in advance.

In my version (1.6.9), the function is located in \hardware\arduino\avr\cores\arduino\wiring_pulse.c

unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
	// cache the port and bit of the pin in order to speed up the
	// pulse width measuring loop and achieve finer resolution.  calling
	// digitalRead() instead yields much coarser resolution.
	uint8_t bit = digitalPinToBitMask(pin);
	uint8_t port = digitalPinToPort(pin);
	uint8_t stateMask = (state ? bit : 0);

	// convert the timeout from microseconds to a number of times through
	// the initial loop; it takes approximately 16 clock cycles per iteration
	unsigned long maxloops = microsecondsToClockCycles(timeout)/16;

	unsigned long width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);

	// prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
	if (width)
		return clockCyclesToMicroseconds(width * 16 + 16);
	else
		return 0;
}

Thank you for the answer Saximus. I took a look at the expanded function you have sent, but it uses many of other arduino "built-in" functions.

As I need to write a brand new code in C++, it serves as reference but still there are some blanks to fill.

Regards,

But I need to do this using a Beaglebone and programming in C++

What did the guys at the Beaglebone forum say?

Unfortunatelly I didn't get any answers from them.