a little help with pulsein

Trying to measure capacitance by turning on a digital output, with R to input pin and C to gnd, and measure the time delay. Arduino Uno.
Using pulsein (see code below) I get timeouts if R=infinity (open) or if tie the input pin low, which is expected.
But if I tie the pulsein input pin to +5V, or use a RC (100k and 0.1uF) to the pulsein pin, I get timeouts, where I expect a number :~ 'scope signals look ok to me.

If I disconnect pulsein pin and touch (giving noise) I start to get wandering readings from pulsein. Otherwise, it's always timeouts, as if pulsein gets "stuck" or needs an edge?

#include <avr/io.h>

byte SensorPin = 3;   // pin "D3", PD3
byte PulseOutPin = 2; // pin "D2", PD2
byte ledPin = 13; 

#define TRUE 1;
#define FALSE 0;

//************************************************************************
void setup() {
 
  digitalWrite(ledPin,LOW) ; // led off
  digitalWrite(PulseOutPin, LOW);  
  pinMode(PulseOutPin, OUTPUT);  
  pinMode(SensorPin, INPUT);
  Serial.begin(57600);
} 
    
//========================================================================
void loop() {

unsigned long duration;
const unsigned long pulsein_timeout = 100000; // in usec
const unsigned long pulse_triptime = 5000; // in usec

  digitalWrite(PulseOutPin, HIGH);  //
  duration = pulseIn(SensorPin, HIGH, pulsein_timeout);
  if (duration==0) {
      Serial.println("pulse timeout");
  }
  else {
  
    Serial.print("tau= "); Serial.print(duration); Serial.print(" usec");
    if (duration>=pulse_triptime) {
       digitalWrite(ledPin,HIGH) ; // led on
       Serial.print("  * trip *");
    }
    else {  
      digitalWrite(ledPin,LOW) ; // led off
    }
    Serial.println();
  }  
  digitalWrite(PulseOutPin, LOW);  //
    
  delay(1000);
}

TEK00007.PNG

It looks like it looks for a transition:

        // wait for any previous pulse to end
	while ((*portInputRegister(port) & bit) == stateMask)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to start
	while ((*portInputRegister(port) & bit) != stateMask)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to stop
	while ((*portInputRegister(port) & bit) == stateMask) {
		if (numloops++ == maxloops)
			return 0;
		width++;

You might use analogRead and use a micros() to determine start and stop and duration?

while (analogRead(PIN) < 10);  // accept some noise
start = micros();
while (analogRead(PIN) < 1020);  // ~5V reached
stop = micros();
Serial.println(stop - start);

There is an ( thinks! more than one) example of doing this in the playground.

Mark